Revision 1962

tmp/org.txm.xmleditor.rcp/src/org/txm/xmleditor/OpenXMLEditor.java (revision 1962)
93 93
		IFileStore fileOnLocalDisk = EFS.getLocalFileSystem().getStore(
94 94
				file.toURI());
95 95

  
96
		URI _uri = file.toURI();
97
		new Path(_uri.getPath());
98

  
99 96
		FileStoreEditorInput editorInput = new FileStoreEditorInput(fileOnLocalDisk);
100
		IWorkbenchWindow window = PlatformUI.getWorkbench()
101
				.getActiveWorkbenchWindow();
97
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
102 98
		IWorkbenchPage page = window.getActivePage();
103 99

  
104 100
		String ID = "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"; //$NON-NLS-1$
tmp/org.txm.xmleditor.rcp/plugin.xml (revision 1962)
14 14
         point="org.eclipse.ui.menus">
15 15
      <menuContribution
16 16
            locationURI="menu:menu.file?after=menu.file.separator.open">
17
         <command
18
               commandId="org.txm.xmleditor.OpenXMLEditor"
19
               style="push">
20
         </command>
21 17
      </menuContribution>
22 18
      <menuContribution
23 19
            locationURI="menu:menu.help.plugins">
24
         <command
25
               commandId="org.txm.rcp.commands.OpenBrowser"
26
               label="%command.label"
27
               style="push">
28
            <parameter
29
                  name="org.txm.rcp.commands.commandParameter2"
30
                  value="https://groupes.renater.fr/wiki/txm-users/public/extensions#xmleditor">
31
            </parameter>
32
         </command>
33 20
      </menuContribution>
34 21
      <menuContribution
35 22
            locationURI="popup:org.txm.rcp.views.fileexplorer.Explorer">
36
         <command
37
               commandId="org.txm.xmleditor.OpenXMLEditor"
38
               style="push"
39
               tooltip="%command.tooltip">
40
            <visibleWhen
41
                  checkEnabled="false">
42
               <reference
43
                     definitionId="OneFileSelected">
44
               </reference>
45
            </visibleWhen>
46
         </command>
47 23
      </menuContribution>
48 24
   </extension>
49 25
   <extension
tmp/org.txm.progression.rcp/src/org/txm/progression/rcp/editors/ProgressionEditor.java (revision 1962)
210 210
			});
211 211
			queryWidget.getQueryWidget().addModifyListener(computeKeyListener);
212 212
			
213
			
214 213
			Button addNewQueryButton = new Button(getMainParametersComposite(), SWT.PUSH);
215 214
			addNewQueryButton.setText(ProgressionUIMessages.add);
216 215
			addNewQueryButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
......
218 217
				
219 218
				@Override
220 219
				public void widgetSelected(SelectionEvent e) {
221
					if (queryWidget.getRawString().length() > 0 && onPlusButtonPressed(null, queryWidget.getRawString())) {
220
					if (queryWidget.getRawString().length() > 0 && onPlusButtonPressed(null, queryWidget.getQueryString())) {
222 221
						compute(true);
223 222
						queryWidget.clearQuery();
223
					} else {
224
						queryWidget.setText(queryWidget.getQueryString());
224 225
					}
225 226
				}
226 227
				
......
526 527
		 */
527 528
		public void setQuery(String query) {
528 529
			// fix the query, remove the double quotes
529
			query = query.replaceAll("^\"(.*)\"$","$1"); //$NON-NLS-1$
530
			//query = query.replaceAll("^\"(.*)\"$","$1"); //$NON-NLS-1$
530 531
			assistedQueryWidget.setText(query);
531 532
		}
532 533

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/parameters/LabelField.java (revision 1962)
25 25
		l.setAlignment(SWT.RIGHT);
26 26
		l.setText(getWidgetLabel());
27 27
		l.setToolTipText(getWidgetUsage());
28
		GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
29
		gd.widthHint = 100;
28
		GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
29
		gd.widthHint = 170;
30 30
		l.setLayoutData(gd);
31 31
	}
32 32

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/AssistedQueryWidget.java (revision 1962)
173 173
//			query = ""; //$NON-NLS-1$
174 174
//		}
175 175
		
176
		// fix the query
177
		query = query.replaceAll("^\"(.*)\"$","$1"); //$NON-NLS-1$
176
//		// fix the query
177
//		query = query.replaceAll("^\"(.*)\"$","$1"); //$NON-NLS-1$
178 178
		
179 179
		querywidget.setText(query);
180 180
	}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/files/EditFile.java (revision 1962)
87 87
	 *
88 88
	 * @param filepath the filepath
89 89
	 */
90
	static public void openfile(File file) {
90
	static public boolean openfile(File file) {
91 91
		if (file.isDirectory())
92
			return;
92
			return false;
93
		
93 94
		try {
94 95
			IFileStore fileOnLocalDisk = EFS.getLocalFileSystem().getStore(file.toURI());
95 96

  
......
97 98
			IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
98 99
			IWorkbenchPage page = window.getActivePage();
99 100

  
100
			IEditorPart a = page.openEditor(editorInput, TxtEditor.ID, true);
101
			TxtEditor editor = (TxtEditor) a;
101
			String ID = null;
102
			if (file.getName().toLowerCase().endsWith(".xml")) {
103
				ID = "org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart"; //$NON-NLS-1$
104
			} else {
105
				ID = TxtEditor.ID;
106
			}
107
			
108
			page.openEditor(editorInput, ID, true);
109
			return true;
102 110
		} catch (Exception e) {
103 111
			Log.printStackTrace(e);
112
			return false;
104 113
		}
105 114
	}
106 115

  
tmp/org.txm.rcp/plugin.xml (revision 1962)
565 565
                  label="%command.label.83">
566 566
            </command>
567 567
            <command
568
                  commandId="org.txm.rcp.commands.EditFile"
568
                  commandId="org.txm.rcp.handlers.files.EditFile"
569 569
                  icon="icons/functions/open.png"
570 570
                  id="file.open"
571 571
                  label="%command.label.45"
......
1458 1458
                  tooltip="%command.tooltip.34">
1459 1459
            </command>
1460 1460
            <command
1461
                  commandId="org.txm.rcp.commands.EditFile"
1461
                  commandId="org.txm.rcp.handlers.files.EditFile"
1462 1462
                  icon="icons/functions/open.png"
1463 1463
                  label="%command.label.45"
1464 1464
                  style="push">
......
2589 2589
      <command
2590 2590
            categoryId="org.txm.rcp.categories.file"
2591 2591
            defaultHandler="org.txm.rcp.handlers.files.EditFile"
2592
            id="org.txm.rcp.commands.EditFile"
2592
            id="org.txm.rcp.handlers.files.EditFile"
2593 2593
            name="%command.name">
2594 2594
         <commandParameter
2595 2595
               id="org.txm.rcp.commands.commandParameter2"
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/SchemasProgressionMacro.groovy (revision 1962)
106 106

  
107 107
	def allUnits = [:]
108 108
	def allHighlightedUnits = [:]
109
	def allSchemas = AnalecUtils.selectSchemas(debug, analecCorpus, corpus, schema_ursql, minimum_schema_size, maximum_schema_size)
109
	def allSchemas = AnalecUtils.selectSchemasInCorpus(debug, analecCorpus, corpus, schema_ursql, minimum_schema_size, maximum_schema_size)
110 110

  
111 111
	if (allSchemas.size() == 0) {
112 112
		println "No schema match for '$schema_ursql' selection. Aborting"
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/mesures1/LongueurMoyenneMacro.groovy (revision 1962)
1
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
2
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3
// @author mdecorde
4
// @author sheiden
5

  
6
// STANDARD DECLARATIONS
7
package org.txm.macro.urs.exploit.mesures1
8

  
9
import org.kohsuke.args4j.*
10
import groovy.transform.Field
11
import org.txm.rcp.swt.widget.parameters.*
12
import org.txm.annotation.urs.*
13
import org.txm.searchengine.cqp.corpus.*
14
import org.txm.Toolbox
15
import org.txm.rcp.commands.*
16

  
17

  
18
// BEGINNING OF PARAMETERS
19
@Field @Option(name="schema_type",usage="", widget="String", required=true, def="CHAINE")
20
String schema_type
21

  
22
@Field @Option(name="minimum_schema_size",usage="", widget="Integer", required=true, def="3")
23
int minimum_schema_size
24

  
25
@Field @Option(name="schema_property_name",usage="", widget="String", required=false, def="")
26
String schema_property_name
27

  
28
@Field @Option(name="schema_property_value",usage="", widget="String", required=false, def=".*")
29
String schema_property_value
30

  
31
@Field @Option(name="unit_type",usage="", widget="String", required=false, def="MENTION")
32
String unit_type
33

  
34
@Field @Option(name="unit_property_name", usage="", widget="String", required=false, def="")
35
String unit_property_name
36

  
37
@Field @Option(name="unit_property_value", usage="", widget="String", required=false, def=".*")
38
String unit_property_value
39

  
40
if (!(corpusViewSelection instanceof MainCorpus)) {
41
	println "Corpora selection is not a Corpus"
42
	return;
43
}
44

  
45
if (!ParametersDialog.open(this)) return;
46
// END OF PARAMETERS
47

  
48
MainCorpus corpus = corpusViewSelection
49
def analecCorpus = URSCorpora.getCorpus(corpus)
50

  
51
// check Schema parameters
52
if (!analecCorpus.getStructure().getSchemas().contains(schema_type)) {
53
	println "No schema with name=$schema_type"
54
	return;
55
} else {
56
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
57
		// test property existance
58
		def props = analecCorpus.getStructure().getSchemaProperties(schema_type);
59
		if (!props.contains(schema_property_name)) {
60
			println "Schema $schema_type has no property named $schema_property_name"
61
			return;
62
		}
63
	}
64
}
65

  
66
// check unit parameters
67
if (!analecCorpus.getStructure().getUnites().contains(unit_type)) {
68
	println "No unit with name=$unit_type"
69
	return;
70
} else {
71
	if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
72
		// test property existance
73
		def props = analecCorpus.getStructure().getUniteProperties(unit_type);
74
		if (!props.contains(unit_property_name)) {
75
			println "Unit $unit_type has no property named $unit_property_name"
76
			return;
77
		}
78
	}
79
}
80

  
81
def schemas = analecCorpus.getSchemas(schema_type)
82

  
83
int nSchemas = 0;
84

  
85
def lens = [:]
86
def lensnames = [:]
87
for (def schema : schemas) {
88

  
89
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
90
		if (!schema.getProp(schema_property_name).matches(schema_property_value)) {
91
			// ignoring this schema
92
			continue
93
		}
94
	}
95
	
96
	int nUnites = 0;
97
	for (def unit : schema.getUnitesSousjacentesNonTriees()) {
98
		if (unit_type.length() > 0) {
99
			if (!unit.getType().equals(unit_type)) {
100
				continue
101
			}
102
		}
103
		
104
		if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
105
			if (!unit.getProp(unit_property_name).matches(unit_property_value)) {
106
				// ignoring this schema
107
				continue
108
			}
109
		}
110
	
111
		nUnites++
112
	}
113
	
114
	if (nUnites < minimum_schema_size) continue;
115
	
116
	if (!lens.containsKey(nUnites)) {
117
		lens[nUnites] = 0;
118
		lensnames[nUnites] = [];
119
	}
120
	
121
	lens[nUnites] = lens[nUnites] + 1;
122
	lensnames[nUnites] << schema.getProp(schema_property_name)
123
	nSchemas++;
124
}
125

  
126
//println "nSchemas=$nSchemas"
127
def freqs = lens.keySet();
128
freqs.sort();
129
int t = 0;
130
int n = 0;
131
//println "Fréquences ("+freqs.size()+")"
132
for (def f : freqs) {
133
	t += f * lens[f]
134
	n += lens[f]
135
}
136

  
137
coef = (t/n)
138
def slens = lens.sort { a, b -> -a.value <=> -b.value ?: -a.key <=> -b.key }
139
def flens = []
140
slens.each { key, value -> value.times { flens << key } }
141
def nbins = flens.size()*2
142

  
143
def cfreq = 0
144
println "longueur moyenne des chaînes de référence : $t/$n = "+coef
145
println "index hiérarchique des longueurs de chaînes :\nlen\tfreq\tcfreq"
146
slens.each { println it.key+"	"+it.value+"	"+(cfreq+=it.value)+"	"+lensnames[it.key] }
147

  
148
def slens2 = slens.sort { a, b -> -a.key <=> -b.key }
149

  
150
def r = RWorkspace.getRWorkspaceInstance()
151

  
152
r.addVectorToWorkspace("len", slens2.keySet() as int[])
153
r.addVectorToWorkspace("freq", slens2.values() as int[])
154
r.addVectorToWorkspace("flen", flens as int[])
155

  
156
def corpusName = corpus.getID()
157

  
158
def PNGFile = File.createTempFile("txm", ".png", new File(Toolbox.getTxmHomePath(), "results"))
159
def PNGFilePath = PNGFile.getAbsolutePath()
160
println "PNG file: "+PNGFilePath
161

  
162
def SVGFile = File.createTempFile("txm", ".svg", new File(Toolbox.getTxmHomePath(), "results"))
163
def SVGFilePath = SVGFile.getAbsolutePath()
164
println "SVG file: "+SVGFilePath
165

  
166
/// BEGINNING OF R SCRIPT
167
def script ="""
168
hist(flen, xaxt='n', col="gray", xlab="Length", breaks=$nbins, main="$corpusName Longueur des chaînes ($nbins bins)")
169
axis(side=1, at=len)
170
dev.off()
171
"""
172
/// END OF R SCRIPT
173

  
174
// execute R script
175
r.plot(PNGFile, "png(file = \"${PNGFilePath}\"); "+script)
176
r.plot(SVGFile, "svg(file = \"${SVGFilePath}\"); "+script)
177

  
178
//display the SVG results graphic
179
monitor.syncExec(new Runnable() {
180
	@Override
181
	public void run() { OpenSVGGraph.OpenSVGFile(SVGFilePath, corpusName+" Longueur des chaînes") }
182
})
183

  
184
return ["result":coef, "data":lens]
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/mesures1/CoefficientStabiliteMacro.groovy (revision 1962)
1
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
2
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3
// @author mdecorde
4
// @author sheiden
5
// STANDARD DECLARATIONS
6
package org.txm.macro.urs.exploit.mesures1
7

  
8
import org.kohsuke.args4j.*
9
import groovy.transform.Field
10
import org.txm.*
11
import org.txm.rcp.swt.widget.parameters.*
12
import org.txm.annotation.urs.*
13
import org.txm.searchengine.cqp.corpus.*
14
import org.apache.commons.lang.StringUtils;
15

  
16
// BEGINNING OF PARAMETERS
17
@Field @Option(name="schema_type",usage="", widget="String", required=true, def="CHAINE")
18
String schema_type
19

  
20
@Field @Option(name="minimum_schema_size", usage="", widget="Integer", required=true, def="3")
21
int minimum_schema_size
22

  
23
@Field @Option(name="schema_property_name",usage="", widget="String", required=false, def="")
24
String schema_property_name
25

  
26
@Field @Option(name="schema_display_property_name",usage="", widget="String", required=false, def="REF")
27
String schema_display_property_name
28

  
29
@Field @Option(name="schema_property_value",usage="", widget="String", required=false, def=".*")
30
String schema_property_value
31

  
32
@Field @Option(name="unit_type",usage="", widget="String", required=false, def="MENTION")
33
String unit_type
34

  
35
@Field @Option(name="unit_property_name", usage="", widget="String", required=false, def="CATEGORIE")
36
String unit_property_name
37

  
38
@Field @Option(name="unit_property_value", usage="", widget="String", required=false, def="GN Défini|GN Démonstratif|Nom Propre")
39
String unit_property_value
40

  
41
@Field @Option(name="word_property", usage="", widget="String", required=false, def="word")
42
String word_property
43

  
44
if (!(corpusViewSelection instanceof MainCorpus)) {
45
	println "Corpora selection is not a Corpus"
46
	return;
47
}
48

  
49
// Open the parameters input dialog box
50
if (!ParametersDialog.open(this)) return;
51
// END OF PARAMETERS
52

  
53
MainCorpus corpus = corpusViewSelection
54
def analecCorpus = URSCorpora.getCorpus(corpus)
55

  
56
// check Schema parameters
57
if (!analecCorpus.getStructure().getSchemas().contains(schema_type)) {
58
	println "No schema with name=$schema_type"
59
	return;
60
} else {
61
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
62
		// test property existance
63
		def props = analecCorpus.getStructure().getSchemaProperties(schema_type);
64
		if (!props.contains(schema_property_name)) {
65
			println "Schema $schema_type has no property named $schema_property_name"
66
			return;
67
		}
68
	}
69
}
70

  
71
// check unit parameters
72
if (!analecCorpus.getStructure().getUnites().contains(unit_type)) {
73
	println "No unit with name=$unit_type"
74
	return;
75
} else {
76
	if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
77
		// test property existance
78
		def props = analecCorpus.getStructure().getUniteProperties(unit_type);
79
		if (!props.contains(unit_property_name)) {
80
			println "Unit $unit_type has no property named $unit_property_name"
81
			return;
82
		}
83
	}
84
}
85

  
86
def CQI = CQPSearchEngine.getCqiClient()
87

  
88
def prop = corpus.getProperty(word_property)
89

  
90
def schemas = analecCorpus.getSchemas(schema_type)
91
allFormesSet = new HashSet();
92
nUnitesGrandTotal = 0;
93
def coefs = []
94
int n = 1
95
for (def schema : schemas) {
96
	def formesSet = new HashSet(); // contient toutes les formes du CR courant
97
	nUnitesTotal = 0;
98
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
99
		if (!schema.getProp(schema_property_name).matches(schema_property_value)) {
100
			// ignoring this schema
101
			continue
102
		}
103
	}
104
	
105
	def units = schema.getUnitesSousjacentesNonTriees()
106
	def nUnites = units.size();
107
	
108
	if (nUnites < minimum_schema_size) continue;
109

  
110
	for (def unit : units) {
111
	
112
		if (unit_type.length() > 0) {
113
			if (!unit.getType().equals(unit_type)) {
114
				continue
115
			}
116
		}
117
		
118
		if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
119
			if (!unit.getProp(unit_property_name).matches(unit_property_value)) {
120
				// ignoring this schema
121
				continue
122
			}
123
		}
124
		
125
		String forme =  null;
126
		if (prop == null) { // word_property is the analec unit property to use
127
			forme = unit.getProp(word_property)
128
		} else {
129
			int[] pos = null;
130
			if (unit.getDeb() == unit.getFin()) pos = [unit.getDeb()]
131
			else pos = unit.getDeb()..unit.getFin()
132
				
133
			forme = StringUtils.join(CQI.cpos2Str(prop.getQualifiedName(), pos), " ") // ids is enough
134
		}
135
		
136
		formesSet.add(forme)
137
		
138
		nUnitesTotal++
139
	}
140
	if (formesSet.size() == 0) {
141
		coef = -1
142
	} else {
143
		coef = (nUnitesTotal/formesSet.size())
144
	}
145
	coefs << coef
146
	nUnitesGrandTotal += nUnitesTotal;
147
	allFormesSet.addAll(formesSet)
148
	
149
	if (schema_display_property_name != null) {
150
		print schema.getProp(schema_display_property_name)
151
	} else {
152
		print schema_type+"-"+n+" : "
153
	}
154
	
155
	println " ($nUnites units) : $nUnitesTotal selected units / ${formesSet.size()} forms = $coef"
156
	n++
157
}
158

  
159
return ["result":coefs, "data":["nUnitesTotal":nUnitesGrandTotal, "allFormesSet":allFormesSet], "coef":(nUnitesGrandTotal/allFormesSet.size())]
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/mesures1/PremierMaillonMacro.groovy (revision 1962)
1
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
2
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3
// @author mdecorde
4
// @author sheiden
5
// STANDARD DECLARATIONS
6
package org.txm.macro.urs.exploit.mesures1
7

  
8
import org.kohsuke.args4j.*
9

  
10
import groovy.transform.Field
11

  
12
import org.txm.rcp.swt.widget.parameters.*
13
import org.txm.annotation.urs.*
14
import org.txm.searchengine.cqp.corpus.*
15

  
16
import visuAnalec.donnees.Structure;
17
import visuAnalec.elements.Unite;
18
import visuAnalec.vue.Vue
19

  
20
if (!(corpusViewSelection instanceof MainCorpus)) {
21
	println "Corpora selection is not a Corpus"
22
	return;
23
}
24

  
25
// BEGINNING OF PARAMETERS
26
@Field @Option(name="unit_type",usage="", widget="String", required=true, def="Maillon")
27
String unit_type
28
@Field @Option(name="reset",usage="", widget="Boolean", required=true, def="true")
29
boolean reset
30

  
31
if (!ParametersDialog.open(this)) return;
32

  
33
MainCorpus corpus = corpusViewSelection
34
def analecCorpus = URSCorpora.getCorpus(corpus);
35
Structure structure = analecCorpus.getStructure()
36
if (!structure.getUnites().contains(unit_type)) { // check if the structure contains the unit_type units
37
	println "Error: corpus structure does not contains unit with name=$unit_type"
38
	return
39
}
40
def props = structure.getUniteProperties(unit_type)
41

  
42
String NEW = "NEW"
43
String REF = "REF"
44
String YES = "YES"
45
String NO = "NO"
46
if (!props.contains(NEW)) { // update the structure if needed
47
	analecCorpus.ajouterProp(Unite.class, unit_type, NEW);
48
	analecCorpus.ajouterVal(Unite.class, unit_type, NEW, "YES");
49
	analecCorpus.ajouterVal(Unite.class, unit_type, NEW, "NO");
50
}
51

  
52
if (!props.contains(REF)) { // check the unit_type units have the REF property
53
	println "Error: $unit_type units have no proprerty named 'REF'"
54
	return
55
}
56

  
57
int nIgnored = 0; // number of units ignored
58
int nYes = 0 // number of "YES" unit set
59
int nNo = 0 // number of "NO" unit set
60

  
61
def allRefs = new HashSet<String>() // store the references already seen, allow to set the 'NEW' property to 'YES' or 'NO'
62
def units = analecCorpus.getUnites(unit_type)
63
units.sort() { a, b -> a.getDeb() <=> b.getDeb() ?: a.getFin() <=> b.getFin() }
64
for (Unite unit : units) {
65
	def prop = unit.getProp(NEW);
66
	def ref = unit.getProp(REF);
67
	if (reset || prop == null || prop.length() == 0) {
68
		if (allRefs.contains(ref)) {
69
			unit.getProps().put(NEW, NO)
70
			nNo++
71
		} else { // this is the first MENTION of the CHAINE
72
			allRefs << ref
73
			unit.getProps().put(NEW, YES)
74
			nYes++
75
		}
76
	} else {
77
		// nothing to do "NEW" already exists
78
		nIgnored++
79
	}
80
}
81

  
82
println "nIgnored=$nIgnored"
83
println "nYes=$nYes"
84
println "nNo=$nNo"
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/mesures1/DensiteReferentielleMacro.groovy (revision 1962)
1
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
2
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3
// @author mdecorde
4
// @author sheiden
5
// STANDARD DECLARATIONS
6
package org.txm.macro.urs.exploit.mesures1
7

  
8
import org.kohsuke.args4j.*
9
import groovy.transform.Field
10
import org.txm.rcp.swt.widget.parameters.*
11
import org.txm.annotation.urs.*
12
import org.txm.searchengine.cqp.corpus.*
13

  
14
if (!(corpusViewSelection instanceof MainCorpus)) {
15
	println "Corpora selection is not a Corpus"
16
	return;
17
}
18

  
19
@Field @Option(name="unit_type",usage="", widget="String", required=false, def="MENTION")
20
String unit_type
21

  
22
@Field @Option(name="unit_property_name", usage="", widget="String", required=false, def="")
23
String unit_property_name
24

  
25
@Field @Option(name="unit_property_value", usage="", widget="String", required=false, def=".*")
26
String unit_property_value
27

  
28
if (!ParametersDialog.open(this)) return;
29
// END OF PARAMETERS
30

  
31
MainCorpus corpus = corpusViewSelection
32
def analecCorpus = URSCorpora.getCorpus(corpus);
33

  
34
// check unit parameters
35
if (!analecCorpus.getStructure().getUnites().contains(unit_type)) {
36
	println "No unit with name=$unit_type"
37
	return;
38
} else {
39
	if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
40
		// test property existance
41
		def props = analecCorpus.getStructure().getUniteProperties(unit_type);
42
		if (!props.contains(unit_property_name)) {
43
			println "Unit $unit_type has no property named $unit_property_name"
44
			return;
45
		}
46
	}
47
}
48

  
49
int nMots = corpus.getSize();
50

  
51
int nUnites = 0;
52
	for (def unit : analecCorpus.getToutesUnites()) {
53
		if (unit_type.length() > 0) {
54
			if (!unit.getType().equals(unit_type)) {
55
				continue
56
			}
57
		}
58
		
59
		if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
60
			if (!unit.getProp(unit_property_name).matches(unit_property_value)) {
61
				// ignoring this schema
62
				continue
63
			}
64
		}
65
	
66
		nUnites++
67
	}
68

  
69
coef = (nUnites /nMots)
70
println "densité référentielle : nUnites/nMots = $nUnites/$nMots = $coef = ${coef*100}%"
71
if (nUnites >= nMots) {
72
	println "WARNING: possible encoding error. Number of units ($nUnites) is greater than number of words ($nMots)"
73
}
74
return ["result":coef, "data":["nUnites":nUnites, "nMots":nMots]]
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/mesures1/NombreDeChainesMacro.groovy (revision 1962)
1
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
2
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3
// @author mdecorde
4
// @author sheiden
5
// STANDARD DECLARATIONS
6
package org.txm.macro.urs.exploit.mesures1
7

  
8
import org.kohsuke.args4j.*
9
import groovy.transform.Field
10
import org.txm.rcp.swt.widget.parameters.*
11
import org.txm.annotation.urs.*
12
import org.txm.searchengine.cqp.corpus.*
13

  
14

  
15
// BEGINNING OF PARAMETERS
16
@Field @Option(name="schema_type",usage="", widget="String", required=true, def="CHAINE")
17
String schema_type
18

  
19
@Field @Option(name="minimum_schema_size",usage="", widget="Integer", required=true, def="3")
20
int minimum_schema_size
21

  
22
@Field @Option(name="schema_property_name",usage="", widget="String", required=false, def="")
23
String schema_property_name
24

  
25
@Field @Option(name="schema_property_value",usage="", widget="String", required=false, def=".*")
26
String schema_property_value
27

  
28
@Field @Option(name="unit_type",usage="", widget="String", required=false, def="MENTION")
29
String unit_type
30

  
31
@Field @Option(name="unit_property_name", usage="", widget="String", required=false, def="")
32
String unit_property_name
33

  
34
@Field @Option(name="unit_property_value", usage="", widget="String", required=false, def=".*")
35
String unit_property_value
36

  
37
if (!(corpusViewSelection instanceof MainCorpus)) {
38
	println "Corpora selection is not a Corpus"
39
	return;
40
}
41

  
42
// Open the parameters input dialog box
43
if (!ParametersDialog.open(this)) return;
44
// END OF PARAMETERS
45

  
46
MainCorpus corpus = corpusViewSelection
47
def analecCorpus = URSCorpora.getCorpus(corpus)
48

  
49
// check Schema parameters
50
if (!analecCorpus.getStructure().getSchemas().contains(schema_type)) {
51
	println "No schema with name=$schema_type"
52
	return;
53
} else {
54
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
55
		// test property existance
56
		def props = analecCorpus.getStructure().getSchemaProperties(schema_type);
57
		if (!props.contains(schema_property_name)) {
58
			println "Schema $schema_type has no property named $schema_property_name"
59
			return;
60
		}
61
	}
62
}
63

  
64
// check unit parameters
65
if (!analecCorpus.getStructure().getUnites().contains(unit_type)) {
66
	println "No unit with name=$unit_type"
67
	return;
68
} else {
69
	if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
70
		// test property existance
71
		def props = analecCorpus.getStructure().getUniteProperties(unit_type);
72
		if (!props.contains(unit_property_name)) {
73
			println "Unit $unit_type has no property named $unit_property_name"
74
			return;
75
		}
76
	}
77
}
78

  
79
def schemas = analecCorpus.getSchemas(schema_type)
80

  
81
int nSchemas = 0;
82
for (def schema : schemas) {
83

  
84
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
85
		if (!schema.getProp(schema_property_name).matches(schema_property_value)) {
86
			// ignoring this schema
87
			continue
88
		}
89
	}
90
	
91
	int nUnites = 0;
92
	for (def unit : schema.getUnitesSousjacentesNonTriees()) {
93
	if (unit_type.length() > 0) {
94
			if (!unit.getType().equals(unit_type)) {
95
				continue
96
			}
97
		}
98
		
99
		if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
100
			if (!unit.getProp(unit_property_name).matches(unit_property_value)) {
101
				// ignoring this schema
102
				continue
103
			}
104
		}
105
	
106
		nUnites++
107
	}
108
	
109
	if (nUnites < minimum_schema_size) continue;
110

  
111
	nSchemas++;
112
}
113

  
114
println "nombre de chaînes de référence d'un texte : $nSchemas"
115

  
116
["result":nSchemas, "data":schemas]
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/mesures1/DistanceInterMaillonnaireMacro.groovy (revision 1962)
1
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
2
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3
// @author mdecorde
4
// @author sheiden
5
// STANDARD DECLARATIONS
6
package org.txm.macro.urs.exploit.mesures1
7

  
8
import org.kohsuke.args4j.*
9
import groovy.transform.Field
10
import org.txm.*
11
import org.txm.rcp.swt.widget.parameters.*
12
import org.txm.annotation.urs.*
13
import org.txm.searchengine.cqp.corpus.*
14
import org.apache.commons.lang.StringUtils;
15

  
16
// BEGINNING OF PARAMETERS
17
@Field @Option(name="schema_type",usage="", widget="String", required=true, def="CHAINE")
18
String schema_type
19

  
20
@Field @Option(name="minimum_schema_size", usage="", widget="Integer", required=true, def="3")
21
int minimum_schema_size
22

  
23
@Field @Option(name="schema_property_name",usage="", widget="String", required=false, def="")
24
String schema_property_name
25

  
26
@Field @Option(name="schema_property_value",usage="", widget="String", required=false, def=".*")
27
String schema_property_value
28

  
29
@Field @Option(name="unit_type",usage="", widget="String", required=false, def="MENTION")
30
String unit_type
31

  
32
@Field @Option(name="unit_property_name", usage="", widget="String", required=false, def="")
33
String unit_property_name
34

  
35
@Field @Option(name="unit_property_value", usage="", widget="String", required=false, def=".*")
36
String unit_property_value
37

  
38
if (!(corpusViewSelection instanceof MainCorpus)) {
39
	println "Corpora selection is not a Corpus"
40
	return;
41
}
42

  
43
if (!ParametersDialog.open(this)) return;
44

  
45
MainCorpus corpus = corpusViewSelection
46
def analecCorpus = URSCorpora.getCorpus(corpus)
47

  
48
// check Schema parameters
49
if (!analecCorpus.getStructure().getSchemas().contains(schema_type)) {
50
	println "No schema with name=$schema_type"
51
	return;
52
} else {
53
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
54
		// test property existance
55
		def props = analecCorpus.getStructure().getSchemaProperties(schema_type);
56
		if (!props.contains(schema_property_name)) {
57
			println "Schema $schema_type has no property named $schema_property_name"
58
			return;
59
		}
60
	}
61
}
62

  
63
// check unit parameters
64
if (!analecCorpus.getStructure().getUnites().contains(unit_type)) {
65
	println "No unit with name=$unit_type"
66
	return;
67
} else {
68
	if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
69
		// test property existance
70
		def props = analecCorpus.getStructure().getUniteProperties(unit_type);
71
		if (!props.contains(unit_property_name)) {
72
			println "Unit $unit_type has no property named $unit_property_name"
73
			return;
74
		}
75
	}
76
}
77

  
78
def schemas = analecCorpus.getSchemas(schema_type)
79
def distances = [];
80
def nDistances = 0
81
def cadences = [];
82
for (def schema : schemas) {
83

  
84
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
85
		if (!schema.getProp(schema_property_name).matches(schema_property_value)) {
86
			// ignoring this schema
87
			continue
88
		}
89
	}
90
	
91
	def allUnites = schema.getUnitesSousjacentesNonTriees()
92
	int nUnites = allUnites.size()
93
	if (nUnites < minimum_schema_size) continue;
94

  
95
	def units = []
96
	for (def unit : allUnites) {
97
	
98
		if (unit_type.length() > 0) {
99
			if (!unit.getType().equals(unit_type)) {
100
				continue
101
			}
102
		}
103
		
104
		if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
105
			if (!unit.getProp(unit_property_name).matches(unit_property_value)) {
106
				// ignoring this schema
107
				continue
108
			}
109
		}
110
		
111
		units << unit
112
	}
113
	
114
	Collections.sort(units)
115
		
116
	for (int i = 0 ; i < units.size() ; i++) {
117
		int d1 = 0;
118
		int d2 = 0;
119
		if (i < units.size()-1) d1 = units[i+1].getDeb() - units[i].getFin();
120
		if (d1 < 0) {
121
			//println "D1 "+units[i+1].getDeb()+" - "+units[i].getFin()+" = "+d1
122
			d1 = 0; // the first unit pass the next one ?
123
		}
124
		if (i > 0) d2 = units[i].getDeb() - units[i-1].getFin();
125
		if (d2 < 0) {
126
			//println "D2 "+units[i].getDeb()+" - "+units[i-1].getFin()+" = "+d2
127
			d2 = 0; // the first unit pass the next one ?
128
		}
129
		distances << d1
130
		
131
		if (d1 < d2) cadences << d1 else cadences << d2
132
		
133
		nDistances++
134
	}
135
}
136
distances = distances.sort()
137
cadences = cadences.sort()
138

  
139
int distances_total = distances.sum()
140
int cadences_total = cadences.sum()
141
coef = (distances_total / nDistances)
142
cadence = (cadences_total / nDistances)
143
println "distances $distances"
144
println "distance moyenne inter-mayonnaise : $distances_total / $nDistances = $coef"
145
println "distance medianne inter-mayonnaise : "+distances[(int)(distances.size() / 2)]
146
println "distance quartils : "+distances[0]+" "+distances[(int)(distances.size() / 4)] + " "+distances[(int)(distances.size() / 2)]+" "+distances[(int)(3*distances.size() / 4)]+" "+distances[(int)(distances.size() -1)]
147
println "cadences $cadences"
148
println "cadence moyenne : $cadences_total / $nDistances = $cadence"
149
println "cadence medianne : "+cadences[(int)(cadences.size() / 2)]
150
println "cadence quartils : "+cadences[0]+" "+cadences[(int)(cadences.size() / 4)] + " "+cadences[(int)(cadences.size() / 2)]+" "+cadences[(int)(3*cadences.size() / 4)]+" "+cadences[(int)(cadences.size() -1)]
151

  
152
return ["result":coef, "result2":cadence, "data":["distances":distances, "nDistances":nDistances, "cadences":cadences]]
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/mesures1/NatureDuPremierMaillonMacro.groovy (revision 1962)
1
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
2
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3
// @author mdecorde
4
// @author sheiden
5
// STANDARD DECLARATIONS
6
package org.txm.macro.urs.exploit.mesures1
7

  
8
import org.kohsuke.args4j.*
9
import groovy.transform.Field
10
import org.txm.*
11
import org.txm.rcp.swt.widget.parameters.*
12
import org.txm.annotation.urs.*
13
import org.txm.searchengine.cqp.corpus.*
14
import org.apache.commons.lang.StringUtils;
15

  
16
// BEGINNING OF PARAMETERS
17
@Field @Option(name="schema_type",usage="", widget="String", required=true, def="CHAINE")
18
String schema_type
19

  
20
@Field @Option(name="minimum_schema_size", usage="", widget="Integer", required=true, def="3")
21
int minimum_schema_size
22

  
23
@Field @Option(name="schema_property_name",usage="", widget="String", required=false, def="")
24
String schema_property_name
25

  
26
@Field @Option(name="schema_property_value",usage="", widget="String", required=false, def=".*")
27
String schema_property_value
28

  
29
@Field @Option(name="unit_type",usage="", widget="String", required=false, def="MENTION")
30
String unit_type
31

  
32
@Field @Option(name="unit_property_name", usage="", widget="String", required=false, def="")
33
String unit_property_name
34

  
35
@Field @Option(name="unit_property_value", usage="", widget="String", required=false, def=".*")
36
String unit_property_value
37

  
38
@Field @Option(name="word_property", usage="", widget="String", required=false, def="CATEGORIE")
39
String word_property
40

  
41
if (!(corpusViewSelection instanceof MainCorpus)) {
42
	println "Corpora selection is not a Corpus"
43
	return;
44
}
45

  
46
// Open the parameters input dialog box
47
if (!ParametersDialog.open(this)) return;
48
// END OF PARAMETERS
49

  
50
MainCorpus corpus = corpusViewSelection
51
def analecCorpus = URSCorpora.getCorpus(corpus)
52

  
53
if (!analecCorpus.getStructure().getSchemas().contains(schema_type)) {
54
	println "No schema with name=$schema_type"
55
	return;
56
} else {
57
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
58
		// test property existance
59
		def props = analecCorpus.getStructure().getSchemaProperties(schema_type);
60
		if (!props.contains(schema_property_name)) {
61
			println "Schema $schema_type has no property named $schema_property_name"
62
			return;
63
		}
64
	}
65
}
66

  
67
if (!analecCorpus.getStructure().getUnites().contains(unit_type)) {
68
	println "No unit with name=$unit_type"
69
	return;
70
} else {
71
	if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
72
		// test property existance
73
		def props = analecCorpus.getStructure().getUniteProperties(unit_type);
74
		if (!props.contains(unit_property_name)) {
75
			println "Unit $unit_type has no property named $unit_property_name"
76
			return;
77
		}
78
	}
79
}
80

  
81
def CQI = CQPSearchEngine.getCqiClient()
82

  
83
def prop = corpus.getProperty(word_property)
84

  
85
def schemas = analecCorpus.getSchemas(schema_type)
86
def freqs = [:]
87

  
88
def distances = 0;
89
def nDistances = 0
90
for (def schema : schemas) {
91

  
92
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
93
		if (!schema.getProp(schema_property_name).matches(schema_property_value)) {
94
			// ignoring this schema
95
			continue
96
		}
97
	}
98
	
99
	def allUnites = schema.getUnitesSousjacentesNonTriees()
100
	int nUnites = allUnites.size()
101
	if (nUnites < minimum_schema_size) continue;
102

  
103
	def units = []
104
	for (def unit : allUnites) {
105
	
106
		if (unit_type.length() > 0) {
107
			if (!unit.getType().equals(unit_type)) {
108
				continue
109
			}
110
		}
111
		
112
		if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
113
			if (!unit.getProp(unit_property_name).matches(unit_property_value)) {
114
				// ignoring this schema
115
				continue
116
			}
117
		}
118
		
119
		units << unit
120
	}
121
	
122
	units.sort() { u1, u2 ->
123
		return u1.getDeb() - u2.getDeb()
124
	}
125
	if (units.size() == 0) continue;
126
	
127
	def unit = units[0]
128
	
129
	String forme =  null;
130
	if (prop == null) { // word_property is the analec unit property to use
131
		forme = unit.getProp(word_property)
132
	} else {
133
		int[] pos = null;
134
		if (unit.getDeb() == unit.getFin()) pos = [unit.getDeb()]
135
		else pos = unit.getDeb()..unit.getFin()
136
			
137
		forme = StringUtils.join(CQI.cpos2Str(prop.getQualifiedName(), pos), " ") // ids is enough
138
	}
139
	
140
	if (!freqs.containsKey(forme)) freqs[forme] = 0;
141
	
142
	freqs[forme] = freqs[forme] + 1;
143
}
144

  
145
println "index des natures de premier maillon :"
146
int max = 0;
147
def result = "";
148
for (def forme : freqs.keySet().sort() {it -> -freqs[it]}) {
149
	println "$forme\t"+freqs[forme]
150
	if (max < freqs[forme]) {
151
		max = freqs[forme]
152
		result = "$forme: "+freqs[forme]
153
	}
154
}
155

  
156
["result": result, "data": freqs]
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/mesures1/CategorieGrammaticaleMacro.groovy (revision 1962)
1
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
2
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3
// @author mdecorde
4
// @author sheiden
5
// STANDARD DECLARATIONS
6
package org.txm.macro.urs.exploit.mesures1
7

  
8
import org.kohsuke.args4j.*
9
import groovy.transform.Field
10
import org.txm.*
11
import org.txm.rcp.swt.widget.parameters.*
12
import org.txm.annotation.urs.*
13
import org.txm.searchengine.cqp.corpus.*
14
import org.apache.commons.lang.StringUtils;
15

  
16
// BEGINNING OF PARAMETERS
17
@Field @Option(name="schema_type",usage="", widget="String", required=true, def="CHAINE")
18
String schema_type
19

  
20
@Field @Option(name="minimum_schema_size", usage="", widget="Integer", required=true, def="3")
21
int minimum_schema_size
22

  
23
@Field @Option(name="schema_property_name",usage="", widget="String", required=false, def="")
24
String schema_property_name
25

  
26
@Field @Option(name="schema_property_value",usage="", widget="String", required=false, def=".*")
27
String schema_property_value
28

  
29
@Field @Option(name="schema_display_property_name",usage="", widget="String", required=false, def="REF")
30
String schema_display_property_name
31

  
32
@Field @Option(name="unit_type",usage="", widget="String", required=false, def="MENTION")
33
String unit_type
34

  
35
@Field @Option(name="unit_property_name", usage="", widget="String", required=false, def="")
36
String unit_property_name
37

  
38
@Field @Option(name="unit_property_value", usage="", widget="String", required=false, def=".*")
39
String unit_property_value
40

  
41
@Field @Option(name="word_property", usage="", widget="String", required=false, def="CATEGORIE")
42

  
43
String word_property
44

  
45
if (!(corpusViewSelection instanceof MainCorpus)) {
46
	println "Corpora selection is not a Corpus"
47
	return;
48
}
49

  
50
// Open the parameters input dialog box
51
if (!ParametersDialog.open(this)) return;
52
// END OF PARAMETERS
53

  
54
MainCorpus corpus = corpusViewSelection
55
def analecCorpus = URSCorpora.getCorpus(corpus)
56

  
57
if (!analecCorpus.getStructure().getSchemas().contains(schema_type)) {
58
	println "No schema with name=$schema_type"
59
	return;
60
} else {
61
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
62
		// test property existance
63
		def props = analecCorpus.getStructure().getSchemaProperties(schema_type);
64
		if (!props.contains(schema_property_name)) {
65
			println "Schema $schema_type has no property named $schema_property_name"
66
			return;
67
		}
68
	}
69
}
70

  
71
if (!analecCorpus.getStructure().getUnites().contains(unit_type)) {
72
	println "No unit with name=$unit_type"
73
	return;
74
} else {
75
	if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
76
		// test property existance
77
		def props = analecCorpus.getStructure().getUniteProperties(unit_type);
78
		if (!props.contains(unit_property_name)) {
79
			println "Unit $unit_type has no property named $unit_property_name"
80
			return;
81
		}
82
	}
83
}
84

  
85
def CQI = CQPSearchEngine.getCqiClient()
86

  
87
def prop = corpus.getProperty(word_property)
88
if (prop == null) {
89
	analecCorpus.getStructure()
90
}
91
def schemas = analecCorpus.getSchemas(schema_type)
92
def allFreqs = [:]
93
def n = 0
94
for (def schema : schemas) {
95
	n++
96
	
97
	def freqs = [:]
98
	
99
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
100
		if (!schema.getProp(schema_property_name).matches(schema_property_value)) {
101
			// ignoring this schema
102
			continue
103
		}
104
	}
105
	
106
	def allUnites = schema.getUnitesSousjacentesNonTriees()
107
	int nUnites = allUnites.size()
108
	if (nUnites < minimum_schema_size) continue;
109

  
110
	def units = []
111
	for (def unit : allUnites) { // no need to sort units
112
	
113
		if (unit_type.length() > 0) {
114
			if (!unit.getType().equals(unit_type)) {
115
				continue
116
			}
117
		}
118
		
119
		if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
120
			if (!unit.getProp(unit_property_name).matches(unit_property_value)) {
121
				// ignoring this schema
122
				continue
123
			}
124
		}
125
		
126
		String forme =  null;
127
		if (prop == null) { // word_property is the analec unit property to use
128
			forme = unit.getProp(word_property)
129
		} else {
130
			int[] pos = null;
131
			if (unit.getDeb() == unit.getFin()) pos = [unit.getDeb()]
132
			else pos = unit.getDeb()..unit.getFin()
133
				
134
			forme = StringUtils.join(CQI.cpos2Str(prop.getQualifiedName(), pos), " ") // ids is enough
135
		}
136
		
137
		if (!freqs.containsKey(forme)) freqs[forme] = 0;
138
		freqs[forme] = freqs[forme] + 1;
139
		
140
		if (!allFreqs.containsKey(forme)) allFreqs[forme] = 0;
141
		allFreqs[forme] = allFreqs[forme] + 1;
142
	}
143
	
144
	if (schema_display_property_name != null) {
145
		println "index des natures de $unit_type de '"+schema.getProp(schema_display_property_name)+"' : "
146
	} else {
147
		println "index des natures de $schema_type - $n : "
148
	}
149
	
150
	int max = 0;
151
	def result = "";
152
	for (def forme : freqs.sort() { a, b -> -a.value <=> -b.value ?: a.key <=> b.key }) {
153
		println forme.key+"\t"+forme.value
154
	}
155
}
156

  
157
int max = 0;
158
def result = "";
159

  
160
println "index des natures de $schema_type : "
161
for (def forme : allFreqs.sort() { a, b -> -a.value <=> -b.value ?: a.key <=> b.key }) {
162
	println forme.key+"\t"+forme.value
163
	if (max < forme.value) {
164
		max = forme.value
165
		result = "$forme: "+forme.value
166
	}
167
}
168

  
169
return ["result":result, "data":allFreqs]
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/mesures1/ChainesMacro.groovy (revision 1962)
1
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
2
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3
// @author mdecorde
4
// @author sheiden
5

  
6
// STANDARD DECLARATIONS
7
package org.txm.macro.urs.exploit.mesures1
8

  
9
import org.kohsuke.args4j.*
10
import groovy.transform.Field
11
import org.txm.rcp.swt.widget.parameters.*
12
import org.txm.annotation.urs.*
13
import org.txm.searchengine.cqp.corpus.*
14
import org.txm.Toolbox
15
import org.txm.rcp.commands.*
16
import org.apache.commons.lang.StringUtils
17

  
18
// BEGINNING OF PARAMETERS
19
@Field @Option(name="schema_type",usage="", widget="String", required=true, def="Coréférence")
20
String schema_type
21

  
22
@Field @Option(name="minimum_schema_size",usage="", widget="Integer", required=true, def="3")
23
int minimum_schema_size
24

  
25
@Field @Option(name="schema_property_name",usage="", widget="String", required=false, def="")
26
String schema_property_name
27

  
28
@Field @Option(name="schema_property_value",usage="", widget="String", required=false, def=".*")
29
String schema_property_value
30

  
31
@Field @Option(name="unit_type",usage="", widget="String", required=false, def="Maillon")
32
String unit_type
33

  
34
@Field @Option(name="unit_property_name", usage="", widget="String", required=false, def="")
35
String unit_property_name
36

  
37
@Field @Option(name="unit_property_value", usage="", widget="String", required=false, def=".*")
38
String unit_property_value
39

  
40
@Field @Option(name="word_property", usage="", widget="StringArray", metaVar="word	lemma	frlemma	frolemma	#forme#	id", required=false, def="word")
41
String word_property
42

  
43
@Field @Option(name="separator", usage="", widget="String", required=true, def=", ")
44
String separator
45

  
46
@Field @Option(name="buildCQL", usage="générer la requête des unités", widget="Boolean", required=true, def='false')
47
def buildCQL
48

  
49

  
50
if (!(corpusViewSelection instanceof MainCorpus)) {
51
	println "Corpus view selection is not a Corpus"
52
	return;
53
}
54

  
55
if (!ParametersDialog.open(this)) return;
56
// END OF PARAMETERS
57

  
58
MainCorpus corpus = corpusViewSelection
59
def analecCorpus = URSCorpora.getCorpus(corpus)
60

  
61
// check Schema parameters
62
if (!analecCorpus.getStructure().getSchemas().contains(schema_type)) {
63
	println "No schema with name=$schema_type"
64
	return;
65
} else {
66
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
67
		// test property existance
68
		def props = analecCorpus.getStructure().getSchemaProperties(schema_type);
69
		if (!props.contains(schema_property_name)) {
70
			println "Schema $schema_type has no property named $schema_property_name"
71
			return;
72
		}
73
	}
74
}
75

  
76
// check unit parameters
77
if (!analecCorpus.getStructure().getUnites().contains(unit_type)) {
78
	println "No unit with name=$unit_type"
79
	return;
80
} else {
81
	if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
82
		// test property existance
83
		def props = analecCorpus.getStructure().getUniteProperties(unit_type);
84
		if (!props.contains(unit_property_name)) {
85
			println "Unit $unit_type has no property named $unit_property_name"
86
			return;
87
		}
88
	}
89
}
90

  
91
def CQI = CQPSearchEngine.getCqiClient()
92

  
93
if (buildCQL) {
94
	word_prop = corpus.getProperty("id")
95
} else {
96
	word_prop = corpus.getProperty(word_property)
97
}
98

  
99
def schemas = analecCorpus.getSchemas(schema_type)
100
schemas.sort() {it.getProps()}
101
def nSchemas = 0
102

  
103
def lens = [:]
104
for (def schema : schemas) {
105

  
106
	if (schema_property_name.length() > 0 && schema_property_value.length() > 0) {
107
		if (!schema.getProp(schema_property_name).matches(schema_property_value)) {
108
			// ignoring this schema
109
			continue
110
		}
111
	}
112
	
113
	def nUnites = 0
114
	for (def unit : schema.getUnitesSousjacentes()) {
115
		if (unit_type.length() > 0) {
116
			if (!unit.getType().equals(unit_type)) {
117
				continue
118
			}
119
		}
120
		
121
		if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
122
			if (!unit.getProp(unit_property_name).matches(unit_property_value)) {
123
				// ignoring this schema
124
				continue
125
			}
126
		}
127

  
128
		nUnites++
129
	}
130

  
131
	if (nUnites < minimum_schema_size) continue
132

  
133
	print schema.getProps().toString()+ ": "
134
	def first = true
135
	for (def unit : schema.getUnitesSousjacentes()) {
136
		if (unit_type.length() > 0) {
137
			if (!unit.getType().equals(unit_type)) {
138
				continue
139
			}
140
		}
141
		
142
		if (unit_property_name.length() > 0 && unit_property_value.length() > 0) {
143
			if (!unit.getProp(unit_property_name).matches(unit_property_value)) {
144
				// ignoring this schema
145
				continue
146
			}
147
		}
148

  
149
		String forme =  null;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff