Revision 1973

tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosContribution.java (revision 1973)
1
package org.txm.rcp.menu;
2

  
3
import java.io.File;
4

  
5
import org.eclipse.jface.action.ContributionItem;
6
import org.eclipse.osgi.util.NLS;
7
import org.eclipse.swt.SWT;
8
import org.eclipse.swt.events.SelectionAdapter;
9
import org.eclipse.swt.events.SelectionEvent;
10
import org.eclipse.swt.widgets.Menu;
11
import org.eclipse.swt.widgets.MenuItem;
12
import org.eclipse.ui.IWorkbenchPart;
13
import org.eclipse.ui.IWorkbenchWindow;
14
import org.txm.Toolbox;
15
import org.txm.rcp.TXMWindows;
16
import org.txm.rcp.handlers.scripts.ExecuteGroovyMacro;
17
import org.txm.rcp.views.corpora.CorporaView;
18
import org.txm.utils.logger.Log;
19

  
20
public class MacrosContribution extends ContributionItem {
21

  
22
	public MacrosContribution() {
23
	}
24

  
25
	public MacrosContribution(String id) {
26
		super(id);
27
	}
28

  
29
	@Override
30
	public void fill(Menu menu, int index) {
31
		
32
		
33
		//create the menu item
34
		final File macroDirectory = new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/org/txm/macro/ui");
35
		File[] files = macroDirectory.listFiles();
36
		if (files == null || files.length == 0) {
37
			MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
38
			menuItem.setText("<no macro>");
39
			menuItem.addSelectionListener(new SelectionAdapter() {
40

  
41
				public void widgetSelected(SelectionEvent e) {
42
					Log.info(NLS.bind("To populate this menu, you must create macros in the {0} directory .", macroDirectory));
43
				}
44
			});
45
			return;
46
		}
47
		for (File f : files) {
48
			if (f.getName().endsWith("Macro.groovy")) {
49
				MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
50
				menuItem.setText(f.getName());
51
				menuItem.addSelectionListener(new MacroSelectionAdapter(f));
52
			}
53
		}
54
	}
55
	
56
	public class MacroSelectionAdapter extends SelectionAdapter {
57
		File macro;
58
		public MacroSelectionAdapter(File macro) {
59
			this.macro = macro;
60
		}
61
		
62
		public void widgetSelected(SelectionEvent e) {
63
			IWorkbenchWindow acWindow = TXMWindows.getActiveWindow();
64
			IWorkbenchPart page = acWindow.getActivePage().getActivePart();
65
			ExecuteGroovyMacro.execute(macro.getAbsolutePath(), page, CorporaView.getInstance().getTreeViewer().getSelection(), "");
66
		}
67
	}
68
}
0 69

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/ApplicationWorkbenchAdvisor.java (revision 1973)
55 55
import org.eclipse.core.runtime.preferences.DefaultScope;
56 56
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine;
57 57
import org.eclipse.e4.ui.css.swt.theme.IThemeManager;
58
import org.eclipse.jface.action.IMenuManager;
59
import org.eclipse.jface.action.MenuManager;
58 60
import org.eclipse.jface.dialogs.MessageDialog;
59 61
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
60 62
import org.eclipse.jface.operation.IRunnableWithProgress;
......
984 986
										ResourcesPlugin.getWorkspace().save(true, null);
985 987
									}
986 988
									monitor.worked(20);
989
									
987 990
									jobHandler.setTaskName("Toolbox ready.");
988 991
								} catch (Exception e) {
989 992
									// TODO Auto-generated catch block
......
993 996

  
994 997
							monitor.done(); 
995 998
						}
999

  
1000
						
996 1001
					});
997 1002

  
998 1003
					Log.fine(TXMUIMessages.loadingViews);
tmp/org.txm.rcp/plugin.xml (revision 1973)
1054 1054
            </separator>
1055 1055
         </menu>
1056 1056
         <menu
1057
               id="menu.macros"
1058
               label="Macros">
1059
            <dynamic
1060
                  class="org.txm.rcp.menu.MacrosContribution"
1061
                  id="org.txm.rcp.menu.MacrosContribution">
1062
            </dynamic>
1063
         </menu>
1064
         <menu
1057 1065
               id="menu.display"
1058 1066
               label="%menu.label.7"
1059 1067
               tooltip="%menu.tooltip.0">
tmp/org.txm.cooccurrence.core/src/org/txm/cooccurrence/core/functions/Cooccurrence.java (revision 1973)
1484 1484
		query += "] "; //$NON-NLS-1$
1485 1485
		
1486 1486
		int maxempan = Math.max(this.getMaxLeft(), this.getMaxRight()); 
1487
		if (this.getIncludeXPivot() && maxempan == 0) maxempan = 1;  
1487
		if (this.getIncludeXPivot() && maxempan == 0) maxempan = 1;
1488 1488
		
1489 1489
		String maxempanstr = "within " + maxempan + " "; //$NON-NLS-1$ //$NON-NLS-2$
1490 1490
		if (this.getStructuralUnitLimit() != null) maxempanstr += this.getStructuralUnitLimit().getName(); 
1491
		if (this.getMaxLeft() == 0) {
1492
			query = ""+this.getQuery()+" []* "+query+" "+maxempanstr; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
1493
		} else if (this.getMaxRight() == 0) {
1494
			query = ""+query+" []* "+this.getQuery()+" "+maxempanstr; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
1495
		} else {
1496
			query = "("+this.getQuery()+" []* "+query+") | ("+query+" []* "+this.getQuery()+") "+maxempanstr; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
1497
		}
1491 1498
		
1492
		query = "("+this.getQuery()+" []* "+query+") | ("+query+" []* "+this.getQuery()+") "+maxempanstr; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
1493
		
1494 1499
		return query;
1495 1500
	}
1496 1501
	
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/edit/CreationRelationsMacro.groovy (revision 1973)
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
// STANDARD DECLARATIONS
5
package org.txm.macro.urs.edit
6

  
7
import org.kohsuke.args4j.*
8

  
9
import groovy.transform.Field
10

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

  
15
import visuAnalec.donnees.Structure;
16
import visuAnalec.elements.Relation;
17
import visuAnalec.elements.Schema
18
import visuAnalec.elements.Unite;
19
import visuAnalec.vue.Vue
20

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

  
26
// BEGINNING OF PARAMETERS
27
@Field @Option(name="unit_type",usage="", widget="String", required=true, def="MENTION")
28
		String unit_type
29
@Field @Option(name="schema_type",usage="", widget="String", required=true, def="CHAINE")
30
		String schema_type
31
if (!ParametersDialog.open(this)) return;
32

  
33
int nCreated = 0 // count the number of created RELATION
34

  
35
MainCorpus corpus = corpusViewSelection
36
def analecCorpus = URSCorpora.getCorpus(corpus); // analec corpus has the same name has the TXM corpus
37
Structure structure = analecCorpus.getStructure()
38
if (!structure.getUnites().contains(unit_type)) { // check if the structure contains the unit_type units
39
	println "Error: corpus structure does not contains unit with name=$unit_type"
40
	return
41
}
42
if (!structure.getSchemas().contains(schema_type)) { // check if the structure contains the unit_type units
43
	println "Error: corpus structure does not contains schema with name=$schema_type"
44
	return
45
}
46
if (!structure.getRelations().contains("ANAPHORE")) { // update the structure if needed
47
	println "Creating the 'ANAPHORE' relation in the structure"
48
	structure.ajouterType(Relation.class, "ANAPHORE")
49
	analecCorpus.ajouterProp(Relation.class, "ANAPHORE", "TYPE")
50
	analecCorpus.ajouterVal(Relation.class, "ANAPHORE", "TYPE", "COREFERENTE")
51
	analecCorpus.ajouterVal(Relation.class, "ANAPHORE", "TYPE", "ASSOCIATIVE")
52
}
53
if (analecCorpus.getRelations("ANAPHORE").size() > 0) {
54
	println "Error: This macro can't update existing Relations"
55
	return
56
}
57

  
58
for (Schema schema : analecCorpus.getSchemas(schema_type)) { // parse all CHAINE
59
	def units = []
60
	for (Unite unit : schema.getUnitesSousjacentes()) { // keep only the 'unit_type' units
61
		if (unit.type.equals(unit_type)) units << unit
62
	}
63
	units.sort() { a, b -> a.getDeb() <=> b.getDeb() ?: a.getFin() <=> b.getFin() } // sort them
64
	
65
	for (int i = 0 ; i < units.size() - 1 ; i++) { // build RELATIONS and don't process the last unit
66
		println "creating "+units[i+1]+", "+units[i]
67
		Relation relation = new Relation("ANAPHORE", units[i+1], units[i])
68
		relation.getProps().put("TYPE", "COREFERENTE")
69
		analecCorpus.addRelationLue(relation)  // add the new relation
70
		nCreated++;
71
	}
72
}
73

  
74
println "nCreated=$nCreated"
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/edit/UnitsAnnotateMacro.groovy (revision 1973)
16 16
import org.txm.macro.urs.AnalecUtils
17 17
import org.txm.searchengine.cqp.AbstractCqiClient
18 18
import org.txm.searchengine.cqp.corpus.*
19
import org.txm.searchengine.cqp.corpus.query.CQLQuery
19 20

  
21
import visuAnalec.donnees.Corpus
20 22
import visuAnalec.donnees.Structure
21 23
import visuAnalec.elements.*
22 24
import visuAnalec.vue.Vue
......
41 43
		int minimum_schema_size
42 44
@Field @Option(name="unit_ursql", usage="TYPE@PROP=VALUE", widget="String", required=false, def="MENTION")
43 45
		String unit_ursql
46
@Field @Option(name="limit_distance_in_schema", usage="Unit distance in schema (0 = no selection, 1 = first after limit, -1 = last before limit, etc.)", widget="Integer", required=true, def="0")
47
		int limit_distance_in_schema
44 48
@Field @Option(name="limit_cql", usage="CQL to build structure limits", widget="Query", required=true, def="<div> [] expand to div")
45 49
		limit_cql
46 50
@Field @Option(name="strict_inclusion", usage="Units must be strictly included into corpus matches", widget="Boolean", required=true, def="true")
......
57 61
if (!ParametersDialog.open(this)) return
58 62
	if (debug == "OFF") debug = 0; else if (debug == "ON") debug = 1; else if (debug == "ALL") debug = 2 else if (debug == "REALLY ALL") debug = 3
59 63

  
60
def CQI = CQPSearchEngine.getCqiClient()
61

  
62 64
if (unit_property_to_set.length() == 0) {
63 65
	println "unit_property_to_set not set: aborting."
64 66
}
......
68 70
def errors = new HashSet()
69 71
for (def corpus : selection) {
70 72
	println "Annotate $corpus..."
71
	MainCorpus mainCorpus = corpus.getMainCorpus()
72 73

  
73
	def word = mainCorpus.getWordProperty()
74
	def analecCorpus = URSCorpora.getCorpus(mainCorpus.getName())
75
	Vue analecView = URSCorpora.getVue(mainCorpus.getName())
74
	def word = corpus.getWordProperty()
75
	def analecCorpus = URSCorpora.getCorpus(corpus)
76
	Vue analecView = URSCorpora.getVue(corpus)
76 77
	Structure structure = analecCorpus.getStructure()
77 78

  
78 79
	AnalecUtils.defineProperty(Unite.class, analecCorpus, unit_ursql, unit_property_to_set)
79 80
	analecView.initVueParDefaut()
80 81

  
81 82
	def selectedUnits = AnalecUtils.selectUnitsInSchema(debug, analecCorpus, corpus, schema_ursql, minimum_schema_size, Integer.MAX_VALUE,
82
			unit_ursql, limit_cql, strict_inclusion, limit_distance);
83
			unit_ursql, limit_distance_in_schema, limit_cql, strict_inclusion, limit_distance);
84
		
83 85
	println " "+selectedUnits.size()+" units to annotate..."
84 86
	def n = 0
85 87
	def nerrors = 0
......
93 95
		}
94 96
	}
95 97
	
96
	mainCorpus.setIsModified(true)
98
	corpus.getMainCorpus().setIsModified(true)
97 99
	allResults[corpus] = selectedUnits
98 100
	println " $n valeurs affectées à $corpus"
99 101
	println " $nerrors erreurs lors de l'annotation de $corpus"
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/edit/CreationAnaphoresMacro.groovy (revision 1973)
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
// STANDARD DECLARATIONS
5
package org.txm.macro.urs.edit
6

  
7
import org.kohsuke.args4j.*
8

  
9
import groovy.transform.Field
10

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

  
15
import visuAnalec.donnees.Structure;
16
import visuAnalec.elements.Relation;
17
import visuAnalec.elements.Schema
18
import visuAnalec.elements.Unite;
19
import visuAnalec.vue.Vue
20

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

  
26
// BEGINNING OF PARAMETERS
27
@Field @Option(name="unit_type",usage="", widget="String", required=true, def="MENTION")
28
		String unit_type
29
@Field @Option(name="schema_type",usage="", widget="String", required=true, def="CHAINE")
30
		String schema_type
31
if (!ParametersDialog.open(this)) return;
32

  
33
int nCreated = 0 // count the number of created RELATION
34

  
35
MainCorpus corpus = corpusViewSelection
36
def analecCorpus = URSCorpora.getCorpus(corpus); // analec corpus has the same name has the TXM corpus
37
Structure structure = analecCorpus.getStructure()
38
if (!structure.getUnites().contains(unit_type)) { // check if the structure contains the unit_type units
39
	println "Error: corpus structure does not contains unit with name=$unit_type"
40
	return
41
}
42
if (!structure.getSchemas().contains(schema_type)) { // check if the structure contains the unit_type units
43
	println "Error: corpus structure does not contains schema with name=$schema_type"
44
	return
45
}
46
if (!structure.getRelations().contains("ANAPHORE")) { // update the structure if needed
47
	println "Creating the 'ANAPHORE' relation in the structure"
48
	structure.ajouterType(Relation.class, "ANAPHORE")
49
	analecCorpus.ajouterProp(Relation.class, "ANAPHORE", "TYPE")
50
	analecCorpus.ajouterVal(Relation.class, "ANAPHORE", "TYPE", "COREFERENTE")
51
	analecCorpus.ajouterVal(Relation.class, "ANAPHORE", "TYPE", "ASSOCIATIVE")
52
}
53
if (analecCorpus.getRelations("ANAPHORE").size() > 0) {
54
	println "Error: This macro can't update existing Relations"
55
	return
56
}
57

  
58
for (Schema schema : analecCorpus.getSchemas(schema_type)) { // parse all CHAINE
59
	def units = []
60
	for (Unite unit : schema.getUnitesSousjacentes()) { // keep only the 'unit_type' units
61
		if (unit.type.equals(unit_type)) units << unit
62
	}
63
	units.sort() { a, b -> a.getDeb() <=> b.getDeb() ?: a.getFin() <=> b.getFin() } // sort them
64
	
65
	for (int i = 0 ; i < units.size() - 1 ; i++) { // build RELATIONS and don't process the last unit
66
		println "creating "+units[i+1]+", "+units[i]
67
		Relation relation = new Relation("ANAPHORE", units[i+1], units[i])
68
		relation.getProps().put("TYPE", "COREFERENTE")
69
		analecCorpus.addRelationLue(relation)  // add the new relation
70
		nCreated++;
71
	}
72
}
73

  
74
println "nCreated=$nCreated"
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/edit/CheckAnnotationStructureValuesMacro.groovy (revision 1973)
13 13
	return;
14 14
}
15 15

  
16
@Field @Option(name="unit_type",usage="", widget="String", required=false, def="Maillon")
16
@Field @Option(name="unit_type",usage="", widget="String", required=false, def="MENTION")
17 17
String unit_type
18 18

  
19 19
@Field @Option(name="unit_property_name", usage="", widget="String", required=false, def="REF")
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/edit/PremierMaillonMacro.groovy (revision 1973)
23 23
}
24 24

  
25 25
// BEGINNING OF PARAMETERS
26
@Field @Option(name="unit_type",usage="", widget="String", required=true, def="Maillon")
26
@Field @Option(name="unit_type",usage="", widget="String", required=true, def="MENTION")
27 27
String unit_type
28 28
@Field @Option(name="reset",usage="", widget="Boolean", required=true, def="true")
29 29
boolean reset
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/edit/ConcordanceToUnitMacro.groovy (revision 1973)
46 46
}
47 47

  
48 48
// check the analec corpus is ready
49
MainCorpus corpus = concordance.getCorpus().getMainCorpus();
49
CQPCorpus corpus = concordance.getCorpus().getMainCorpus();
50 50
String name = corpus.getID()
51
if (!URSCorpora.isAnnotationStructureReady(name)) {
51
if (!URSCorpora.isAnnotationStructureReady(corpus)) {
52 52
	println "Annotation structure is not ready."
53 53
	return
54 54
}
......
57 57
if (!ParametersDialog.open(this)) return;
58 58

  
59 59
// check the corpus structure has the unit_type provided
60
def analecCorpus = URSCorpora.getCorpus(name)
60
def analecCorpus = URSCorpora.getCorpus(corpus)
61 61
if (!analecCorpus.getStructure().getUnites().contains(unit_type)) {
62 62
	//println "The corpus structure does not contains unit with type=$unit_type"
63 63
	//return;
......
93 93
			if (iUnit < units.size()) {
94 94
				unit = units[iUnit++]
95 95
				if (unit.getDeb() == m.getStart() && unit.getFin() == m.getEnd()) { // skip and print the line
96
					println "skiping concordance line '"+line.keywordToString()+"' at "+line.getViewRef().toString()+" ("+unit.getDeb(), ", "+unit.getFin()+")"
96
					println("skiping concordance line '"+line.keywordToString()+"' at "+line.getViewRef().toString()+" ("+unit.getDeb()+ ", "+unit.getFin()+")")
97 97
					do_create = false
98 98
					continue
99 99
				}
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/edit/AjoutDefinitudeMacro.groovy (revision 1973)
15 15
import org.txm.annotation.urs.*
16 16
import org.txm.searchengine.cqp.AbstractCqiClient;
17 17
import org.txm.searchengine.cqp.corpus.*
18

  
18
import org.txm.searchengine.cqp.CQPSearchEngine
19 19
import visuAnalec.Message.StructureEvent;
20 20
import visuAnalec.Message.TypeModifStructure;
21 21
import visuAnalec.donnees.Structure;
......
28 28
}
29 29

  
30 30
// BEGINNING OF PARAMETERS
31
@Field @Option(name="unit_type",usage="", widget="String", required=true, def="Maillon")
31
@Field @Option(name="unit_type",usage="", widget="String", required=true, def="MENTION")
32 32
String unit_type
33
@Field @Option(name="reset",usage="", widget="Boolean", required=true, def="true")
33
@Field @Option(name="reset",usage="", widget="Boolean", required=true, def="false")
34 34
boolean reset
35 35

  
36 36
if (!ParametersDialog.open(this)) return;
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/edit/CheckDuplicatesInSchemasMacro.groovy (revision 1973)
16 16
import org.txm.rcp.Application
17 17
import org.txm.rcp.IImageKeys
18 18
import org.txm.rcp.swt.widget.parameters.*
19
import org.txm.searchengine.cqp.CQPSearchEngine
19 20
import org.txm.searchengine.cqp.corpus.*
20 21
import org.txm.searchengine.cqp.corpus.query.CQLQuery
21 22

  
......
41 42
def CQI = CQPSearchEngine.getCqiClient()
42 43

  
43 44
def corpus = corpusViewSelection
44
mainCorpus = corpus.getMainCorpus()
45 45

  
46
def word = mainCorpus.getWordProperty()
47
def analecCorpus = URSCorpora.getCorpus(mainCorpus.getName())
46
def word = corpus.getWordProperty()
47
def analecCorpus = URSCorpora.getCorpus(corpus)
48 48

  
49 49
if (schema_property_display.length() > 0) {
50 50
	def errors = AnalecUtils.isPropertyDefined(Schema.class, analecCorpus, schema_ursql, schema_property_display).size()
......
56 56

  
57 57
def allUnits = [:]
58 58

  
59
def allSchemas = AnalecUtils.selectSchemasInCorpus(debug, analecCorpus, , schema_ursql, -1, Integer.MAX_VALUE)
59
def allSchemas = AnalecUtils.selectSchemasInCorpus(debug, analecCorpus, corpus , schema_ursql, -1, Integer.MAX_VALUE)
60 60

  
61 61
if (allSchemas.size() == 0) {
62 62
	println "No schema match for '$schema_ursql' selection. Aborting"
tmp/org.txm.analec.rcp/plugin.xml (revision 1973)
346 346
   </extension>
347 347
   <extension
348 348
         point="org.txm.searchengine.core.SearchEngine">
349
      <SearchEngine
350
            class="org.txm.annotation.urs.search.URSSearchEngine">
351
      </SearchEngine>
352 349
   </extension>
353 350

  
354 351
</plugin>

Also available in: Unified diff