Révision 3710
TXM/trunk/bundles/org.txm.statsengine.core/src/org/txm/statsengine/core/StatsEngine.java (revision 3710) | ||
---|---|---|
1 | 1 |
package org.txm.statsengine.core; |
2 | 2 |
|
3 |
import java.util.List; |
|
4 |
|
|
3 | 5 |
import org.txm.core.engines.Engine; |
4 | 6 |
import org.txm.core.results.TXMResult; |
5 | 7 |
|
... | ... | |
20 | 22 |
return ""; |
21 | 23 |
} |
22 | 24 |
|
23 |
public boolean hasAdditionalDetailsForResult(TXMResult result) {
|
|
24 |
return false;
|
|
25 |
public String hasAdditionalDetailsForResult(TXMResult result) {
|
|
26 |
return null;
|
|
25 | 27 |
} |
26 | 28 |
|
27 | 29 |
public String getAdditionalDetailsForResult(TXMResult result) { |
TXM/trunk/bundles/org.txm.chartsengine.core/src/org/txm/chartsengine/core/ChartsEngine.java (revision 3710) | ||
---|---|---|
5 | 5 |
import java.io.IOException; |
6 | 6 |
import java.util.ArrayList; |
7 | 7 |
import java.util.HashMap; |
8 |
import java.util.List; |
|
8 | 9 |
|
9 | 10 |
import org.eclipse.core.runtime.CoreException; |
10 | 11 |
import org.eclipse.core.runtime.IConfigurationElement; |
... | ... | |
681 | 682 |
return this.description; |
682 | 683 |
} |
683 | 684 |
|
684 |
public boolean hasAdditionalDetailsForResult(TXMResult result) {
|
|
685 |
return false;
|
|
685 |
public String hasAdditionalDetailsForResult(TXMResult result) {
|
|
686 |
return null;
|
|
686 | 687 |
} |
687 | 688 |
|
688 | 689 |
public String getAdditionalDetailsForResult(TXMResult result) { |
TXM/trunk/bundles/org.txm.conllu.core/src/org/txm/conllu/core/function/UDSearch.java (revision 3710) | ||
---|---|---|
1 |
package org.txm.conllu.core.function; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.Arrays; |
|
7 |
import java.util.HashMap; |
|
8 |
import java.util.List; |
|
9 |
|
|
10 |
import org.apache.commons.lang.StringUtils; |
|
11 |
import org.txm.conllu.core.preferences.UDPreferences; |
|
12 |
import org.txm.conllu.core.preferences.UDTreePreferences; |
|
13 |
import org.txm.core.results.TXMParameters; |
|
14 |
import org.txm.libs.deptreeviz.UDDepTreeVizPrintTree; |
|
15 |
import org.txm.searchengine.core.Selection; |
|
16 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
|
17 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
18 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
19 |
import org.txm.searchengine.cqp.corpus.QueryResult; |
|
20 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
21 |
import org.txm.searchengine.cqp.corpus.Subcorpus; |
|
22 |
import org.txm.searchengine.cqp.corpus.WordProperty; |
|
23 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery; |
|
24 |
import org.txm.searchengine.cqp.corpus.query.Match; |
|
25 |
import org.txm.treesearch.function.TreeSearch; |
|
26 |
import org.txm.treesearch.function.TreeSearchSelector; |
|
27 |
import org.txm.utils.TXMProgressMonitor; |
|
28 |
import org.txm.utils.logger.Log; |
|
29 |
|
|
30 |
public class UDSearch extends TreeSearch { |
|
31 |
|
|
32 |
protected boolean ready = false; |
|
33 |
|
|
34 |
Subcorpus udSentences; |
|
35 |
|
|
36 |
private QueryResult matches; |
|
37 |
|
|
38 |
public UDSearch(CQPCorpus corpus) { |
|
39 |
this(null, corpus); |
|
40 |
} |
|
41 |
|
|
42 |
public UDSearch(String parentNodePath, CQPCorpus corpus) { |
|
43 |
super(parentNodePath, corpus); |
|
44 |
|
|
45 |
this.corpus = getParent(); |
|
46 |
|
|
47 |
ready = hasUDProperties(corpus, UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX))); |
|
48 |
} |
|
49 |
|
|
50 |
public UDSearch(String parentNodePath) { |
|
51 |
this(parentNodePath, null); |
|
52 |
} |
|
53 |
|
|
54 |
public boolean isComputed() { |
|
55 |
return matches != null; |
|
56 |
} |
|
57 |
|
|
58 |
public boolean isDrawn() { |
|
59 |
return matches != null; |
|
60 |
} |
|
61 |
|
|
62 |
public Selection getSelection() { |
|
63 |
return matches; |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public boolean toSVG(File svgFile, int sent, int sub, List<String> T, List<String> NT) { |
|
68 |
|
|
69 |
if (!isDrawn()) return false; // no result |
|
70 |
try { |
|
71 |
//File file = File.createTempFile("txm", ".svg", new File(Toolbox.getTxmHomePath(), "results")); |
|
72 |
|
|
73 |
//String engine = UDTreePreferences.getInstance().getString(UDTreePreferences.ENGINE); |
|
74 |
|
|
75 |
Match match = this.matches.getMatches().get(sent); |
|
76 |
org.txm.objects.Match sentence = null; |
|
77 |
for (org.txm.objects.Match s : udSentences.getMatches()) { |
|
78 |
if (s.getStart() <= match.getStart() && match.getEnd() <= s.getEnd()) { |
|
79 |
sentence = s; |
|
80 |
break; |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
if (sentence == null) { |
|
85 |
Log.warning("Error: match positions not found in sentences positions"); |
|
86 |
return false; |
|
87 |
} |
|
88 |
|
|
89 |
int[] positions = new int[sentence.size()]; |
|
90 |
for (int i = 0 ; i < sentence.size() ; i++) positions[i] = sentence.getStart()+i; |
|
91 |
|
|
92 |
String prefix = UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX)); |
|
93 |
|
|
94 |
String[] Tvalues = new String[positions.length]; |
|
95 |
|
|
96 |
|
|
97 |
if (T != null && T.size() > 0) { |
|
98 |
for (int i = 0 ; i < Tvalues.length ; i++) { |
|
99 |
Tvalues[i] = ""; |
|
100 |
} |
|
101 |
for (int iT = 0 ; iT < T.size() ; iT++) { |
|
102 |
String t = T.get(iT); |
|
103 |
if (corpus.getProperty(t) != null) { |
|
104 |
String[] tvalues = corpus.getProperty(t).cpos2Str(positions); |
|
105 |
for (int i = 0 ; i < tvalues.length ; i++) { |
|
106 |
if (iT > 0) Tvalues[i] += " / "; |
|
107 |
Tvalues[i] += tvalues[i]; |
|
108 |
} |
|
109 |
} |
|
110 |
} |
|
111 |
} |
|
112 |
|
|
113 |
String[] NTvalues = new String[positions.length]; |
|
114 |
if (NT != null && NT.size() > 0) { |
|
115 |
for (int i = 0 ; i < NTvalues.length ; i++) { |
|
116 |
NTvalues[i] = ""; |
|
117 |
} |
|
118 |
for (int iNT = 0 ; iNT < NT.size() ; iNT++) { |
|
119 |
String nt = NT.get(iNT); |
|
120 |
if (corpus.getProperty(nt) != null) { |
|
121 |
String[] ntvalues = corpus.getProperty(nt).cpos2Str(positions); |
|
122 |
for (int i = 0 ; i < ntvalues.length ; i++) { |
|
123 |
if (iNT > 0) NTvalues[i] += " / "; |
|
124 |
NTvalues[i] += ntvalues[i]; |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
|
|
131 |
// if (NT != null && corpus.getProperty(NT) != null) { |
|
132 |
// NTvalues = corpus.getProperty(NT).cpos2Str(positions); |
|
133 |
// } |
|
134 |
HashMap<String, String[]> values = new HashMap<>(); |
|
135 |
for (String p : ImportCoNLLUAnnotations.UD_PROPERTY_NAMES) { |
|
136 |
values.put(prefix+p, corpus.getProperty(prefix+p).cpos2Str(positions)); |
|
137 |
} |
|
138 |
|
|
139 |
ArrayList<String> conll = new ArrayList<String>(); |
|
140 |
|
|
141 |
for (int p = 0 ; p < positions.length ; p++) { |
|
142 |
StringBuilder buffer = new StringBuilder(); |
|
143 |
for (String prop : ImportCoNLLUAnnotations.UD_PROPERTY_NAMES) { |
|
144 |
if (buffer.length() > 0) buffer.append("\t"); |
|
145 |
buffer.append(values.get(prefix+prop)[p]); |
|
146 |
} |
|
147 |
|
|
148 |
conll.add(buffer.toString()); |
|
149 |
} |
|
150 |
|
|
151 |
if (UDTreePreferences.getInstance().getBoolean(UDTreePreferences.PRINTCONLLUSENTENCES)) { |
|
152 |
Log.info("CoNLL-U:"); |
|
153 |
for (String l : conll) { |
|
154 |
Log.info(l); |
|
155 |
} |
|
156 |
} |
|
157 |
|
|
158 |
if (UDTreePreferences.BRAT.equals(pVisualisation)) { |
|
159 |
return BratPrintTree.print(svgFile, conll, Tvalues, NTvalues) != null; |
|
160 |
} else { // if (engine == null || UDTreePreferences.DEPTREEVIZ.equals(engine)) { |
|
161 |
return UDDepTreeVizPrintTree.print(svgFile, conll, Tvalues, NTvalues) != null; |
|
162 |
} |
|
163 |
} |
|
164 |
catch (Throwable e) { |
|
165 |
Log.warning("Error while drawing SVG: "+e+ " at "+e.getStackTrace()[0]); |
|
166 |
Log.printStackTrace(e); |
|
167 |
return false; |
|
168 |
} |
|
169 |
} |
|
170 |
|
|
171 |
protected String[] getAvailableProperties() throws CqiClientException { |
|
172 |
List<WordProperty> props = corpus.getProperties(); |
|
173 |
String[] sprops = new String[props.size()]; |
|
174 |
|
|
175 |
for (int i = 0 ; i < props.size() ; i++) { |
|
176 |
sprops[i] = props.get(i).getName(); |
|
177 |
} |
|
178 |
|
|
179 |
Arrays.sort(sprops); |
|
180 |
return sprops; |
|
181 |
} |
|
182 |
|
|
183 |
public String[] getAvailableTProperties() { |
|
184 |
|
|
185 |
// String prefix = UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX)); |
|
186 |
// |
|
187 |
// String[] properties = new String[ImportCoNLLUAnnotations.UD_PROPERTY_NAMES.length]; |
|
188 |
// for (int p = 0 ; p < ImportCoNLLUAnnotations.UD_PROPERTY_NAMES.length ; p++) { |
|
189 |
// properties[p] = prefix+ImportCoNLLUAnnotations.UD_PROPERTY_NAMES[p]; |
|
190 |
// } |
|
191 |
try { |
|
192 |
return getAvailableProperties(); |
|
193 |
} |
|
194 |
catch (CqiClientException e) { |
|
195 |
// TODO Auto-generated catch block |
|
196 |
e.printStackTrace(); |
|
197 |
return new String[0]; |
|
198 |
} |
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* UD words stores the T and NT values |
|
203 |
*/ |
|
204 |
public final String[] getAvailableNTProperties() { |
|
205 |
return getAvailableTProperties(); |
|
206 |
} |
|
207 |
|
|
208 |
@Override |
|
209 |
public CQPCorpus getParent() { |
|
210 |
return (CQPCorpus) super.getParent(); |
|
211 |
} |
|
212 |
|
|
213 |
public boolean isReady() { |
|
214 |
return ready; |
|
215 |
} |
|
216 |
|
|
217 |
public int getNSentences() { |
|
218 |
if (matches == null) return 0; |
|
219 |
|
|
220 |
try { |
|
221 |
return matches.getMatches().size(); |
|
222 |
} |
|
223 |
catch (CqiClientException e) { |
|
224 |
// TODO Auto-generated catch block |
|
225 |
e.printStackTrace(); |
|
226 |
return 0; |
|
227 |
}//getNMatch(); |
|
228 |
} |
|
229 |
|
|
230 |
public int getNSubGraph(int matchNo) { |
|
231 |
|
|
232 |
return 1; |
|
233 |
} |
|
234 |
|
|
235 |
public int getSub(int matchNo) { |
|
236 |
|
|
237 |
return 1; |
|
238 |
} |
|
239 |
|
|
240 |
/** |
|
241 |
* @return the query or the generic one |
|
242 |
*/ |
|
243 |
public String getQuery() { |
|
244 |
|
|
245 |
String prefix = UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX)); |
|
246 |
|
|
247 |
if (pQuery == null || pQuery.getQueryString().length() ==0) { |
|
248 |
return "["+prefix+"id=\"1\"]"; |
|
249 |
} else { |
|
250 |
return pQuery.getQueryString(); |
|
251 |
} |
|
252 |
} |
|
253 |
|
|
254 |
@Override |
|
255 |
public String toString() { |
|
256 |
if (pQuery != null) { |
|
257 |
return pQuery.getQueryString().substring(0, Math.min(20, pQuery.getQueryString().length())); |
|
258 |
} |
|
259 |
return "" + corpus; |
|
260 |
} |
|
261 |
|
|
262 |
@Override |
|
263 |
public boolean _toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception { |
|
264 |
return false; |
|
265 |
} |
|
266 |
|
|
267 |
@Override |
|
268 |
public void clean() { |
|
269 |
|
|
270 |
} |
|
271 |
|
|
272 |
/** |
|
273 |
* |
|
274 |
* @return the array of extensions to show in the FileDialog SWT widget |
|
275 |
*/ |
|
276 |
@Override |
|
277 |
public String[] getExportTXTExtensions() { |
|
278 |
return new String[] { "*.xml" }; |
|
279 |
} |
|
280 |
|
|
281 |
@Override |
|
282 |
public boolean canCompute() { |
|
283 |
return corpus != null; // && pQuery != null && pQuery.length() > 0; // if pQuery is empty/null set a default query |
|
284 |
} |
|
285 |
|
|
286 |
@Override |
|
287 |
public boolean setParameters(TXMParameters parameters) { |
|
288 |
if (parameters.getString("query") != null) { |
|
289 |
this.pQuery = new CQLQuery(parameters.getString("query")); |
|
290 |
} |
|
291 |
return true; |
|
292 |
} |
|
293 |
|
|
294 |
@Override |
|
295 |
public boolean saveParameters() throws Exception { |
|
296 |
return true; |
|
297 |
} |
|
298 |
|
|
299 |
@Override |
|
300 |
public boolean loadParameters() throws Exception { |
|
301 |
return super.loadParameters(); |
|
302 |
} |
|
303 |
|
|
304 |
@Override |
|
305 |
protected boolean _compute(TXMProgressMonitor monitor) throws Exception { |
|
306 |
|
|
307 |
String prefix = UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX)); |
|
308 |
|
|
309 |
|
|
310 |
if (pQuery == null || pQuery.getQueryString().length() == 0) { |
|
311 |
pQuery = new CQLQuery("["+prefix+"deprel=\"root\"]"); // [ud-deprel="root"] |
|
312 |
} |
|
313 |
|
|
314 |
udSentences = corpus.getSubcorpusByName(corpus.getName()+"/ud-sentences"); |
|
315 |
if (udSentences != null) udSentences.compute(); |
|
316 |
|
|
317 |
CQLQuery sentencesQuery = new CQLQuery("["+prefix+"id=\"1\"] ["+prefix+"id !=\"1\"]+ [:"+prefix+"id=\"1|__UNDEF__\":]"); |
|
318 |
if (udSentences == null) { |
|
319 |
udSentences = corpus.createSubcorpus(sentencesQuery, "ud-sentences"); |
|
320 |
udSentences.setVisible(false); |
|
321 |
} |
|
322 |
if (!udSentences.getQuery().equals(sentencesQuery)) { |
|
323 |
udSentences = corpus.createSubcorpus(sentencesQuery, "ud-sentences"); |
|
324 |
udSentences.setVisible(false); |
|
325 |
} |
|
326 |
|
|
327 |
matches = udSentences.query((CQLQuery)pQuery, "matches", false); |
|
328 |
|
|
329 |
return matches.getNMatch() > 0; |
|
330 |
} |
|
331 |
|
|
332 |
@Override |
|
333 |
public String getResultType() { |
|
334 |
return "UD search"; |
|
335 |
} |
|
336 |
|
|
337 |
public void setIndexAndSubIndex(int sent, int sub) { |
|
338 |
this.pIndex = sent; |
|
339 |
this.pSubIndex = sub; |
|
340 |
} |
|
341 |
|
|
342 |
@Override |
|
343 |
public boolean hasSubMatchesStrategy() { |
|
344 |
|
|
345 |
return false; |
|
346 |
} |
|
347 |
|
|
348 |
public static boolean hasUDProperties(CQPCorpus corpus) { |
|
349 |
return hasUDProperties(corpus, UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX))); |
|
350 |
} |
|
351 |
|
|
352 |
public static boolean hasUDProperties(CQPCorpus corpus, String prefix) { |
|
353 |
|
|
354 |
for (String prop : ImportCoNLLUAnnotations.UD_PROPERTY_NAMES) { |
|
355 |
try { |
|
356 |
if (corpus.getProperty(prefix+prop) == null) return false; |
|
357 |
} |
|
358 |
catch (CqiClientException e) { |
|
359 |
return false; |
|
360 |
} |
|
361 |
} |
|
362 |
return true; |
|
363 |
} |
|
364 |
|
|
365 |
@Override |
|
366 |
public String getEngine() { |
|
367 |
|
|
368 |
return UDTreeSearchSelector.UD; |
|
369 |
} |
|
370 |
|
|
371 |
@Override |
|
372 |
public TreeSearchSelector getSelector() { |
|
373 |
|
|
374 |
return new UDTreeSearchSelector(); |
|
375 |
} |
|
376 |
|
|
377 |
@Override |
|
378 |
public String[] getTextAndWordIDSOfCurrentSentence() throws Exception { |
|
379 |
|
|
380 |
String[] textAndWord = new String[2]; |
|
381 |
|
|
382 |
WordProperty pid = corpus.getProperty("id"); |
|
383 |
StructuralUnitProperty ptextid = corpus.getStructuralUnitProperty("text_id"); |
|
384 |
|
|
385 |
org.txm.objects.Match match = this.udSentences.getMatches().get(this.pIndex); |
|
386 |
int[] positions = new int[match.size()]; |
|
387 |
for (int i = 0 ; i < match.size() ; i++) { |
|
388 |
positions[i] = match.getStart() + i; |
|
389 |
} |
|
390 |
|
|
391 |
List<String> idvalues = CQPSearchEngine.getEngine().getValuesForProperty(positions, pid); |
|
392 |
|
|
393 |
int[] structid = CQPSearchEngine.getCqiClient().cpos2Struc(ptextid.getQualifiedName(), positions); |
|
394 |
String[] values = CQPSearchEngine.getCqiClient().struc2Str(ptextid.getQualifiedName(), structid); |
|
395 |
|
|
396 |
textAndWord[0] = values[0]; |
|
397 |
textAndWord[1] = StringUtils.join(idvalues, ","); |
|
398 |
|
|
399 |
return textAndWord; |
|
400 |
} |
|
401 |
|
|
402 |
@Override |
|
403 |
public String getIconPath() { |
|
404 |
|
|
405 |
return "platform:/plugin/org.txm.conllu.core/icons/functions/UD.png"; |
|
406 |
} |
|
407 |
|
|
408 |
@Override |
|
409 |
public File createTemporaryFile(File resultDir) { |
|
410 |
|
|
411 |
try { |
|
412 |
String engine = this.pVisualisation;//UDTreePreferences.getInstance().getString(UDTreePreferences.VISUALISATION); |
|
413 |
if (engine.equals(UDTreePreferences.BRAT)) { |
|
414 |
return File.createTempFile("UDTreeSearch", ".html", resultDir); |
|
415 |
} else { |
|
416 |
return File.createTempFile("UDTreeSearch", ".svg", resultDir); |
|
417 |
} |
|
418 |
} |
|
419 |
catch (IOException e) { |
|
420 |
// TODO Auto-generated catch block |
|
421 |
e.printStackTrace(); |
|
422 |
return null; |
|
423 |
} //$NON-NLS-1$ //$NON-NLS-2$ull; |
|
424 |
} |
|
425 |
|
|
426 |
@Override |
|
427 |
public String[] getAvailableVisualisations() { |
|
428 |
|
|
429 |
return new String[] {UDTreePreferences.DEPTREEVIZ, UDTreePreferences.BRAT}; |
|
430 |
} |
|
431 |
} |
TXM/trunk/bundles/org.txm.conllu.core/src/org/txm/conllu/core/function/UDTreeSearch.java (revision 3710) | ||
---|---|---|
1 |
package org.txm.conllu.core.function; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.Arrays; |
|
7 |
import java.util.HashMap; |
|
8 |
import java.util.List; |
|
9 |
|
|
10 |
import org.apache.commons.lang.StringUtils; |
|
11 |
import org.txm.conllu.core.preferences.UDPreferences; |
|
12 |
import org.txm.conllu.core.preferences.UDTreePreferences; |
|
13 |
import org.txm.conllu.core.search.UDSearchEngine; |
|
14 |
import org.txm.core.results.TXMParameters; |
|
15 |
import org.txm.libs.deptreeviz.UDDepTreeVizPrintTree; |
|
16 |
import org.txm.searchengine.core.Selection; |
|
17 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
|
18 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
19 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
20 |
import org.txm.searchengine.cqp.corpus.QueryResult; |
|
21 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
22 |
import org.txm.searchengine.cqp.corpus.Subcorpus; |
|
23 |
import org.txm.searchengine.cqp.corpus.WordProperty; |
|
24 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery; |
|
25 |
import org.txm.searchengine.cqp.corpus.query.Match; |
|
26 |
import org.txm.treesearch.function.TreeSearch; |
|
27 |
import org.txm.treesearch.function.TreeSearchSelector; |
|
28 |
import org.txm.utils.TXMProgressMonitor; |
|
29 |
import org.txm.utils.logger.Log; |
|
30 |
|
|
31 |
public class UDTreeSearch extends TreeSearch { |
|
32 |
|
|
33 |
protected boolean ready = false; |
|
34 |
|
|
35 |
Subcorpus udSentences; |
|
36 |
|
|
37 |
private QueryResult matches; |
|
38 |
|
|
39 |
public UDTreeSearch(CQPCorpus corpus) { |
|
40 |
this(null, corpus); |
|
41 |
} |
|
42 |
|
|
43 |
public UDTreeSearch(String parentNodePath, CQPCorpus corpus) { |
|
44 |
super(parentNodePath, corpus); |
|
45 |
|
|
46 |
this.corpus = getParent(); |
|
47 |
|
|
48 |
ready = hasUDProperties(corpus, UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX))); |
|
49 |
} |
|
50 |
|
|
51 |
public UDTreeSearch(String parentNodePath) { |
|
52 |
this(parentNodePath, null); |
|
53 |
} |
|
54 |
|
|
55 |
public boolean isComputed() { |
|
56 |
return matches != null; |
|
57 |
} |
|
58 |
|
|
59 |
public boolean isDrawn() { |
|
60 |
return matches != null; |
|
61 |
} |
|
62 |
|
|
63 |
public Selection getSelection() { |
|
64 |
return matches; |
|
65 |
} |
|
66 |
|
|
67 |
@Override |
|
68 |
public boolean toSVG(File svgFile, int sent, int sub, List<String> T, List<String> NT) { |
|
69 |
|
|
70 |
if (!isDrawn()) return false; // no result |
|
71 |
try { |
|
72 |
//File file = File.createTempFile("txm", ".svg", new File(Toolbox.getTxmHomePath(), "results")); |
|
73 |
|
|
74 |
//String engine = UDTreePreferences.getInstance().getString(UDTreePreferences.ENGINE); |
|
75 |
|
|
76 |
Match match = this.matches.getMatches().get(sent); |
|
77 |
org.txm.objects.Match sentence = null; |
|
78 |
for (org.txm.objects.Match s : udSentences.getMatches()) { |
|
79 |
if (s.getStart() <= match.getStart() && match.getEnd() <= s.getEnd()) { |
|
80 |
sentence = s; |
|
81 |
break; |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
if (sentence == null) { |
|
86 |
Log.warning("Error: match positions not found in sentences positions"); |
|
87 |
return false; |
|
88 |
} |
|
89 |
|
|
90 |
int[] positions = new int[sentence.size()]; |
|
91 |
for (int i = 0 ; i < sentence.size() ; i++) positions[i] = sentence.getStart()+i; |
|
92 |
|
|
93 |
String prefix = UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX)); |
|
94 |
|
|
95 |
String[] Tvalues = new String[positions.length]; |
|
96 |
|
|
97 |
|
|
98 |
if (T != null && T.size() > 0) { |
|
99 |
for (int i = 0 ; i < Tvalues.length ; i++) { |
|
100 |
Tvalues[i] = ""; |
|
101 |
} |
|
102 |
for (int iT = 0 ; iT < T.size() ; iT++) { |
|
103 |
String t = T.get(iT); |
|
104 |
if (corpus.getProperty(t) != null) { |
|
105 |
String[] tvalues = corpus.getProperty(t).cpos2Str(positions); |
|
106 |
for (int i = 0 ; i < tvalues.length ; i++) { |
|
107 |
if (iT > 0) Tvalues[i] += " / "; |
|
108 |
Tvalues[i] += tvalues[i]; |
|
109 |
} |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
String[] NTvalues = new String[positions.length]; |
|
115 |
if (NT != null && NT.size() > 0) { |
|
116 |
for (int i = 0 ; i < NTvalues.length ; i++) { |
|
117 |
NTvalues[i] = ""; |
|
118 |
} |
|
119 |
for (int iNT = 0 ; iNT < NT.size() ; iNT++) { |
|
120 |
String nt = NT.get(iNT); |
|
121 |
if (corpus.getProperty(nt) != null) { |
|
122 |
String[] ntvalues = corpus.getProperty(nt).cpos2Str(positions); |
|
123 |
for (int i = 0 ; i < ntvalues.length ; i++) { |
|
124 |
if (iNT > 0) NTvalues[i] += " / "; |
|
125 |
NTvalues[i] += ntvalues[i]; |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
// if (NT != null && corpus.getProperty(NT) != null) { |
|
133 |
// NTvalues = corpus.getProperty(NT).cpos2Str(positions); |
|
134 |
// } |
|
135 |
HashMap<String, String[]> values = new HashMap<>(); |
|
136 |
for (String p : ImportCoNLLUAnnotations.UD_PROPERTY_NAMES) { |
|
137 |
values.put(prefix+p, corpus.getProperty(prefix+p).cpos2Str(positions)); |
|
138 |
} |
|
139 |
|
|
140 |
ArrayList<String> conll = new ArrayList<String>(); |
|
141 |
|
|
142 |
for (int p = 0 ; p < positions.length ; p++) { |
|
143 |
StringBuilder buffer = new StringBuilder(); |
|
144 |
for (String prop : ImportCoNLLUAnnotations.UD_PROPERTY_NAMES) { |
|
145 |
if (buffer.length() > 0) buffer.append("\t"); |
|
146 |
buffer.append(values.get(prefix+prop)[p]); |
|
147 |
} |
|
148 |
|
|
149 |
conll.add(buffer.toString()); |
|
150 |
} |
|
151 |
|
|
152 |
if (UDTreePreferences.getInstance().getBoolean(UDTreePreferences.PRINTCONLLUSENTENCES)) { |
|
153 |
Log.info("CoNLL-U:"); |
|
154 |
for (String l : conll) { |
|
155 |
Log.info(l); |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
if (UDTreePreferences.BRAT.equals(pVisualisation)) { |
|
160 |
return BratPrintTree.print(svgFile, conll, Tvalues, NTvalues) != null; |
|
161 |
} else { // if (engine == null || UDTreePreferences.DEPTREEVIZ.equals(engine)) { |
|
162 |
return UDDepTreeVizPrintTree.print(svgFile, conll, Tvalues, NTvalues) != null; |
|
163 |
} |
|
164 |
} |
|
165 |
catch (Throwable e) { |
|
166 |
Log.warning("Error while drawing SVG: "+e+ " at "+e.getStackTrace()[0]); |
|
167 |
Log.printStackTrace(e); |
|
168 |
return false; |
|
169 |
} |
|
170 |
} |
|
171 |
|
|
172 |
protected String[] getAvailableProperties() throws CqiClientException { |
|
173 |
List<WordProperty> props = corpus.getProperties(); |
|
174 |
String[] sprops = new String[props.size()]; |
|
175 |
|
|
176 |
for (int i = 0 ; i < props.size() ; i++) { |
|
177 |
sprops[i] = props.get(i).getName(); |
|
178 |
} |
|
179 |
|
|
180 |
Arrays.sort(sprops); |
|
181 |
return sprops; |
|
182 |
} |
|
183 |
|
|
184 |
public String[] getAvailableTProperties() { |
|
185 |
|
|
186 |
// String prefix = UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX)); |
|
187 |
// |
|
188 |
// String[] properties = new String[ImportCoNLLUAnnotations.UD_PROPERTY_NAMES.length]; |
|
189 |
// for (int p = 0 ; p < ImportCoNLLUAnnotations.UD_PROPERTY_NAMES.length ; p++) { |
|
190 |
// properties[p] = prefix+ImportCoNLLUAnnotations.UD_PROPERTY_NAMES[p]; |
|
191 |
// } |
|
192 |
try { |
|
193 |
return getAvailableProperties(); |
|
194 |
} |
|
195 |
catch (CqiClientException e) { |
|
196 |
// TODO Auto-generated catch block |
|
197 |
e.printStackTrace(); |
|
198 |
return new String[0]; |
|
199 |
} |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* UD words stores the T and NT values |
|
204 |
*/ |
|
205 |
public final String[] getAvailableNTProperties() { |
|
206 |
return getAvailableTProperties(); |
|
207 |
} |
|
208 |
|
|
209 |
@Override |
|
210 |
public CQPCorpus getParent() { |
|
211 |
return (CQPCorpus) super.getParent(); |
|
212 |
} |
|
213 |
|
|
214 |
public boolean isReady() { |
|
215 |
return ready; |
|
216 |
} |
|
217 |
|
|
218 |
public int getNSentences() { |
|
219 |
if (matches == null) return 0; |
|
220 |
|
|
221 |
try { |
|
222 |
return matches.getMatches().size(); |
|
223 |
} |
|
224 |
catch (CqiClientException e) { |
|
225 |
// TODO Auto-generated catch block |
|
226 |
e.printStackTrace(); |
|
227 |
return 0; |
|
228 |
}//getNMatch(); |
|
229 |
} |
|
230 |
|
|
231 |
public int getNSubGraph(int matchNo) { |
|
232 |
|
|
233 |
return 1; |
|
234 |
} |
|
235 |
|
|
236 |
public int getSub(int matchNo) { |
|
237 |
|
|
238 |
return 1; |
|
239 |
} |
|
240 |
|
|
241 |
/** |
|
242 |
* @return the query or the generic one |
|
243 |
*/ |
|
244 |
public String getQuery() { |
|
245 |
|
|
246 |
String prefix = UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX)); |
|
247 |
|
|
248 |
if (pQuery == null || pQuery.getQueryString().length() ==0) { |
|
249 |
return "["+prefix+"id=\"1\"]"; |
|
250 |
} else { |
|
251 |
return pQuery.getQueryString(); |
|
252 |
} |
|
253 |
} |
|
254 |
|
|
255 |
@Override |
|
256 |
public String toString() { |
|
257 |
if (pQuery != null) { |
|
258 |
return pQuery.getQueryString().substring(0, Math.min(20, pQuery.getQueryString().length())); |
|
259 |
} |
|
260 |
return "" + corpus; |
|
261 |
} |
|
262 |
|
|
263 |
@Override |
|
264 |
public boolean _toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception { |
|
265 |
return false; |
|
266 |
} |
|
267 |
|
|
268 |
@Override |
|
269 |
public void clean() { |
|
270 |
|
|
271 |
} |
|
272 |
|
|
273 |
/** |
|
274 |
* |
|
275 |
* @return the array of extensions to show in the FileDialog SWT widget |
|
276 |
*/ |
|
277 |
@Override |
|
278 |
public String[] getExportTXTExtensions() { |
|
279 |
return new String[] { "*.xml" }; |
|
280 |
} |
|
281 |
|
|
282 |
@Override |
|
283 |
public boolean canCompute() { |
|
284 |
return corpus != null; // && pQuery != null && pQuery.length() > 0; // if pQuery is empty/null set a default query |
|
285 |
} |
|
286 |
|
|
287 |
@Override |
|
288 |
public boolean setParameters(TXMParameters parameters) { |
|
289 |
if (parameters.getString("query") != null) { |
|
290 |
this.pQuery = new CQLQuery(parameters.getString("query")); |
|
291 |
} |
|
292 |
return true; |
|
293 |
} |
|
294 |
|
|
295 |
@Override |
|
296 |
public boolean saveParameters() throws Exception { |
|
297 |
return true; |
|
298 |
} |
|
299 |
|
|
300 |
@Override |
|
301 |
public boolean loadParameters() throws Exception { |
|
302 |
return super.loadParameters(); |
|
303 |
} |
|
304 |
|
|
305 |
@Override |
|
306 |
protected boolean _compute(TXMProgressMonitor monitor) throws Exception { |
|
307 |
|
|
308 |
String prefix = UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX)); |
|
309 |
|
|
310 |
|
|
311 |
if (pQuery == null || pQuery.getQueryString().length() == 0) { |
|
312 |
pQuery = new CQLQuery("["+prefix+"deprel=\"root\"]"); // [ud-deprel="root"] |
|
313 |
} |
|
314 |
|
|
315 |
udSentences = UDSearchEngine.getSentenceSubcorpus(corpus, prefix); |
|
316 |
|
|
317 |
matches = udSentences.query((CQLQuery)pQuery, "matches", false); |
|
318 |
|
|
319 |
return matches.getNMatch() > 0; |
|
320 |
} |
|
321 |
|
|
322 |
@Override |
|
323 |
public String getResultType() { |
|
324 |
return "UD search"; |
|
325 |
} |
|
326 |
|
|
327 |
public void setIndexAndSubIndex(int sent, int sub) { |
|
328 |
this.pIndex = sent; |
|
329 |
this.pSubIndex = sub; |
|
330 |
} |
|
331 |
|
|
332 |
@Override |
|
333 |
public boolean hasSubMatchesStrategy() { |
|
334 |
|
|
335 |
return false; |
|
336 |
} |
|
337 |
|
|
338 |
public static boolean hasUDProperties(CQPCorpus corpus) { |
|
339 |
return hasUDProperties(corpus, UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX))); |
|
340 |
} |
|
341 |
|
|
342 |
public static boolean hasUDProperties(CQPCorpus corpus, String prefix) { |
|
343 |
|
|
344 |
for (String prop : ImportCoNLLUAnnotations.UD_PROPERTY_NAMES) { |
|
345 |
try { |
|
346 |
if (corpus.getProperty(prefix+prop) == null) return false; |
|
347 |
} |
|
348 |
catch (CqiClientException e) { |
|
349 |
return false; |
|
350 |
} |
|
351 |
} |
|
352 |
return true; |
|
353 |
} |
|
354 |
|
|
355 |
@Override |
|
356 |
public String getEngine() { |
|
357 |
|
|
358 |
return UDTreeSearchSelector.UD; |
|
359 |
} |
|
360 |
|
|
361 |
@Override |
|
362 |
public TreeSearchSelector getSelector() { |
|
363 |
|
|
364 |
return new UDTreeSearchSelector(); |
|
365 |
} |
|
366 |
|
|
367 |
@Override |
|
368 |
public String[] getTextAndWordIDSOfCurrentSentence() throws Exception { |
|
369 |
|
|
370 |
String[] textAndWord = new String[2]; |
|
371 |
|
|
372 |
WordProperty pid = corpus.getProperty("id"); |
|
373 |
StructuralUnitProperty ptextid = corpus.getStructuralUnitProperty("text_id"); |
|
374 |
|
|
375 |
org.txm.objects.Match match = this.udSentences.getMatches().get(this.pIndex); |
|
376 |
int[] positions = new int[match.size()]; |
|
377 |
for (int i = 0 ; i < match.size() ; i++) { |
|
378 |
positions[i] = match.getStart() + i; |
|
379 |
} |
|
380 |
|
|
381 |
List<String> idvalues = CQPSearchEngine.getEngine().getValuesForProperty(positions, pid); |
|
382 |
|
|
383 |
int[] structid = CQPSearchEngine.getCqiClient().cpos2Struc(ptextid.getQualifiedName(), positions); |
|
384 |
String[] values = CQPSearchEngine.getCqiClient().struc2Str(ptextid.getQualifiedName(), structid); |
|
385 |
|
|
386 |
textAndWord[0] = values[0]; |
|
387 |
textAndWord[1] = StringUtils.join(idvalues, ","); |
|
388 |
|
|
389 |
return textAndWord; |
|
390 |
} |
|
391 |
|
|
392 |
@Override |
|
393 |
public String getIconPath() { |
|
394 |
|
|
395 |
return "platform:/plugin/org.txm.conllu.core/icons/functions/UD.png"; |
|
396 |
} |
|
397 |
|
|
398 |
@Override |
|
399 |
public File createTemporaryFile(File resultDir) { |
|
400 |
|
|
401 |
try { |
|
402 |
String engine = this.pVisualisation;//UDTreePreferences.getInstance().getString(UDTreePreferences.VISUALISATION); |
|
403 |
if (engine.equals(UDTreePreferences.BRAT)) { |
|
404 |
return File.createTempFile("UDTreeSearch", ".html", resultDir); |
|
405 |
} else { |
|
406 |
return File.createTempFile("UDTreeSearch", ".svg", resultDir); |
|
407 |
} |
|
408 |
} |
|
409 |
catch (IOException e) { |
|
410 |
// TODO Auto-generated catch block |
|
411 |
e.printStackTrace(); |
|
412 |
return null; |
|
413 |
} //$NON-NLS-1$ //$NON-NLS-2$ull; |
|
414 |
} |
|
415 |
|
|
416 |
@Override |
|
417 |
public String[] getAvailableVisualisations() { |
|
418 |
|
|
419 |
return new String[] {UDTreePreferences.DEPTREEVIZ, UDTreePreferences.BRAT}; |
|
420 |
} |
|
421 |
} |
|
0 | 422 |
TXM/trunk/bundles/org.txm.conllu.core/src/org/txm/conllu/core/function/UDTreeSearchSelector.java (revision 3710) | ||
---|---|---|
20 | 20 |
@Override |
21 | 21 |
public boolean canComputeWith(CQPCorpus corpus) { |
22 | 22 |
|
23 |
return UDSearch.hasUDProperties(corpus); |
|
23 |
return UDTreeSearch.hasUDProperties(corpus);
|
|
24 | 24 |
} |
25 | 25 |
|
26 | 26 |
@Override |
27 | 27 |
public TreeSearch getTreeSearch(CQPCorpus corpus) { |
28 | 28 |
|
29 |
return new UDSearch(corpus); |
|
29 |
return new UDTreeSearch(corpus);
|
|
30 | 30 |
} |
31 | 31 |
|
32 | 32 |
@Override |
33 | 33 |
public TreeSearch getTreeSearch(String resultnodepath, CQPCorpus corpus) { |
34 | 34 |
|
35 |
return new UDSearch(resultnodepath, corpus); |
|
35 |
return new UDTreeSearch(resultnodepath, corpus);
|
|
36 | 36 |
} |
37 | 37 |
|
38 | 38 |
@Override |
TXM/trunk/bundles/org.txm.conllu.core/src/org/txm/conllu/core/search/UDQuery.java (revision 3710) | ||
---|---|---|
1 |
package org.txm.conllu.core.search; |
|
2 |
|
|
3 |
import org.txm.searchengine.core.SearchEngine; |
|
4 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery; |
|
5 |
|
|
6 |
public class UDQuery extends CQLQuery { |
|
7 |
|
|
8 |
public UDQuery() { |
|
9 |
|
|
10 |
} |
|
11 |
|
|
12 |
public UDQuery(String query) { |
|
13 |
super(query); |
|
14 |
} |
|
15 |
|
|
16 |
@Override |
|
17 |
public SearchEngine getSearchEngine() { |
|
18 |
return UDSearchEngine.getEngine(); |
|
19 |
} |
|
20 |
} |
|
0 | 21 |
TXM/trunk/bundles/org.txm.conllu.core/src/org/txm/conllu/core/search/UDSearchEngine.java (revision 3710) | ||
---|---|---|
1 |
package org.txm.conllu.core.search; |
|
2 |
|
|
3 |
import java.util.Arrays; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
7 |
import org.txm.Toolbox; |
|
8 |
import org.txm.conllu.core.function.UDTreeSearch; |
|
9 |
import org.txm.conllu.core.function.UDTreeSearchSelector; |
|
10 |
import org.txm.conllu.core.preferences.UDPreferences; |
|
11 |
import org.txm.core.engines.EngineType; |
|
12 |
import org.txm.core.preferences.TXMPreferences; |
|
13 |
import org.txm.core.results.TXMResult; |
|
14 |
import org.txm.objects.CorpusBuild; |
|
15 |
import org.txm.objects.Match; |
|
16 |
import org.txm.searchengine.core.EmptySelection; |
|
17 |
import org.txm.searchengine.core.IQuery; |
|
18 |
import org.txm.searchengine.core.Query; |
|
19 |
import org.txm.searchengine.core.SearchEngine; |
|
20 |
import org.txm.searchengine.core.SearchEngineProperty; |
|
21 |
import org.txm.searchengine.core.Selection; |
|
22 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
|
23 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
24 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
25 |
import org.txm.searchengine.cqp.corpus.Subcorpus; |
|
26 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery; |
|
27 |
|
|
28 |
/** |
|
29 |
* Encasulate CQP Search engine to execute queries on "ud-s" subcorpus |
|
30 |
* @author mdecorde |
|
31 |
* |
|
32 |
*/ |
|
33 |
public class UDSearchEngine extends SearchEngine { |
|
34 |
|
|
35 |
public static final String NAME = "UD"; |
|
36 |
|
|
37 |
CQPSearchEngine CQI; |
|
38 |
|
|
39 |
private CQPSearchEngine getCQI() { |
|
40 |
|
|
41 |
if (CQI == null) { |
|
42 |
CQI = CQPSearchEngine.getEngine(); |
|
43 |
} |
|
44 |
return CQI; |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public boolean isRunning() { |
|
49 |
|
|
50 |
return getCQI().isRunning(); |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public boolean initialize() throws Exception { |
|
55 |
|
|
56 |
return true; |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public boolean start(IProgressMonitor monitor) throws Exception { |
|
61 |
return true; |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public boolean stop() throws Exception { |
|
66 |
return true; |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
public void notify(TXMResult r, String state) { |
|
71 |
|
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public String getName() { |
|
76 |
return "UD"; |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
public Selection query(CorpusBuild corpus, IQuery query, String name, boolean saveQuery) throws Exception { |
|
81 |
|
|
82 |
if (corpus instanceof CQPCorpus) { |
|
83 |
CQPCorpus cqpCorpus = (CQPCorpus)corpus; |
|
84 |
String prefix = UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX)); |
|
85 |
Subcorpus udsentences = getSentenceSubcorpus(cqpCorpus, prefix); |
|
86 |
|
|
87 |
return getCQI().query(udsentences, query, name, saveQuery); |
|
88 |
} |
|
89 |
return new EmptySelection(query); |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public Query newQuery() { |
|
94 |
|
|
95 |
return new UDQuery(); |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public boolean hasIndexes(CorpusBuild corpus) { |
|
100 |
return getCQI().hasIndexes(corpus); |
|
101 |
} |
|
102 |
|
|
103 |
@Override |
|
104 |
public String getValueForProperty(Match match, SearchEngineProperty property) { |
|
105 |
|
|
106 |
return getCQI().getValueForProperty(match, property); |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
public List<String> getValuesForProperty(Match match, SearchEngineProperty property) { |
|
111 |
|
|
112 |
return getCQI().getValuesForProperty(match, property); |
|
113 |
} |
|
114 |
|
|
115 |
public static SearchEngine getEngine() { |
|
116 |
|
|
117 |
return (UDSearchEngine) Toolbox.getEngineManager(EngineType.SEARCH).getEngine(UDSearchEngine.NAME); |
|
118 |
} |
|
119 |
|
|
120 |
public static Subcorpus getSentenceSubcorpus(CQPCorpus corpus, String prefix) throws CqiClientException, InterruptedException { |
|
121 |
|
|
122 |
Subcorpus udSentences = corpus.getSubcorpusByName(corpus.getName()+TXMPreferences.PARENT_NAME_SEPARATOR+"ud-s"); |
|
123 |
if (udSentences != null) udSentences.compute(); |
|
124 |
|
|
125 |
CQLQuery sentencesQuery = new CQLQuery("["+prefix+"id=\"1\"] ["+prefix+"id !=\"1\"]+ [:"+prefix+"id=\"1|__UNDEF__\":]"); |
|
126 |
if (udSentences == null) { // no ud-s subcorpus, create it |
|
127 |
udSentences = corpus.createSubcorpus(sentencesQuery, "ud-s"); |
|
128 |
udSentences.setVisible(false); |
|
129 |
} |
|
130 |
if (!udSentences.getQuery().equals(sentencesQuery)) { // the subcorpus exists but its query differs |
|
131 |
udSentences = corpus.createSubcorpus(sentencesQuery, "ud-s"); |
|
132 |
udSentences.setVisible(false); |
|
133 |
} |
|
134 |
|
|
135 |
return udSentences; |
|
136 |
} |
|
137 |
|
|
138 |
public String hasAdditionalDetailsForResult(TXMResult result) { |
|
139 |
if (result instanceof CQPCorpus) { |
|
140 |
CQPCorpus corpus = (CQPCorpus)result; |
|
141 |
return UDTreeSearch.hasUDProperties(corpus)?"Syntax":null; |
|
142 |
} |
|
143 |
return null; |
|
144 |
} |
|
145 |
|
|
146 |
public String getAdditionalDetailsForResult(TXMResult result) { |
|
147 |
if (result instanceof CQPCorpus) { |
|
148 |
CQPCorpus corpus = (CQPCorpus)result; |
|
149 |
if (UDTreeSearch.hasUDProperties(corpus)) { |
|
150 |
StringBuilder buffer = new StringBuilder(); |
|
151 |
|
|
152 |
buffer.append("<h3>CoNLLU</h3>\n"); |
|
153 |
|
|
154 |
String prefix = UDPreferences.getInstance().getProjectPreferenceValue(corpus.getProject(), UDPreferences.UDPREFIX, UDPreferences.getInstance().getString(UDPreferences.UDPREFIX)); |
|
155 |
buffer.append("<p>UD prefix: '"+prefix+"'</p>\n"); |
|
156 |
|
|
157 |
try { |
|
158 |
Subcorpus udSentences = getSentenceSubcorpus(corpus, prefix); |
|
159 |
buffer.append("<p>Sentences: "+udSentences.getNMatch()+"</p>\n"); |
|
160 |
} catch (Exception e) { |
|
161 |
// TODO Auto-generated catch block |
|
162 |
e.printStackTrace(); |
|
163 |
} |
|
164 |
|
|
165 |
return buffer.toString(); |
|
166 |
} |
|
167 |
} |
|
168 |
return null; |
|
169 |
} |
|
170 |
} |
|
0 | 171 |
TXM/trunk/bundles/org.txm.conllu.core/plugin.xml (revision 3710) | ||
---|---|---|
24 | 24 |
class="org.txm.conllu.core.preferences.UDTreePreferences"> |
25 | 25 |
</initializer> |
26 | 26 |
</extension> |
27 |
<extension |
|
28 |
point="org.txm.searchengine.core.SearchEngine"> |
|
29 |
<SearchEngine |
|
30 |
class="org.txm.conllu.core.search.UDSearchEngine"> |
|
31 |
</SearchEngine> |
|
32 |
</extension> |
|
27 | 33 |
|
28 | 34 |
</plugin> |
TXM/trunk/bundles/org.txm.core/src/java/org/txm/core/preferences/TXMPreferences.java (revision 3710) | ||
---|---|---|
93 | 93 |
public final static String USER_NAME = "user_name"; //$NON-NLS-1$ |
94 | 94 |
|
95 | 95 |
public final static String LAZY_NAME = "lazy_name"; //$NON-NLS-1$ |
96 |
|
|
96 | 97 |
public final static String VISIBLE = "visible"; //$NON-NLS-1$ |
97 | 98 |
|
98 | 99 |
public static final String LOCK = "locked_result"; //$NON-NLS-1$ |
... | ... | |
261 | 262 |
@Override |
262 | 263 |
// FIXME: SJ: define an abstract method as _initializeDefaultPreferences() called here and that must be implemented by subclasses |
263 | 264 |
public void initializeDefaultPreferences() { |
265 |
|
|
264 | 266 |
Preferences preferences = this.getDefaultPreferencesNode(); |
265 | 267 |
preferences.putBoolean(TBXPreferences.VISIBLE, true); |
266 | 268 |
preferences.putBoolean(TBXPreferences.LOCK, false); |
TXM/trunk/bundles/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 3710) | ||
---|---|---|
262 | 262 |
this.commandPreferencesNodePath = FrameworkUtil.getBundle(getClass()).getSymbolicName(); |
263 | 263 |
Log.finest("TXMResult.TXMResult(): command preferences node path: " + this.commandPreferencesNodePath + "."); //$NON-NLS-1$ //$NON-NLS-2$ |
264 | 264 |
|
265 |
this.visible = true; |
|
265 |
//this.visible = true;
|
|
266 | 266 |
this.dirty = true; |
267 | 267 |
|
268 | 268 |
// set result as persistent if AUTO_PERSISTENCE_ENABLED preference is activated |
TXM/trunk/bundles/org.txm.core/src/java/org/txm/core/engines/ImportEngine.java (revision 3710) | ||
---|---|---|
1 | 1 |
package org.txm.core.engines; |
2 | 2 |
|
3 |
import java.util.List; |
|
4 |
|
|
3 | 5 |
import org.eclipse.core.runtime.IProgressMonitor; |
4 | 6 |
import org.eclipse.core.runtime.IStatus; |
5 | 7 |
import org.txm.core.results.TXMResult; |
... | ... | |
31 | 33 |
return this.getClass() + " " + this.toString(); |
32 | 34 |
} |
33 | 35 |
|
34 |
public boolean hasAdditionalDetailsForResult(TXMResult result) {
|
|
35 |
return false;
|
|
36 |
public String hasAdditionalDetailsForResult(TXMResult result) {
|
|
37 |
return null;
|
|
36 | 38 |
} |
37 | 39 |
|
38 | 40 |
public String getAdditionalDetailsForResult(TXMResult result) { |
TXM/trunk/bundles/org.txm.core/src/java/org/txm/core/engines/Engine.java (revision 3710) | ||
---|---|---|
1 | 1 |
package org.txm.core.engines; |
2 | 2 |
|
3 |
import java.util.List; |
|
4 |
|
|
3 | 5 |
import org.eclipse.core.runtime.IProgressMonitor; |
4 | 6 |
import org.txm.core.results.TXMResult; |
5 | 7 |
|
... | ... | |
61 | 63 |
*/ |
62 | 64 |
public String getDetails(); |
63 | 65 |
|
64 |
public boolean hasAdditionalDetailsForResult(TXMResult result);
|
|
66 |
public String hasAdditionalDetailsForResult(TXMResult result);
|
|
65 | 67 |
|
66 | 68 |
public String getAdditionalDetailsForResult(TXMResult result); |
67 | 69 |
} |
TXM/trunk/bundles/org.txm.core/src/java/org/txm/core/engines/ScriptEngine.java (revision 3710) | ||
---|---|---|
72 | 72 |
return executeScript(perlScript, null, args); |
73 | 73 |
} |
74 | 74 |
|
75 |
public boolean hasAdditionalDetailsForResult(TXMResult result) {
|
|
76 |
return false;
|
|
75 |
public String hasAdditionalDetailsForResult(TXMResult result) {
|
|
76 |
return null;
|
|
77 | 77 |
} |
78 | 78 |
|
79 | 79 |
public String getAdditionalDetailsForResult(TXMResult result) { |
TXM/trunk/bundles/org.txm.core/src/java/org/txm/core/engines/ScriptedImportEngine.java (revision 3710) | ||
---|---|---|
1 | 1 |
package org.txm.core.engines; |
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 |
import java.util.List; |
|
4 | 5 |
|
5 | 6 |
import org.eclipse.core.runtime.IProgressMonitor; |
6 | 7 |
import org.eclipse.core.runtime.IStatus; |
... | ... | |
57 | 58 |
return _build(project, monitor); |
58 | 59 |
} |
59 | 60 |
|
60 |
public boolean hasAdditionalDetailsForResult(TXMResult result) {
|
|
61 |
return false;
|
|
61 |
public String hasAdditionalDetailsForResult(TXMResult result) {
|
|
62 |
return null;
|
|
62 | 63 |
} |
63 | 64 |
|
64 | 65 |
public String getAdditionalDetailsForResult(TXMResult result) { |
TXM/trunk/bundles/org.txm.properties.core/src/org/txm/properties/core/functions/PartitionPropertiesComputer.java (revision 3710) | ||
---|---|---|
1 | 1 |
package org.txm.properties.core.functions; |
2 | 2 |
|
3 |
import java.text.NumberFormat; |
|
4 |
import java.util.ArrayList; |
|
5 | 3 |
import java.util.Arrays; |
6 |
import java.util.Collections; |
|
7 |
import java.util.Comparator; |
|
8 |
import java.util.HashMap; |
|
9 | 4 |
import java.util.LinkedHashMap; |
10 | 5 |
import java.util.LinkedHashSet; |
11 | 6 |
import java.util.List; |
12 |
import java.util.Locale; |
|
13 | 7 |
|
14 |
import org.apache.commons.lang.StringUtils; |
|
15 |
import org.eclipse.osgi.util.NLS; |
|
16 |
import org.txm.core.messages.TXMCoreMessages; |
|
17 |
import org.txm.objects.Project; |
|
18 |
import org.txm.properties.core.messages.PropertiesCoreMessages; |
|
19 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
|
20 | 8 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
21 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
|
22 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
23 | 9 |
import org.txm.searchengine.cqp.corpus.Part; |
24 | 10 |
import org.txm.searchengine.cqp.corpus.Partition; |
25 |
import org.txm.searchengine.cqp.corpus.Property; |
|
26 |
import org.txm.searchengine.cqp.corpus.QueryResult; |
|
27 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
|
28 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
29 |
import org.txm.searchengine.cqp.corpus.WordProperty; |
|
30 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery; |
|
31 | 11 |
import org.txm.utils.TXMProgressMonitor; |
32 |
import org.txm.utils.logger.Log; |
|
33 | 12 |
|
34 | 13 |
public class PartitionPropertiesComputer extends PropertiesComputer<Partition> { |
35 | 14 |
|
... | ... | |
38 | 17 |
} |
39 | 18 |
|
40 | 19 |
@Override |
41 |
public List<String> getComputableInformations() {
|
|
42 |
return Arrays.asList("all");
|
|
20 |
public LinkedHashSet<String> getComputableInformations() {
|
|
21 |
return new LinkedHashSet(Arrays.asList("all"));
|
|
43 | 22 |
} |
44 | 23 |
|
45 | 24 |
@Override |
46 |
public LinkedHashMap<String, String> getInformation(String name) {
|
|
25 |
public String getInformation(String name) {
|
|
47 | 26 |
LinkedHashMap<String, String> data = new LinkedHashMap<>(); |
48 | 27 |
data.put("all", dump()); |
49 |
return data; |
|
28 |
return data.get(name);
|
|
50 | 29 |
} |
51 | 30 |
|
52 | 31 |
@Override |
TXM/trunk/bundles/org.txm.properties.core/src/org/txm/properties/core/functions/CorpusPropertiesComputer.java (revision 3710) | ||
---|---|---|
35 | 35 |
import org.txm.utils.logger.Log; |
36 | 36 |
|
37 | 37 |
public class CorpusPropertiesComputer extends PropertiesComputer<CQPCorpus> { |
38 |
|
|
39 |
ArrayList<String> computableInformations = new ArrayList<String>(Arrays.asList("all")); |
|
40 |
|
|
38 |
|
|
39 |
LinkedHashSet<String> computableInformations = new LinkedHashSet<String>(Arrays.asList("Summary Statistics", "Lexical Units properties", "Structural Units properties")); |
|
40 |
//new ArrayList<String>(Arrays.asList("Statistiques Générales", "Propriétés des unités lexicales", "Propriétés des structures")); |
|
41 |
// Summary Statistics, Lexical Units properties, Structural Units properties |
|
42 |
|
|
43 |
LinkedHashMap<String, String> data = new LinkedHashMap<>(); |
|
44 |
|
|
41 | 45 |
public CorpusPropertiesComputer(Properties props, CQPCorpus result) { |
42 | 46 |
super(props, result); |
43 | 47 |
} |
44 |
|
|
48 |
|
|
45 | 49 |
@Override |
46 |
public List<String> getComputableInformations() {
|
|
50 |
public LinkedHashSet<String> getComputableInformations() {
|
|
47 | 51 |
return computableInformations; |
48 | 52 |
} |
49 |
|
|
53 |
|
|
50 | 54 |
@Override |
51 |
public LinkedHashMap<String, String> getInformation(String name) { |
|
52 |
LinkedHashMap<String, String> data = new LinkedHashMap<>(); |
|
53 |
data.put("all", dump(props.pMaxPropertiesToDisplay)); |
|
54 |
for (EngineType set : Toolbox.getEngineManagers().keySet()) { |
|
55 |
EnginesManager<?> se = Toolbox.getEngineManagers().get(set); |
|
56 |
for (String ename : se.getEngines().keySet()) { |
|
57 |
Engine engine = se.get(ename); |
|
58 |
if (engine.hasAdditionalDetailsForResult(result)) { |
|
59 |
data.put(engine.getName(), dump(props.pMaxPropertiesToDisplay)); |
|
60 |
} |
|
61 |
} |
|
55 |
public String getInformation(String name) { |
|
56 |
|
|
57 |
if ("Summary Statistics".equals(name)) { |
|
58 |
return dumpGeneralStats(); |
|
59 |
} else if ("Lexical Units properties".equals(name)) { |
|
60 |
return dumpLexicalStats(); |
|
61 |
} else if ("Structural Units properties".equals(name)) { |
|
62 |
return dumpStrutureStats(); |
|
63 |
} else { |
|
64 |
return data.get(name); |
|
62 | 65 |
} |
63 |
return data; |
|
64 | 66 |
} |
65 |
|
|
67 |
|
|
66 | 68 |
@Override |
67 |
public String getInformationHTML(String info) { |
|
68 |
return htmlDump(); |
|
69 |
public String getInformationHTML(String name) { |
|
70 |
|
|
71 |
if ("Summary Statistics".equals(name)) { |
|
72 |
return htmlDumpGeneralStats(null); |
|
73 |
} else if ("Lexical Units properties".equals(name)) { |
|
74 |
return htmlDumpLexicalProperties(null); |
|
75 |
} else if ("Structural Units properties".equals(name)) { |
|
76 |
return htmlDumpStructureProperties(null); |
|
77 |
} else { |
|
78 |
return getInformation(name); |
|
79 |
} |
|
80 |
|
|
69 | 81 |
} |
70 |
|
|
82 |
|
|
71 | 83 |
// Numbers |
72 | 84 |
/** The T. */ |
73 | 85 |
int numberOfWords = 0; // number of word |
74 |
|
|
86 |
|
|
75 | 87 |
/** The N properties. */ |
76 | 88 |
int NProperties = 0; // number of word properties |
77 | 89 |
// HashMap<String, Integer> propertiesCounts = new HashMap<String, Integer>(); |
78 | 90 |
// // properties counts |
79 |
|
|
91 |
|
|
80 | 92 |
/** The properties values. */ |
81 | 93 |
HashMap<String, List<String>> propertiesValues = new HashMap<>(); // properties values |
82 |
|
|
94 |
|
|
83 | 95 |
/** The N structures. */ |
84 | 96 |
int NStructures = 0; // number of structures |
85 |
|
|
97 |
|
|
86 | 98 |
/** The structures counts. */ |
87 | 99 |
HashMap<String, Integer> structuresCounts = new HashMap<>(); // structures counts |
88 |
|
|
100 |
|
|
89 | 101 |
/** The internal architecture. */ |
90 | 102 |
List<String> internalArchitecture = new ArrayList<>(); // cqp structures = propertiesCounts keys but ordered |
91 |
|
|
103 |
|
|
92 | 104 |
/** The hierarchie counts. */ |
93 | 105 |
HashMap<String, Integer> hierarchieCounts = new HashMap<>(); // hierarchic structures counts |
94 |
|
|
106 |
|
|
95 | 107 |
/** The internal architecture properties. */ |
96 | 108 |
HashMap<String, HashMap<String, List<String>>> internalArchitectureProperties = new HashMap<>(); // hierarchic structures counts |
97 |
|
|
109 |
|
|
98 | 110 |
/** The internal architecture properties counts. */ |
99 | 111 |
HashMap<String, HashMap<String, Integer>> internalArchitecturePropertiesCounts = new HashMap<>(); // hierarchic structures counts |
100 |
|
|
112 |
|
|
101 | 113 |
// Annotations description |
102 | 114 |
/** The annotations types. */ |
103 | 115 |
HashMap<String, Integer> annotationsTypes = new HashMap<>(); // for each annotation its description |
104 |
|
|
116 |
|
|
105 | 117 |
/** The annotations origins. */ |
106 | 118 |
HashMap<String, Integer> annotationsOrigins = new HashMap<>(); // for each annoation its origin description |
107 |
|
|
119 |
|
|
108 | 120 |
/** The properties. */ |
109 | 121 |
List<WordProperty> properties; |
110 |
|
|
122 |
|
|
111 | 123 |
/** The structures. */ |
112 | 124 |
List<StructuralUnit> structures; |
113 |
|
|
125 |
|
|
114 | 126 |
@Override |
115 | 127 |
public String getName() { |
116 | 128 |
String filename = result.getMainCorpus() + "-" + result.getName(); //$NON-NLS-1$ |
... | ... | |
119 | 131 |
} |
120 | 132 |
return filename; |
121 | 133 |
} |
122 |
|
|
134 |
|
|
123 | 135 |
/** |
124 | 136 |
* Step general infos. |
125 | 137 |
*/ |
126 | 138 |
public void stepGeneralInfos() { |
127 | 139 |
try { |
128 | 140 |
properties = result.getOrderedProperties(); |
129 |
|
|
141 |
|
|
130 | 142 |
List<WordProperty> pproperties = new ArrayList<>(properties); |
131 | 143 |
for (WordProperty p : properties) { |
132 | 144 |
if (p.getName().equals("id")) { |
... | ... | |
134 | 146 |
} |
135 | 147 |
} |
136 | 148 |
properties = pproperties; |
149 |
|
|
137 | 150 |
NProperties = properties.size(); |
Formats disponibles : Unified diff