Révision 3423
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/ImportWordPropertiesFromTableMacro.groovy (revision 3423) | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import org.txm.rcp.swt.widget.parameters.* |
13 | 13 |
|
14 |
@Field @Option(name="inputDirectory", usage="The XML-TXM folder", widget="Folder", required=true, def="")
|
|
15 |
def inputDirectory = new File(System.getProperty("user.home"), "xml/anapovoas/HELPTXM-02-131124/ite02")
|
|
14 |
@Field @Option(name="tsvFile", usage="The annotation TSV file", widget="FileOpen", required=true, def="")
|
|
15 |
def tsvFile
|
|
16 | 16 |
|
17 |
@Field @Option(name="outputDirectory", usage="The result folder", widget="Folder", required=true, def="") |
|
18 |
def outputDirectory = new File(System.getProperty("user.home"), "xml/anapovoas/HELPTXM-02-131124/ite03") |
|
19 |
|
|
20 |
@Field @Option(name="tsvFile", usage="The annotation TSV file", widget="File", required=true, def="") |
|
21 |
def tsvFile = new File(System.getProperty("user.home"), "xml/anapovoas/HELPTXM-02-131124/TSV-ITE02.csv") |
|
22 |
|
|
23 | 17 |
@Field @Option(name="properties", usage="columns to inject separated by commas", widget="String", required=true, def="p1, p2, ... , pn") |
24 |
def properties = "verificado"
|
|
18 |
def properties |
|
25 | 19 |
|
26 |
@Field @Option(name="debug", usage="Debug de the macro", widget="Boolean", required=true, def="false")
|
|
27 |
def debug = true
|
|
20 |
@Field @Option(name="debug", usage="Debug de the macro", widget="Boolean", required=false, def="false")
|
|
21 |
def debug |
|
28 | 22 |
|
29 | 23 |
if (!ParametersDialog.open(this)) return; |
30 | 24 |
|
31 |
def split = properties.split(",") |
|
32 |
if (split.length == 0) { |
|
33 |
println "ERROR: no property given" |
|
34 |
return false |
|
35 |
} |
|
36 |
properties = [] |
|
37 |
for (def p : split) properties << p.trim() |
|
25 |
println "Importing the $properties properties in the $selection corpus" |
|
26 |
println "selection="+selection |
|
27 |
println "sel class="+selection.getClass() |
|
28 |
println "sel project="+selection.getParent() |
|
29 |
println "sel name="+selection.getName() |
|
38 | 30 |
|
39 |
println "Injecting annotations with the following parameters:" |
|
40 |
println "- inputDirectory: $inputDirectory" |
|
41 |
println "- outputDirectory: $outputDirectory" |
|
42 |
println "- tsvFile: $tsvFile" |
|
43 |
println "- properties: $properties" |
|
31 |
File inputDirectory = new File(selection.getParent().getProjectDirectory(), "txm/"+selection.getName()) |
|
44 | 32 |
|
45 |
outputDirectory.mkdir() |
|
46 |
if (!outputDirectory.exists()) { |
|
47 |
println "ERROR: could not create or read $outputDirectory directory" |
|
48 |
return false |
|
49 |
} |
|
33 |
// insert the section in the TRS files |
|
34 |
gse.runMacro(InjectWordPropTableMacro, ["inputDirectory": inputDirectory |
|
35 |
, "outputDirectory": inputDirectory |
|
36 |
, "tsvFile": tsvFile |
|
37 |
, "properties": properties |
|
38 |
, "debug":debug]) |
|
50 | 39 |
|
51 |
CsvReader records = new CsvReader(tsvFile.getAbsolutePath(), "\t".charAt(0), Charset.forName("UTF-8")) |
|
52 |
records.setTextQualifier((char)0) |
|
53 |
records.readHeaders(); |
|
54 |
|
|
55 |
def header = Arrays.asList(records.getHeaders()) |
|
56 |
if (debug) println "CSV header: $header" |
|
57 |
for (def s : properties) if (!header.contains(s)) { |
|
58 |
println "Missing annotation property : $s" |
|
59 |
return; |
|
60 |
} |
|
61 |
for (def s : ["text_id", "id"]) if (!header.contains(s)) { |
|
62 |
println "Missing annotation property : $s" |
|
63 |
return; |
|
64 |
} |
|
65 |
|
|
66 |
def injections = [:] |
|
67 |
int no = 1; |
|
68 |
while (records.readRecord()) { |
|
69 |
String textid = records.get("text_id") |
|
70 |
if (!injections.containsKey(textid)) injections[textid] = [:] |
|
71 |
|
|
72 |
def props = [:] |
|
73 |
for (def s : properties) props[s] = records.get(s) |
|
74 |
if (records.get("id") == "") { |
|
75 |
print "ERROR in record "+no |
|
76 |
} else { |
|
77 |
injections[textid][records.get("id")] = props |
|
78 |
} |
|
79 |
no++; |
|
80 |
} |
|
81 |
|
|
82 |
println "Injecting..." |
|
83 |
//for (String textid : injections.keySet()) { |
|
84 |
for (File currentXMLFile : inputDirectory.listFiles().sort{ it.name }) { |
|
85 |
if (currentXMLFile.isDirectory()) continue; |
|
86 |
if (currentXMLFile.isHidden()) continue; |
|
87 |
|
|
88 |
String textid = currentXMLFile.getName(); |
|
89 |
int idx = textid.lastIndexOf(".") |
|
90 |
if (idx > 0) textid = textid.substring(0, idx); |
|
91 |
|
|
92 |
if (injections.containsKey(textid)) { |
|
93 |
if (debug) println "Injections of "+injections[textid].size()+" lines." |
|
94 |
|
|
95 |
def builder = new AnnotationInjectionFilter(currentXMLFile, injections[textid], properties, debug) |
|
96 |
println "injecting in $currentXMLFile $properties" |
|
97 |
builder.process(new File(outputDirectory, currentXMLFile.getName())); |
|
98 |
println ""+builder.n+" lines injected." |
|
99 |
} else { |
|
100 |
println "copying file $currentXMLFile" |
|
101 |
FileCopy.copy(currentXMLFile, new File(outputDirectory, currentXMLFile.getName())) |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
println "New XML-TXM files are saved in ${outputDirectory}." |
|
40 |
org.txm.rcp.commands.workspace.UpdateCorpus.update(selection, false) |
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/InjectWordPropTableMacro.groovy (revision 3423) | ||
---|---|---|
1 |
package org.txm.macro.annotation; |
|
2 |
|
|
3 |
import org.txm.utils.* |
|
4 |
import org.txm.utils.io.* |
|
5 |
|
|
6 |
import java.nio.charset.Charset |
|
7 |
|
|
8 |
import org.kohsuke.args4j.* |
|
9 |
|
|
10 |
import groovy.transform.Field |
|
11 |
|
|
12 |
import org.txm.rcp.swt.widget.parameters.* |
|
13 |
|
|
14 |
@Field @Option(name="inputDirectory", usage="The XML-TXM folder", widget="Folder", required=true, def="") |
|
15 |
def inputDirectory |
|
16 |
|
|
17 |
@Field @Option(name="outputDirectory", usage="The result folder", widget="Folder", required=true, def="") |
|
18 |
def outputDirectory |
|
19 |
|
|
20 |
@Field @Option(name="tsvFile", usage="The annotation TSV file", widget="FileOpen", required=true, def="") |
|
21 |
def tsvFile |
|
22 |
|
|
23 |
@Field @Option(name="properties", usage="columns to inject separated by commas", widget="String", required=true, def="p1, p2, ... , pn") |
|
24 |
def properties |
|
25 |
|
|
26 |
@Field @Option(name="debug", usage="Debug de the macro", widget="Boolean", required=false, def="false") |
|
27 |
def debug |
|
28 |
|
|
29 |
if (!ParametersDialog.open(this)) return; |
|
30 |
|
|
31 |
def split = properties.split(",") |
|
32 |
if (split.length == 0) { |
|
33 |
println "ERROR: no property given" |
|
34 |
return false |
|
35 |
} |
|
36 |
properties = [] |
|
37 |
for (def p : split) properties << p.trim() |
|
38 |
|
|
39 |
println "Injecting annotations with the following parameters:" |
|
40 |
println "- inputDirectory: $inputDirectory" |
|
41 |
println "- outputDirectory: $outputDirectory" |
|
42 |
println "- tsvFile: $tsvFile" |
|
43 |
println "- properties: $properties" |
|
44 |
|
|
45 |
outputDirectory.mkdir() |
|
46 |
if (!outputDirectory.exists()) { |
|
47 |
println "ERROR: could not create or read $outputDirectory directory" |
|
48 |
return false |
|
49 |
} |
|
50 |
|
|
51 |
CsvReader records = new CsvReader(tsvFile.getAbsolutePath(), "\t".charAt(0), Charset.forName("UTF-8")) |
|
52 |
records.setTextQualifier((char)0) |
|
53 |
records.readHeaders(); |
|
54 |
|
|
55 |
def header = Arrays.asList(records.getHeaders()) |
|
56 |
if (debug) println "CSV header: $header" |
|
57 |
for (def s : properties) if (!header.contains(s)) { |
|
58 |
println "Missing annotation property : $s" |
|
59 |
return; |
|
60 |
} |
|
61 |
for (def s : ["text_id", "id"]) if (!header.contains(s)) { |
|
62 |
println "Missing annotation property : $s" |
|
63 |
return; |
|
64 |
} |
|
65 |
|
|
66 |
def injections = [:] |
|
67 |
int no = 1; |
|
68 |
while (records.readRecord()) { |
|
69 |
String textid = records.get("text_id") |
|
70 |
if (!injections.containsKey(textid)) injections[textid] = [:] |
|
71 |
|
|
72 |
def props = [:] |
|
73 |
for (def s : properties) props[s] = records.get(s) |
|
74 |
if (records.get("id") == "") { |
|
75 |
print "ERROR in record "+no |
|
76 |
} else { |
|
77 |
injections[textid][records.get("id")] = props |
|
78 |
} |
|
79 |
no++; |
|
80 |
} |
|
81 |
|
|
82 |
println "Injecting..." |
|
83 |
//for (String textid : injections.keySet()) { |
|
84 |
for (File currentXMLFile : inputDirectory.listFiles().sort{ it.name }) { |
|
85 |
if (currentXMLFile.isDirectory()) continue; |
|
86 |
if (currentXMLFile.isHidden()) continue; |
|
87 |
|
|
88 |
String textid = currentXMLFile.getName(); |
|
89 |
int idx = textid.lastIndexOf(".") |
|
90 |
if (idx > 0) textid = textid.substring(0, idx); |
|
91 |
|
|
92 |
if (injections.containsKey(textid)) { |
|
93 |
if (debug) println "Injections of "+injections[textid].size()+" lines." |
|
94 |
File tmp = null |
|
95 |
String filename = currentXMLFile.getName() |
|
96 |
if (outputDirectory.equals(inputDirectory)) { |
|
97 |
|
|
98 |
tmp = File.createTempFile("tmp", currentXMLFile.getName()) |
|
99 |
FileCopy.copy(currentXMLFile, tmp) |
|
100 |
//println "Patching input: $currentXMLFile with $tmp" |
|
101 |
currentXMLFile = tmp; |
|
102 |
} |
|
103 |
def builder = new AnnotationInjectionFilter(currentXMLFile, injections[textid], properties, debug) |
|
104 |
println "injecting in $currentXMLFile $properties" |
|
105 |
builder.process(new File(outputDirectory, filename)); |
|
106 |
|
|
107 |
if (tmp != null) tmp.delete(); // tmp != null if inputdir == outputir |
|
108 |
|
|
109 |
println ""+builder.n+" lines injected." |
|
110 |
} else { |
|
111 |
if (!outputDirectory.equals(inputDirectory)) { |
|
112 |
println "copying file $currentXMLFile" |
|
113 |
FileCopy.copy(currentXMLFile, new File(outputDirectory, currentXMLFile.getName())) |
|
114 |
} |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
println "New XML-TXM files are saved in ${outputDirectory}." |
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/BuildWordPropTableMacro.groovy (revision 3423) | ||
---|---|---|
1 |
// Copyright © 2010-2013 ENS de Lyon. |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// $LastChangedDate: 2012-10-15 17:35:36 +0200 (lun., 15 oct. 2012) $ |
|
24 |
// $LastChangedRevision: 2279 $ |
|
25 |
// $LastChangedBy: mdecorde $ |
|
26 |
// |
|
27 |
package org.txm.macro.annotation |
|
28 |
|
|
29 |
import org.txm.Toolbox |
|
30 |
import org.txm.searchengine.cqp.corpus.* |
|
31 |
import org.txm.searchengine.cqp.corpus.query.* |
|
32 |
import org.txm.concordance.core.functions.Concordance |
|
33 |
import org.txm.concordance.core.functions.Line |
|
34 |
import org.txm.functions.concordances.* |
|
35 |
import org.txm.functions.concordances.comparators.* |
|
36 |
import org.txm.searchengine.cqp.ReferencePattern |
|
37 |
|
|
38 |
import java.util.List |
|
39 |
|
|
40 |
import org.kohsuke.args4j.* |
|
41 |
import groovy.transform.Field |
|
42 |
import org.txm.rcp.swt.widget.parameters.* |
|
43 |
|
|
44 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
|
45 |
println "Error: you must select a corpus or a subcorpus to export properties" |
|
46 |
return false; |
|
47 |
} |
|
48 |
|
|
49 |
CQPCorpus corpus = corpusViewSelection |
|
50 |
|
|
51 |
|
|
52 |
@Field @Option(name="properties", usage="columns to inject separated by commas", widget="String", required=true, def="p1, p2, ... , pn") |
|
53 |
def properties |
|
54 |
|
|
55 |
@Field @Option(name="query", usage="The query to select words to annotate", widget="Query", required=true, def="[]") |
|
56 |
def query |
|
57 |
|
|
58 |
@Field @Option(name="leftcontextsize", usage="The context sizes", widget="Integer", required=true, def="10") |
|
59 |
def leftcontextsize |
|
60 |
|
|
61 |
@Field @Option(name="rightcontextsize", usage="The context sizes", widget="Integer", required=true, def="10") |
|
62 |
def rightcontextsize |
|
63 |
|
|
64 |
@Field @Option(name="references", usage="references to show", widget="String", required=true, def="text_id") |
|
65 |
def references |
|
66 |
|
|
67 |
@Field @Option(name="tsvFile", usage="The result TSV file", widget="FileSave", required=true, def="export.tsv") |
|
68 |
def tsvFile |
|
69 |
|
|
70 |
if (!ParametersDialog.open(this)) return; |
|
71 |
|
|
72 |
def split = properties.split(",") |
|
73 |
if (split.length == 0) { |
|
74 |
println "ERROR: no property given" |
|
75 |
return false |
|
76 |
} |
|
77 |
properties = [] |
|
78 |
for (def p : split) properties << p.trim() |
|
79 |
|
|
80 |
println "Building Annotation Table with the following parameters: " |
|
81 |
println "- corpus: $corpus" |
|
82 |
println "- query: $query" |
|
83 |
println "- annotation properties: $properties" |
|
84 |
println "- references: $properties" |
|
85 |
println "- TSV file: $tsvFile" |
|
86 |
|
|
87 |
tsvFile = tsvFile.getAbsoluteFile() |
|
88 |
if (!tsvFile.getParentFile().canWrite()) { |
|
89 |
println "Error: "+tsvFile.getParentFile()+" is not writable." |
|
90 |
return; |
|
91 |
} |
|
92 |
|
|
93 |
def annots = [] |
|
94 |
for (def p : properties) { |
|
95 |
def prop = corpus.getProperty(p) |
|
96 |
if (prop == null) { |
|
97 |
println "No such property $p in the $corpus corpus" |
|
98 |
return false; |
|
99 |
} |
|
100 |
annots << prop |
|
101 |
} |
|
102 |
def id = corpus.getProperty("id") |
|
103 |
def word = corpus.getProperty("word") |
|
104 |
def text = corpus.getStructuralUnit("text") |
|
105 |
def text_id = text.getProperty("id") |
|
106 |
def refs = references.split(",") |
|
107 |
|
|
108 |
if (annots == null || annots.size() == 0) { |
|
109 |
println "No such property given"//$annots in the $corpus corpus" |
|
110 |
return false; |
|
111 |
} |
|
112 |
|
|
113 |
println "Exporting ..." |
|
114 |
def start = System.currentTimeMillis() |
|
115 |
|
|
116 |
// define the references pattern for each concordance line |
|
117 |
def referencePattern = new ReferencePattern() |
|
118 |
referencePattern.addProperty(text_id) |
|
119 |
referencePattern.addProperty(id) |
|
120 |
for (def annot : annots) referencePattern.addProperty(annot) |
|
121 |
|
|
122 |
def refProperties = [] |
|
123 |
for (def ref : refs) { |
|
124 |
ref = ref.trim() |
|
125 |
try { |
|
126 |
if (ref.contains("_")) { |
|
127 |
def split2 = ref.split("_",2) |
|
128 |
def refp = corpus.getStructuralUnit(split2[0].trim()).getProperty(split2[1].trim()) |
|
129 |
if (ref != "text_id") |
|
130 |
referencePattern.addProperty(refp) |
|
131 |
refProperties << refp |
|
132 |
} else { |
|
133 |
def p = corpus.getProperty(ref) |
|
134 |
if (p != null) referencePattern.addProperty(p) |
|
135 |
} |
|
136 |
} catch(Exception e) { println "Error while parsing references: "+ref+" "+e} |
|
137 |
} |
|
138 |
|
|
139 |
// compute the concordance with contexts of 15 words on each side of the keyword |
|
140 |
//query = new Query(Query.fixQuery(query)) |
|
141 |
def viewprops = [word] |
|
142 |
viewprops.addAll(annots) |
|
143 |
Concordance concordance = new Concordance(corpus) |
|
144 |
concordance.setParameters(query, [word], [word], [word], viewprops, viewprops, viewprops, referencePattern, referencePattern, leftcontextsize, rightcontextsize) |
|
145 |
concordance.compute() |
|
146 |
//println "Conc done "+(System.currentTimeMillis()-start) |
|
147 |
|
|
148 |
def writer = tsvFile.newWriter("UTF-8"); |
|
149 |
|
|
150 |
//println "Writing lines..." |
|
151 |
start = System.currentTimeMillis() |
|
152 |
String annotHeader = "" |
|
153 |
for (def annot : annots) annotHeader += "\t$annot" |
|
154 |
writer.write("N"+"\t"+"Références"+"\t"+"ContexteGauche"+"\t"+"Pivot"+annotHeader+"\t"+"ContexteDroit"+"\t"+"id"+"\t"+"text_id\n") |
|
155 |
|
|
156 |
// define which occurrence properties will be displayed |
|
157 |
concordance.setViewProperties([word]) |
|
158 |
int NLines = concordance.getNLines(); |
|
159 |
int chunk = 1000; |
|
160 |
for (int i = 0 ; i < concordance.getNLines() ; i += chunk) { |
|
161 |
List<Line> lines |
|
162 |
if (i+chunk > NLines) |
|
163 |
lines = concordance.getLines(i, concordance.getNLines()-1) |
|
164 |
else |
|
165 |
lines = concordance.getLines(i, i+chunk-1) // e.g. from 0 to 999 |
|
166 |
|
|
167 |
int n = 1 |
|
168 |
for (Line l : lines) { |
|
169 |
String ntext = l.getViewRef().getValue(text_id) |
|
170 |
String lcontext = l.leftContextToString() |
|
171 |
String pivot = l.keywordToString() |
|
172 |
String rcontext = l.rightContextToString() |
|
173 |
String ids = l.getViewRef().getValue(id) |
|
174 |
String refValue = ""; |
|
175 |
for (def refp : refProperties) refValue += " "+l.getViewRef().getValue(refp) |
|
176 |
|
|
177 |
String poss = ""; |
|
178 |
for (def annot : annots) { |
|
179 |
poss += "\t"+l.getViewRef().getValue(annot) |
|
180 |
} |
|
181 |
|
|
182 |
//println l.getKeywordsViewProperties().get(pos) |
|
183 |
writer.write(""+(l.getKeywordPosition())+"\t"+refValue+"\t"+lcontext+"\t"+pivot+poss+"\t"+rcontext+"\t"+ids+"\t"+ntext+"\n") |
|
184 |
} |
|
185 |
writer.flush() |
|
186 |
} |
|
187 |
println "Saved in "+tsvFile.getAbsolutePath() |
|
188 |
writer.close() |
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/ExportWordPropertiesToTableMacro.groovy (revision 3423) | ||
---|---|---|
50 | 50 |
|
51 | 51 |
|
52 | 52 |
@Field @Option(name="properties", usage="columns to inject separated by commas", widget="String", required=true, def="p1, p2, ... , pn") |
53 |
def properties = "pos"
|
|
53 |
def properties |
|
54 | 54 |
|
55 | 55 |
@Field @Option(name="query", usage="The query to select words to annotate", widget="Query", required=true, def="[]") |
56 | 56 |
def query |
57 | 57 |
|
58 | 58 |
@Field @Option(name="leftcontextsize", usage="The context sizes", widget="Integer", required=true, def="10") |
59 |
def leftcontextsize = 10
|
|
59 |
def leftcontextsize |
|
60 | 60 |
|
61 | 61 |
@Field @Option(name="rightcontextsize", usage="The context sizes", widget="Integer", required=true, def="10") |
62 |
def rightcontextsize = 10
|
|
62 |
def rightcontextsize |
|
63 | 63 |
|
64 | 64 |
@Field @Option(name="references", usage="references to show", widget="String", required=true, def="text_id") |
65 |
def references = "text_id, p_id, s_id"
|
|
65 |
def references |
|
66 | 66 |
|
67 |
@Field @Option(name="tsvFile", usage="The result TSV file", widget="File", required=true, def="export.tsv") |
|
67 |
@Field @Option(name="tsvFile", usage="The result TSV file", widget="FileSave", required=true, def="export.tsv")
|
|
68 | 68 |
def tsvFile |
69 | 69 |
|
70 | 70 |
if (!ParametersDialog.open(this)) return; |
... | ... | |
81 | 81 |
println "- corpus: $corpus" |
82 | 82 |
println "- query: $query" |
83 | 83 |
println "- annotation properties: $properties" |
84 |
println "- references: $properties" |
|
84 | 85 |
println "- TSV file: $tsvFile" |
85 | 86 |
|
86 | 87 |
tsvFile = tsvFile.getAbsoluteFile() |
TXM/trunk/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/URSToolsMenuContribution.java (revision 3423) | ||
---|---|---|
139 | 139 |
public void widgetSelected(SelectionEvent e) { |
140 | 140 |
IWorkbenchWindow acWindow = TXMWindows.getActiveWindow(); |
141 | 141 |
IWorkbenchPart page = acWindow.getActivePage().getActivePart(); |
142 |
ExecuteGroovyMacro.execute(macro.getAbsolutePath(), page, CorporaView.getInstance().getTreeViewer().getSelection(), ""); |
|
142 |
ExecuteGroovyMacro.execute(macro.getAbsolutePath(), page, CorporaView.getInstance().getTreeViewer().getSelection(), "", null);
|
|
143 | 143 |
} |
144 | 144 |
} |
145 | 145 |
|
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosMenuContribution.java (revision 3423) | ||
---|---|---|
145 | 145 |
public void widgetSelected(SelectionEvent e) { |
146 | 146 |
IWorkbenchWindow acWindow = TXMWindows.getActiveWindow(); |
147 | 147 |
IWorkbenchPart page = acWindow.getActivePage().getActivePart(); |
148 |
ExecuteGroovyMacro.execute(macro.getAbsolutePath(), page, CorporaView.getInstance().getTreeViewer().getSelection(), ""); |
|
148 |
ExecuteGroovyMacro.execute(macro.getAbsolutePath(), page, CorporaView.getInstance().getTreeViewer().getSelection(), "", null);
|
|
149 | 149 |
} |
150 | 150 |
} |
151 | 151 |
|
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/p2/plugins/TXMUpdateHandler.java (revision 3423) | ||
---|---|---|
38 | 38 |
import org.eclipse.swt.SWT; |
39 | 39 |
import org.eclipse.swt.widgets.Display; |
40 | 40 |
import org.eclipse.swt.widgets.Shell; |
41 |
import org.eclipse.ui.console.ConsolePlugin; |
|
42 |
import org.eclipse.ui.console.IConsole; |
|
43 |
import org.eclipse.ui.console.IOConsole; |
|
41 | 44 |
import org.eclipse.ui.handlers.HandlerUtil; |
42 | 45 |
import org.osgi.framework.Version; |
43 | 46 |
import org.txm.core.preferences.TBXPreferences; |
... | ... | |
92 | 95 |
try { |
93 | 96 |
Log.info("Looking for TXM updates..."); |
94 | 97 |
|
98 |
// flush console ? |
|
99 |
org.eclipse.ui.console.IOConsole console = (IOConsole) (ConsolePlugin.getDefault().getConsoleManager().getConsoles())[0]; |
|
100 |
console.activate(); |
|
101 |
ConsolePlugin.getDefault().getConsoleManager().refresh(console); |
|
102 |
|
|
95 | 103 |
ProvisioningUI pui = ProvisioningUI.getDefaultUI(); |
96 | 104 |
|
97 | 105 |
String profileId = pui.getProfileId(); |
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/commands/function/WordPropertiestoTable.java (revision 3423) | ||
---|---|---|
1 | 1 |
package org.txm.rcp.commands.function; |
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 |
import java.util.HashMap; |
|
4 | 5 |
|
6 |
import org.apache.commons.lang.StringUtils; |
|
5 | 7 |
import org.eclipse.core.commands.AbstractHandler; |
6 | 8 |
import org.eclipse.core.commands.ExecutionEvent; |
7 | 9 |
import org.eclipse.core.commands.ExecutionException; |
... | ... | |
9 | 11 |
import org.eclipse.ui.IWorkbenchPart; |
10 | 12 |
import org.eclipse.ui.handlers.HandlerUtil; |
11 | 13 |
import org.txm.Toolbox; |
14 |
import org.txm.objects.CorpusBuild; |
|
12 | 15 |
import org.txm.rcp.handlers.scripts.ExecuteGroovyMacro; |
16 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
17 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
18 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery; |
|
19 |
import org.txm.utils.logger.Log; |
|
13 | 20 |
|
14 | 21 |
public class WordPropertiestoTable extends AbstractHandler{ |
15 |
|
|
22 |
|
|
16 | 23 |
@Override |
17 | 24 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
18 | 25 |
IWorkbenchPart part = HandlerUtil.getActivePart(event); |
19 | 26 |
IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event); |
20 | 27 |
|
28 |
Object first = selection.getFirstElement(); |
|
29 |
if (!(first instanceof MainCorpus)) { |
|
30 |
Log.warning("Selection must be a corpus. Aborting"); |
|
31 |
return null; |
|
32 |
} |
|
33 |
|
|
34 |
MainCorpus corpus = (MainCorpus)first; |
|
35 |
|
|
21 | 36 |
File script = new File(Toolbox.getTxmHomePath(), "/scripts/groovy/user/org/txm/macro/annotation/ExportWordPropertiesToTableMacro.groovy"); |
22 |
ExecuteGroovyMacro.execute(script.getAbsolutePath(), part, selection, ""); |
|
37 |
File parametersFile = new File(Toolbox.getTxmHomePath(), "/scripts/groovy/user/org/txm/macro/annotation/ExportWordPropertiesToTableMacro.properties"); |
|
38 |
|
|
39 |
ExecuteGroovyMacro.execute(script.getAbsolutePath(), part, selection, "", null); |
|
23 | 40 |
return null; |
24 | 41 |
} |
25 | 42 |
} |
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/commands/function/WordPropertiesFromTable.java (revision 3423) | ||
---|---|---|
1 | 1 |
package org.txm.rcp.commands.function; |
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 |
import java.util.HashMap; |
|
4 | 5 |
|
6 |
import org.apache.commons.lang.StringUtils; |
|
5 | 7 |
import org.eclipse.core.commands.AbstractHandler; |
6 | 8 |
import org.eclipse.core.commands.ExecutionEvent; |
7 | 9 |
import org.eclipse.core.commands.ExecutionException; |
... | ... | |
10 | 12 |
import org.eclipse.ui.handlers.HandlerUtil; |
11 | 13 |
import org.txm.Toolbox; |
12 | 14 |
import org.txm.rcp.handlers.scripts.ExecuteGroovyMacro; |
15 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
16 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
17 |
import org.txm.utils.logger.Log; |
|
13 | 18 |
|
14 | 19 |
public class WordPropertiesFromTable extends AbstractHandler{ |
15 | 20 |
|
... | ... | |
18 | 23 |
IWorkbenchPart part = HandlerUtil.getActivePart(event); |
19 | 24 |
IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event); |
20 | 25 |
|
21 |
File script = new File(Toolbox.getTxmHomePath(), "/scripts/groovy/user/org/txm/macro/annotation/ImportWordPropertiesFromTableMacro.groovy"); |
|
22 |
ExecuteGroovyMacro.execute(script.getAbsolutePath(), part, selection, ""); |
|
26 |
Object first = selection.getFirstElement(); |
|
27 |
if (!(first instanceof MainCorpus)) { |
|
28 |
Log.warning("Selection must be a corpus. Aborting"); |
|
29 |
return null; |
|
30 |
} |
|
31 |
|
|
32 |
MainCorpus corpus = (MainCorpus)first; |
|
33 |
|
|
34 |
File script = new File(Toolbox.getTxmHomePath(), "/scripts/groovy/user/org/txm/macro/annotation/ImportWordPropertiesFromTableMacro.groovy"); |
|
35 |
File parametersFile = new File(Toolbox.getTxmHomePath(), "/scripts/groovy/user/org/txm/macro/annotation/ImportWordPropertiesFromTableMacro.properties"); |
|
36 |
|
|
37 |
ExecuteGroovyMacro.execute(script.getAbsolutePath(), part, selection, "", null); |
|
23 | 38 |
return null; |
24 | 39 |
} |
25 | 40 |
|
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/views/fileexplorer/MacroExplorer.java (revision 3423) | ||
---|---|---|
271 | 271 |
IWorkbenchPart page = acWindow.getActivePage().getActivePart(); |
272 | 272 |
|
273 | 273 |
if (selectedItem.getName().toLowerCase().endsWith(".groovy")) { |
274 |
ExecuteGroovyMacro.execute(selectedItem.getAbsolutePath(), page, selection, ""); |
|
274 |
ExecuteGroovyMacro.execute(selectedItem.getAbsolutePath(), page, selection, "", null);
|
|
275 | 275 |
} |
276 | 276 |
else { |
277 | 277 |
String ext = FileUtils.getExtension(selectedItem); |
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteLastGroovyScript.java (revision 3423) | ||
---|---|---|
90 | 90 |
return; |
91 | 91 |
} |
92 | 92 |
|
93 |
ExecuteGroovyScript.executeScript(currentRootDir, lastScript.getAbsolutePath(), page, selection, false, ""); |
|
93 |
ExecuteGroovyScript.executeScript(currentRootDir, lastScript.getAbsolutePath(), page, selection, false, "", null);
|
|
94 | 94 |
} |
95 | 95 |
} |
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteGroovyMacro.java (revision 3423) | ||
---|---|---|
28 | 28 |
package org.txm.rcp.handlers.scripts; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.util.HashMap; |
|
31 | 32 |
import java.util.Iterator; |
32 | 33 |
|
33 | 34 |
import org.eclipse.core.commands.AbstractHandler; |
... | ... | |
112 | 113 |
LastOpened.set(ID, new File(result)); |
113 | 114 |
} |
114 | 115 |
|
115 |
return execute(result, page, selection, stringArgs); |
|
116 |
return execute(result, page, selection, stringArgs, null);
|
|
116 | 117 |
} |
117 | 118 |
|
118 |
public static IStatus execute(String scriptpath, IWorkbenchPart page, ISelection selection, String stringArgs) { |
|
119 |
public static IStatus execute(String scriptpath, IWorkbenchPart page, ISelection selection, String stringArgs, HashMap<String, Object> parameters) {
|
|
119 | 120 |
//IPreferencesService service = Platform.getPreferencesService(); |
120 | 121 |
String scriptRootDir = Toolbox.getTxmHomePath() + "/scripts"; //$NON-NLS-1$ |
121 | 122 |
File currentRootDir = new File(scriptRootDir, "groovy/user"); //$NON-NLS-1$ |
122 | 123 |
|
123 | 124 |
if (scriptpath.endsWith(".groovy")) { |
124 |
return ExecuteGroovyScript.executeScript(currentRootDir, scriptpath, page, selection, false, stringArgs); |
|
125 |
return ExecuteGroovyScript.executeScript(currentRootDir, scriptpath, page, selection, false, stringArgs, parameters);
|
|
125 | 126 |
} else { |
126 | 127 |
return ExecuteScript.executeScript(scriptpath, page, selection, stringArgs); |
127 | 128 |
} |
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteGroovyScript.java (revision 3423) | ||
---|---|---|
28 | 28 |
package org.txm.rcp.handlers.scripts; |
29 | 29 |
|
30 | 30 |
import java.io.File; |
31 |
import java.util.HashMap; |
|
31 | 32 |
import java.util.Iterator; |
32 | 33 |
import java.util.List; |
33 | 34 |
|
... | ... | |
163 | 164 |
String scriptRootDir = Toolbox.getTxmHomePath() + "/scripts"; //$NON-NLS-1$ |
164 | 165 |
File currentRootDir = new File(scriptRootDir, "groovy/user"); //$NON-NLS-1$ |
165 | 166 |
|
166 |
return executeScript(currentRootDir, scriptpath, page, selection, modal, stringArgs); |
|
167 |
return executeScript(currentRootDir, scriptpath, page, selection, modal, stringArgs, null);
|
|
167 | 168 |
} |
168 | 169 |
|
169 | 170 |
/** |
... | ... | |
195 | 196 |
* @param page current active page, might be null |
196 | 197 |
* @param sel current selection, might be null |
197 | 198 |
*/ |
198 |
public static IStatus executeScript(final File currentRootDir, String scriptpath, final IWorkbenchPart page, final ISelection sel, final boolean modal, final String stringArgs) { |
|
199 |
public static IStatus executeScript(final File currentRootDir, String scriptpath, final IWorkbenchPart page, final ISelection sel, final boolean modal, final String stringArgs, HashMap<String, Object> parameters) {
|
|
199 | 200 |
// check script |
200 | 201 |
final File scriptfile = new File(scriptpath); |
201 | 202 |
if (!scriptfile.exists()) { |
... | ... | |
259 | 260 |
binding.setProperty("monitor", this); //$NON-NLS-1$ |
260 | 261 |
binding.setProperty("MONITOR", this); //$NON-NLS-1$ |
261 | 262 |
binding.setProperty("stringArgs", stringArgs); //$NON-NLS-1$ |
263 |
if (parameters != null) binding.setProperty("args", parameters); //$NON-NLS-1$ |
|
262 | 264 |
binding.setProperty("gse", gse); |
263 | 265 |
Timer timer = new Timer(); |
264 | 266 |
binding.setProperty("timer", timer); //$NON-NLS-1$ |
TXM/trunk/org.txm.internalview.rcp/src/org/txm/internalview/rcp/editors/InternalViewEditor.java (revision 3423) | ||
---|---|---|
6 | 6 |
import java.util.List; |
7 | 7 |
|
8 | 8 |
import org.eclipse.jface.viewers.ColumnLabelProvider; |
9 |
import org.eclipse.jface.viewers.ISelection; |
|
9 | 10 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
10 | 11 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
12 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
11 | 13 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
12 | 14 |
import org.eclipse.jface.viewers.TableViewer; |
13 | 15 |
import org.eclipse.jface.viewers.TableViewerColumn; |
... | ... | |
16 | 18 |
import org.eclipse.swt.SWT; |
17 | 19 |
import org.eclipse.swt.events.KeyEvent; |
18 | 20 |
import org.eclipse.swt.events.KeyListener; |
21 |
import org.eclipse.swt.events.MouseEvent; |
|
22 |
import org.eclipse.swt.events.MouseListener; |
|
19 | 23 |
import org.eclipse.swt.layout.GridData; |
20 | 24 |
import org.eclipse.swt.layout.GridLayout; |
21 | 25 |
import org.eclipse.swt.widgets.Composite; |
... | ... | |
224 | 228 |
} |
225 | 229 |
}); |
226 | 230 |
|
231 |
table.addMouseListener(new MouseListener() { |
|
232 |
|
|
233 |
@Override |
|
234 |
public void mouseUp(MouseEvent e) { } |
|
235 |
|
|
236 |
@Override |
|
237 |
public void mouseDown(MouseEvent e) { } |
|
238 |
|
|
239 |
@Override |
|
240 |
public void mouseDoubleClick(MouseEvent e) { |
|
241 |
|
|
242 |
// ISelection selection = viewer.getSelection(); |
|
243 |
// if (selection.isEmpty()) return; |
|
244 |
// |
|
245 |
// IStructuredSelection sselection = (IStructuredSelection) selection; |
|
246 |
// Object first = sselection.getFirstElement(); |
|
247 |
// System.out.println("First="+first); |
|
248 |
} |
|
249 |
}); |
|
250 |
|
|
227 | 251 |
// Register the context menu |
228 | 252 |
TXMEditor.initContextMenu(this.viewer.getTable(), this.getSite(), this.viewer); |
229 | 253 |
|
Formats disponibles : Unified diff