Révision 2408
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Subcorpus.java (revision 2408) | ||
---|---|---|
63 | 63 |
* @author jmague |
64 | 64 |
*/ |
65 | 65 |
public class Subcorpus extends CQPCorpus { |
66 |
|
|
66 |
|
|
67 | 67 |
/** |
68 | 68 |
* Query used to build the corpus. |
69 | 69 |
*/ |
70 |
@Parameter(key=TXMPreferences.QUERY)
|
|
70 |
@Parameter(key = TXMPreferences.QUERY)
|
|
71 | 71 |
protected CQLQuery pQuery; |
72 | 72 |
|
73 | 73 |
protected QueryResult qresult; |
... | ... | |
81 | 81 |
public Subcorpus(CQPCorpus corpus) { |
82 | 82 |
super(corpus); |
83 | 83 |
} |
84 |
|
|
84 |
|
|
85 | 85 |
/** |
86 | 86 |
* |
87 | 87 |
* @param partition |
... | ... | |
89 | 89 |
public Subcorpus(Partition partition) { |
90 | 90 |
super(partition); |
91 | 91 |
} |
92 |
|
|
92 |
|
|
93 | 93 |
/** |
94 | 94 |
* |
95 | 95 |
* @param parametersNodePath |
... | ... | |
97 | 97 |
public Subcorpus(String parametersNodePath) { |
98 | 98 |
super(parametersNodePath); |
99 | 99 |
} |
100 |
|
|
100 |
|
|
101 | 101 |
/** |
102 | 102 |
* Instantiates a new subcorpus. |
103 | 103 |
* |
... | ... | |
108 | 108 |
* @param parent the parent |
109 | 109 |
* @param query the query |
110 | 110 |
* @throws InvalidCqpIdException the invalid cqp id exception |
111 |
* {@link CQPCorpus#createSubcorpus(CQLQuery, String)} |
|
111 |
* {@link CQPCorpus#createSubcorpus(CQLQuery, String)}
|
|
112 | 112 |
*/ |
113 |
@Override |
|
113 | 114 |
protected boolean _compute() throws Exception { |
114 | 115 |
if (this.pQuery != null) { |
115 | 116 |
this.qresult = null; // reset |
... | ... | |
120 | 121 |
} |
121 | 122 |
return qresult != null; |
122 | 123 |
} |
123 |
|
|
124 | 124 |
|
125 |
|
|
125 | 126 |
@Override |
126 | 127 |
public String getComputingStartMessage() { |
127 | 128 |
return TXMCoreMessages.bind("Création du sous-corpus {0} dans le corpus {1}...", this.getSimpleName(), this.getParent().getName()); |
128 | 129 |
} |
129 |
|
|
130 |
|
|
130 | 131 |
@Override |
131 | 132 |
public String getComputingDoneMessage() { |
132 | 133 |
if (hasBeenComputedOnce()) { |
133 | 134 |
return getDetails(); |
134 |
} else { |
|
135 |
} |
|
136 |
else { |
|
135 | 137 |
return ""; |
136 | 138 |
} |
137 |
//return TXMCoreMessages.common_done; |
|
139 |
// return TXMCoreMessages.common_done;
|
|
138 | 140 |
} |
139 | 141 |
|
140 | 142 |
/* |
141 | 143 |
* retro compatibility method for import.xml file |
142 |
* |
|
143 | 144 |
* @see org.txm.searchengine.cqp.corpus.Corpus#getLocale() |
144 | 145 |
*/ |
145 | 146 |
@Override |
146 | 147 |
protected boolean _load(Element e) { |
147 | 148 |
if (e != null) { |
148 | 149 |
this.userName = e.getAttribute(NAME); |
149 |
this.pID = "S"+getNextSubcorpusCounter();
|
|
150 |
this.pID = "S" + getNextSubcorpusCounter();
|
|
150 | 151 |
this.pQuery = new CQLQuery(e.getAttribute("query")); //$NON-NLS-1$ |
151 |
|
|
152 |
|
|
152 | 153 |
NodeList subcorpusElems = e.getElementsByTagName("subcorpus"); //$NON-NLS-1$ |
153 |
for (int i = 0 ; i < subcorpusElems.getLength() ; i++) {
|
|
154 |
for (int i = 0; i < subcorpusElems.getLength(); i++) {
|
|
154 | 155 |
Element subcorpusElem = (Element) subcorpusElems.item(i); |
155 | 156 |
try { |
156 | 157 |
Subcorpus subcorp = new Subcorpus(this); |
157 | 158 |
subcorp._load(subcorpusElem); |
158 |
} catch (Exception ex) { |
|
159 |
} |
|
160 |
catch (Exception ex) { |
|
159 | 161 |
Log.warning(this.pID + TXMCoreMessages.failedToRestoreSubcorpus + subcorpusElem.getAttribute("name") |
160 |
+ " : " + ex); //$NON-NLS-1$ |
|
162 |
+ " : " + ex); //$NON-NLS-1$
|
|
161 | 163 |
} |
162 | 164 |
} |
163 |
|
|
165 |
|
|
164 | 166 |
NodeList partitionElems = e.getElementsByTagName("partition"); //$NON-NLS-1$ |
165 |
for (int i = 0 ; i < partitionElems.getLength() ; i++) {
|
|
167 |
for (int i = 0; i < partitionElems.getLength(); i++) {
|
|
166 | 168 |
Element partitionElem = (Element) partitionElems.item(i); |
167 | 169 |
String name = partitionElem.getAttribute("name"); //$NON-NLS-1$ |
168 |
List<String> names = new ArrayList<String>();
|
|
169 |
List<String> queries = new ArrayList<String>();
|
|
170 |
|
|
170 |
List<String> names = new ArrayList<>(); |
|
171 |
List<String> queries = new ArrayList<>(); |
|
172 |
|
|
171 | 173 |
NodeList partElems = partitionElem.getElementsByTagName("part"); //$NON-NLS-1$ |
172 | 174 |
for (int j = 0; j < partElems.getLength(); j++) { |
173 | 175 |
Element part = (Element) partElems.item(j); |
... | ... | |
175 | 177 |
queries.add(part.getAttribute("query")); //$NON-NLS-1$ |
176 | 178 |
} |
177 | 179 |
try { |
178 |
//System.out.println("Create Partition with corpus "+this+" : "+name+", queries "+queries+", names "+names); |
|
180 |
// System.out.println("Create Partition with corpus "+this+" : "+name+", queries "+queries+", names "+names);
|
|
179 | 181 |
Partition partition = new Partition(this); |
180 | 182 |
partition.setParameters(name, queries, names); |
181 |
//partition.setSelfElement(partitionElem); |
|
183 |
// partition.setSelfElement(partitionElem);
|
|
182 | 184 |
partition._load(partitionElem); |
183 |
} catch (Exception ex) { |
|
185 |
} |
|
186 |
catch (Exception ex) { |
|
184 | 187 |
Log.warning(this.pID + TXMCoreMessages.failedToRestorePartition + name |
185 | 188 |
+ " : " + ex); //$NON-NLS-1$ |
186 |
//c.getParentNode().removeChild(c); |
|
189 |
// c.getParentNode().removeChild(c);
|
|
187 | 190 |
} |
188 | 191 |
} |
189 | 192 |
} |
190 | 193 |
initSelectionResult(e); |
191 |
//System.out.println("Subcorpus.load: Selection of "+this+" = "+selectionResult); |
|
192 |
//return super.load(); |
|
194 |
// System.out.println("Subcorpus.load: Selection of "+this+" = "+selectionResult);
|
|
195 |
// return super.load();
|
|
193 | 196 |
return true; |
194 | 197 |
} |
195 |
|
|
198 |
|
|
196 | 199 |
@Override |
197 | 200 |
public boolean canCompute() { |
198 | 201 |
return pID != null && userName != null && (pQuery != null || qresult != null); |
... | ... | |
200 | 203 |
|
201 | 204 |
/* |
202 | 205 |
* (non-Javadoc) |
203 |
* |
|
204 | 206 |
* @see |
205 | 207 |
* org.txm.searchengine.cqp.corpus.CqpObject#checkCqpId(java.lang |
206 | 208 |
* .String) |
... | ... | |
211 | 213 |
throw new InvalidCqpIdException(TXMCoreMessages.bind(CQPSearchEngineCoreMessages.p0IsNotAValidCQPIDForASubcorpusItMustBeAnUppercaseCharacterFollowedByLowercaseCharacters, pID)); |
212 | 214 |
return true; |
213 | 215 |
} |
214 |
|
|
216 |
|
|
215 | 217 |
@Override |
216 | 218 |
public void clean() { |
217 | 219 |
super.clean(); |
218 | 220 |
|
219 | 221 |
// nothing to do if the corpus has not yet been computed |
220 |
if(this.hasBeenComputedOnce) { |
|
222 |
if (this.hasBeenComputedOnce) {
|
|
221 | 223 |
try { |
222 | 224 |
AbstractCqiClient CQI = CorpusManager.getCorpusManager().getCqiClient(); |
223 | 225 |
if (CQPSearchEngine.isInitialized()) { |
... | ... | |
234 | 236 |
qresult = null; |
235 | 237 |
selectionResult = null; |
236 | 238 |
} |
237 |
|
|
239 |
|
|
238 | 240 |
@Override |
239 | 241 |
public String getDetails() { |
240 | 242 |
try { |
241 |
return "T "+this.getSize(); |
|
242 |
} catch (CqiClientException e) { |
|
243 |
return this.getName()+ " (" + this.getQualifiedCqpId()+")"; |
|
243 |
return "T " + this.getSize(); |
|
244 | 244 |
} |
245 |
catch (CqiClientException e) { |
|
246 |
return this.getName() + " (" + this.getQualifiedCqpId() + ")"; |
|
247 |
} |
|
245 | 248 |
} |
246 |
|
|
249 |
|
|
247 | 250 |
@Override |
248 | 251 |
public List<Match> getMatches() { |
249 | 252 |
try { |
250 | 253 |
return qresult.getMatches(); |
251 |
} catch (CqiClientException e) { |
|
254 |
} |
|
255 |
catch (CqiClientException e) { |
|
252 | 256 |
// TODO Auto-generated catch block |
253 | 257 |
org.txm.utils.logger.Log.printStackTrace(e); |
254 |
return new ArrayList<Match>();
|
|
258 |
return new ArrayList<>(); |
|
255 | 259 |
} |
256 | 260 |
} |
257 |
|
|
261 |
|
|
258 | 262 |
public int getNMatch() { |
259 | 263 |
try { |
260 | 264 |
return qresult.getNMatch(); |
261 |
} catch (CqiClientException e) { |
|
265 |
} |
|
266 |
catch (CqiClientException e) { |
|
262 | 267 |
// TODO Auto-generated catch block |
263 | 268 |
org.txm.utils.logger.Log.printStackTrace(e); |
264 | 269 |
return 0; |
265 | 270 |
} |
266 | 271 |
} |
267 |
|
|
272 |
|
|
268 | 273 |
/* |
269 | 274 |
* (non-Javadoc) |
270 |
* |
|
271 | 275 |
* @see org.txm.searchengine.cqp.corpus.Corpus#getProperties() |
272 | 276 |
*/ |
273 | 277 |
@Override |
274 | 278 |
public List<WordProperty> getProperties() throws CqiClientException { |
275 | 279 |
return getMainCorpus().getProperties(); |
276 | 280 |
} |
277 |
|
|
281 |
|
|
278 | 282 |
/* |
279 | 283 |
* (non-Javadoc) |
280 |
* |
|
281 | 284 |
* @see |
282 | 285 |
* org.txm.searchengine.cqp.corpus.Corpus#getProperty(java.lang. |
283 | 286 |
* String) |
... | ... | |
286 | 289 |
public WordProperty getProperty(String name) throws CqiClientException { |
287 | 290 |
return getMainCorpus().getProperty(name); |
288 | 291 |
} |
289 |
|
|
292 |
|
|
290 | 293 |
// protected void finalize() throws Throwable { |
291 | 294 |
// try { |
292 | 295 |
// // |
293 |
//
|
|
296 |
// |
|
294 | 297 |
// //As finalize is run in a separate thread, we have problems of concurrent |
295 | 298 |
// accesses to the cqi server if we drop the subcorpus here. |
296 | 299 |
// //It as to be done manually |
... | ... | |
301 | 304 |
// super.finalize(); |
302 | 305 |
// } |
303 | 306 |
// } |
304 |
|
|
307 |
|
|
305 | 308 |
/* |
306 | 309 |
* (non-Javadoc) |
307 |
* |
|
308 | 310 |
* @see |
309 | 311 |
* org.txm.searchengine.cqp.corpus.CqpObject#getQualifiedCqpId() |
310 | 312 |
*/ |
... | ... | |
312 | 314 |
public String getQualifiedCqpId() { |
313 | 315 |
return getMainCorpus().getCqpId() + ":" + this.pID; //$NON-NLS-1$ |
314 | 316 |
} |
315 |
|
|
316 |
// /**
|
|
317 |
// * Register to parent.
|
|
318 |
// *
|
|
319 |
// * @param subcorpusName the subcorpus name
|
|
320 |
// * @param query the query
|
|
321 |
// */
|
|
322 |
// private void registerToParent(String subcorpusName, CQLQuery query) {
|
|
323 |
// if (this.getSelfElement() == null && this.getParent() != null)
|
|
324 |
// try {
|
|
325 |
// Element parentElem = (Element) this.getParent().getSelfElement();
|
|
326 |
// if (parentElem == null) return;
|
|
327 |
// Document doc = parentElem.getOwnerDocument();
|
|
328 |
// Element subcorpusElem = doc.createElement("subcorpus"); //$NON-NLS-1$
|
|
329 |
// subcorpusElem.setAttribute("name", subcorpusName); //$NON-NLS-1$
|
|
330 |
// subcorpusElem.setAttribute("desc", subcorpusName); //$NON-NLS-1$
|
|
331 |
// if (query != null)
|
|
332 |
// subcorpusElem.setAttribute("query", query.getQueryString()); //$NON-NLS-1$
|
|
333 |
// Element corporaElem;
|
|
334 |
// if (this.getParent() instanceof MainCorpus) {
|
|
335 |
// NodeList corporaList = parentElem.getElementsByTagName("preBuild"); //$NON-NLS-1$
|
|
336 |
// corporaElem = (Element) corporaList.item(0);
|
|
337 |
// } else {
|
|
338 |
// corporaElem = parentElem;
|
|
339 |
// }
|
|
340 |
// corporaElem.appendChild(subcorpusElem);
|
|
341 |
// this.setSelfElement(subcorpusElem);
|
|
342 |
// } catch (Exception e) {
|
|
343 |
// System.out.println(TXMCoreMessages.Subcorpus_2+Log.toString(e));
|
|
344 |
// }
|
|
317 |
|
|
318 |
// /**
|
|
319 |
// * Register to parent. |
|
320 |
// * |
|
321 |
// * @param subcorpusName the subcorpus name |
|
322 |
// * @param query the query |
|
323 |
// */ |
|
324 |
// private void registerToParent(String subcorpusName, CQLQuery query) {
|
|
325 |
// if (this.getSelfElement() == null && this.getParent() != null)
|
|
326 |
// try {
|
|
327 |
// Element parentElem = (Element) this.getParent().getSelfElement();
|
|
328 |
// if (parentElem == null) return;
|
|
329 |
// Document doc = parentElem.getOwnerDocument();
|
|
330 |
// Element subcorpusElem = doc.createElement("subcorpus"); //$NON-NLS-1$
|
|
331 |
// subcorpusElem.setAttribute("name", subcorpusName); //$NON-NLS-1$
|
|
332 |
// subcorpusElem.setAttribute("desc", subcorpusName); //$NON-NLS-1$
|
|
333 |
// if (query != null)
|
|
334 |
// subcorpusElem.setAttribute("query", query.getQueryString()); //$NON-NLS-1$
|
|
335 |
// Element corporaElem;
|
|
336 |
// if (this.getParent() instanceof MainCorpus) {
|
|
337 |
// NodeList corporaList = parentElem.getElementsByTagName("preBuild"); //$NON-NLS-1$
|
|
338 |
// corporaElem = (Element) corporaList.item(0);
|
|
339 |
// } else {
|
|
340 |
// corporaElem = parentElem;
|
|
341 |
// }
|
|
342 |
// corporaElem.appendChild(subcorpusElem);
|
|
343 |
// this.setSelfElement(subcorpusElem);
|
|
344 |
// } catch (Exception e) {
|
|
345 |
// System.out.println(TXMCoreMessages.Subcorpus_2+Log.toString(e));
|
|
346 |
// }
|
|
345 | 347 |
// |
346 |
// this._load();
|
|
347 |
// }
|
|
348 |
|
|
348 |
// this._load();
|
|
349 |
// }
|
|
350 |
|
|
349 | 351 |
/** |
350 | 352 |
* Gets the query. |
351 | 353 |
* |
... | ... | |
354 | 356 |
public CQLQuery getQuery() { |
355 | 357 |
return pQuery; |
356 | 358 |
} |
357 |
|
|
359 |
|
|
358 | 360 |
@Override |
359 | 361 |
public String getResultType() { |
360 | 362 |
return "Corpus"; |
361 | 363 |
} |
362 |
|
|
364 |
|
|
363 | 365 |
public SelectionResult getSelectionResult() { |
364 | 366 |
return selectionResult; |
365 | 367 |
} |
366 |
|
|
368 |
|
|
367 | 369 |
@Override |
368 | 370 |
public String getSimpleName() { |
369 | 371 |
return this.getName(); |
370 | 372 |
} |
371 |
|
|
373 |
|
|
372 | 374 |
/** |
373 | 375 |
* Returns the number of occurrences in the subcorpus. |
374 | 376 |
* |
... | ... | |
384 | 386 |
if (!hasBeenComputedOnce) return 0; |
385 | 387 |
|
386 | 388 |
if (this.size == -1) { |
387 |
//Log.finest(TXMCoreMessages.bind(TXMCoreMessages.SUBCORPUS_SIZE, new Object[]{this.pName, "N/A"})); |
|
389 |
// Log.finest(TXMCoreMessages.bind(TXMCoreMessages.SUBCORPUS_SIZE, new Object[]{this.pName, "N/A"}));
|
|
388 | 390 |
long start = System.currentTimeMillis(); |
389 |
|
|
391 |
|
|
390 | 392 |
try { |
391 | 393 |
AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient(); |
392 |
String qid= this.getQualifiedCqpId(); |
|
394 |
String qid = this.getQualifiedCqpId();
|
|
393 | 395 |
int nMatch = cqiClient.subCorpusSize(qid); |
394 |
//System.out.println("n matchs: "+nMatch); |
|
396 |
// System.out.println("n matchs: "+nMatch);
|
|
395 | 397 |
if (nMatch == 0) { |
396 | 398 |
this.size = 0; |
397 | 399 |
} |
... | ... | |
402 | 404 |
throw new UnexpectedAnswerException(); |
403 | 405 |
} |
404 | 406 |
this.size = 0; |
405 |
|
|
407 |
|
|
406 | 408 |
for (int i = 0; i < match.length; i++) { |
407 | 409 |
size += matchend[i] - match[i] + 1; |
408 | 410 |
} |
409 | 411 |
} |
410 |
} catch (Exception e) { |
|
412 |
} |
|
413 |
catch (Exception e) { |
|
411 | 414 |
throw new CqiClientException(e); |
412 | 415 |
} |
413 | 416 |
long end = System.currentTimeMillis(); |
414 |
Log.finest(NLS.bind(SearchEngineCoreMessages.sizeOfSubcorpusP0P1ComputedInP2Ms, new Object[]{this.pID, this.size, (end - start)}));
|
|
417 |
Log.finest(NLS.bind(SearchEngineCoreMessages.sizeOfSubcorpusP0P1ComputedInP2Ms, new Object[] { this.pID, this.size, (end - start) }));
|
|
415 | 418 |
} |
416 | 419 |
return this.size; |
417 | 420 |
} |
418 |
|
|
421 |
|
|
419 | 422 |
@Override |
420 | 423 |
public int[] getStartLimits(String sup) throws IOException, |
421 |
CqiServerError, InvalidCqpIdException, CqiClientException { |
|
424 |
CqiServerError, InvalidCqpIdException, CqiClientException {
|
|
422 | 425 |
return this.getMainCorpus().getStartLimits(sup); |
423 | 426 |
} |
424 |
|
|
427 |
|
|
425 | 428 |
/* |
426 | 429 |
* (non-Javadoc) |
427 |
* |
|
428 | 430 |
* @see |
429 | 431 |
* org.txm.searchengine.cqp.corpus.Corpus#getStructuralUnit(java |
430 | 432 |
* .lang.String) |
... | ... | |
434 | 436 |
throws CqiClientException { |
435 | 437 |
return getMainCorpus().getStructuralUnit(name); |
436 | 438 |
} |
437 |
|
|
439 |
|
|
438 | 440 |
/* |
439 | 441 |
* (non-Javadoc) |
440 |
* |
|
441 | 442 |
* @see org.txm.searchengine.cqp.corpus.Corpus#getStructuralUnits() |
442 | 443 |
*/ |
443 | 444 |
@Override |
444 | 445 |
public List<StructuralUnit> getStructuralUnits() throws CqiClientException { |
445 | 446 |
return getMainCorpus().getStructuralUnits(); |
446 | 447 |
} |
447 |
|
|
448 |
|
|
448 | 449 |
public SelectionResult initSelectionResult(Element e) { |
449 |
|
|
450 |
|
|
450 | 451 |
if (e != null) { |
451 | 452 |
selectionResult = new SelectionResult(); |
452 | 453 |
NodeList selectionList = e.getElementsByTagName("selection"); //$NON-NLS-1$ |
453 |
for (int i = 0 ; i < selectionList.getLength() ;) {
|
|
454 |
for (int i = 0; i < selectionList.getLength();) {
|
|
454 | 455 |
Element selection = (Element) selectionList.item(i); // the selection element |
455 |
|
|
456 |
|
|
456 | 457 |
NodeList textList = selection.getElementsByTagName("selText"); // get text ids //$NON-NLS-1$ |
457 |
for (int j = 0 ; j < textList.getLength() ; j++) {
|
|
458 |
for (int j = 0; j < textList.getLength(); j++) {
|
|
458 | 459 |
Element text = (Element) textList.item(j); |
459 | 460 |
selectionResult.add(text.getAttribute("id")); //$NON-NLS-1$ |
460 | 461 |
} |
461 |
|
|
462 |
|
|
462 | 463 |
NodeList critList = selection.getElementsByTagName("selCrit"); // get the criteria //$NON-NLS-1$ |
463 |
for (int j = 0 ; j < critList.getLength() ; j++) {
|
|
464 |
for (int j = 0; j < critList.getLength(); j++) {
|
|
464 | 465 |
Element crit = (Element) critList.item(j); |
465 | 466 |
String name = crit.getAttribute("id"); // the name of the critera //$NON-NLS-1$ |
466 | 467 |
if (!selectionResult.critera.containsKey(name)) // create new list if new critera |
... | ... | |
472 | 473 |
} |
473 | 474 |
return selectionResult; |
474 | 475 |
} |
475 |
|
|
476 |
|
|
476 | 477 |
@Override |
477 | 478 |
public boolean loadParameters() throws Exception { |
478 | 479 |
String q = this.getStringParameterValue(TXMPreferences.QUERY); |
... | ... | |
482 | 483 |
|
483 | 484 |
return true; |
484 | 485 |
} |
485 |
|
|
486 |
|
|
486 | 487 |
@Override |
487 | 488 |
public boolean saveParameters() throws Exception { |
488 | 489 |
if (pQuery != null) { |
... | ... | |
490 | 491 |
} |
491 | 492 |
return true; |
492 | 493 |
} |
493 |
|
|
494 |
|
|
494 | 495 |
/** |
495 | 496 |
* Instantiates a new subcorpus. |
496 | 497 |
* |
... | ... | |
501 | 502 |
* @param parent the parent |
502 | 503 |
* @param query the query |
503 | 504 |
* @throws InvalidCqpIdException the invalid cqp id exception |
504 |
* {@link CQPCorpus#createSubcorpus(CQLQuery, String)} |
|
505 |
* {@link CQPCorpus#createSubcorpus(CQLQuery, String)}
|
|
505 | 506 |
*/ |
506 | 507 |
protected void setParameters(String pID, String name, CQLQuery query) throws InvalidCqpIdException { |
507 | 508 |
this.pID = pID; |
508 | 509 |
this.pQuery = query; |
509 | 510 |
this.userName = name; |
510 | 511 |
} |
511 |
|
|
512 |
|
|
512 | 513 |
/** |
513 | 514 |
* |
514 | 515 |
* @param cqpId |
... | ... | |
520 | 521 |
this.userName = name; |
521 | 522 |
this.pQuery = queryResult.getQuery(); |
522 | 523 |
this.qresult = queryResult; |
523 |
|
|
524 |
|
|
524 | 525 |
this.dirty = false; |
525 | 526 |
} |
526 |
|
|
527 |
|
|
527 | 528 |
@Override |
528 | 529 |
public boolean setParameters(TXMParameters parameters) { |
529 | 530 |
// TODO Auto-generated method stub |
530 | 531 |
System.err.println("Subcorpus.setParameters(): not yet implemented."); |
531 | 532 |
return true; |
532 | 533 |
} |
533 |
|
|
534 |
|
|
534 | 535 |
/** |
535 | 536 |
* Sets the query to use. |
537 |
* |
|
536 | 538 |
* @param query |
537 | 539 |
*/ |
538 | 540 |
public void setQuery(CQLQuery query) { |
539 | 541 |
this.pQuery = query; |
540 | 542 |
} |
541 |
|
|
542 |
|
|
543 |
//TODO merge SelectionResult and Subcorpus ? |
|
543 |
|
|
544 |
|
|
545 |
// TODO merge SelectionResult and Subcorpus ?
|
|
544 | 546 |
public void setSelectionResult(SelectionResult selectionResult) { |
545 | 547 |
this.selectionResult = selectionResult; |
546 |
//TODO persists the selectionResult ? |
|
547 |
// if (this.getSelfElement() != null) {
|
|
548 |
// //remove old node if any
|
|
549 |
// NodeList selectionList = getSelfElement().getElementsByTagName("selection"); //$NON-NLS-1$
|
|
550 |
// for (int i = 0 ; i < selectionList.getLength() ; i++)
|
|
551 |
// getSelfElement().removeChild(selectionList.item(i));
|
|
548 |
// TODO persists the selectionResult ?
|
|
549 |
// if (this.getSelfElement() != null) {
|
|
550 |
// //remove old node if any
|
|
551 |
// NodeList selectionList = getSelfElement().getElementsByTagName("selection"); //$NON-NLS-1$
|
|
552 |
// for (int i = 0 ; i < selectionList.getLength() ; i++)
|
|
553 |
// getSelfElement().removeChild(selectionList.item(i));
|
|
552 | 554 |
// |
553 |
// Document doc = this.getParent().getSelfElement().getOwnerDocument();
|
|
554 |
// Element selectionElem = doc.createElement("selection"); // the selection element //$NON-NLS-1$
|
|
555 |
// for (String txt : selectionResult) // the text ids
|
|
556 |
// {
|
|
557 |
// Element textElem = doc.createElement("selText"); //$NON-NLS-1$
|
|
558 |
// textElem.setAttribute("id", txt); //$NON-NLS-1$
|
|
559 |
// selectionElem.appendChild(textElem);
|
|
560 |
// }
|
|
561 |
// for (String crit : selectionResult.critera.keySet()) // the critera
|
|
562 |
// {
|
|
563 |
// ArrayList<String> values = selectionResult.critera.get(crit);
|
|
564 |
// for (String value : values) {
|
|
565 |
// Element criteraElem = doc.createElement("selCrit"); //$NON-NLS-1$
|
|
566 |
// criteraElem.setAttribute("id", crit); //$NON-NLS-1$
|
|
567 |
// criteraElem.setAttribute("value", value); //$NON-NLS-1$
|
|
568 |
// selectionElem.appendChild(criteraElem);
|
|
569 |
// }
|
|
570 |
// }
|
|
571 |
// getSelfElement().appendChild(selectionElem);// append selection elem to self
|
|
572 |
// }
|
|
555 |
// Document doc = this.getParent().getSelfElement().getOwnerDocument();
|
|
556 |
// Element selectionElem = doc.createElement("selection"); // the selection element //$NON-NLS-1$
|
|
557 |
// for (String txt : selectionResult) // the text ids
|
|
558 |
// {
|
|
559 |
// Element textElem = doc.createElement("selText"); //$NON-NLS-1$
|
|
560 |
// textElem.setAttribute("id", txt); //$NON-NLS-1$
|
|
561 |
// selectionElem.appendChild(textElem);
|
|
562 |
// }
|
|
563 |
// for (String crit : selectionResult.critera.keySet()) // the critera
|
|
564 |
// {
|
|
565 |
// ArrayList<String> values = selectionResult.critera.get(crit);
|
|
566 |
// for (String value : values) {
|
|
567 |
// Element criteraElem = doc.createElement("selCrit"); //$NON-NLS-1$
|
|
568 |
// criteraElem.setAttribute("id", crit); //$NON-NLS-1$
|
|
569 |
// criteraElem.setAttribute("value", value); //$NON-NLS-1$
|
|
570 |
// selectionElem.appendChild(criteraElem);
|
|
571 |
// }
|
|
572 |
// }
|
|
573 |
// getSelfElement().appendChild(selectionElem);// append selection elem to self
|
|
574 |
// }
|
|
573 | 575 |
} |
574 |
|
|
575 |
/* (non-Javadoc) |
|
576 |
|
|
577 |
/* |
|
578 |
* (non-Javadoc) |
|
576 | 579 |
* @see java.lang.Object#toString() |
577 | 580 |
*/ |
578 | 581 |
@Override |
579 | 582 |
public String toString() { |
580 | 583 |
return this.getName(); |
581 | 584 |
} |
582 |
|
|
585 |
|
|
583 | 586 |
@Override |
584 | 587 |
@Deprecated |
585 | 588 |
public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception { |
586 | 589 |
return false; |
587 | 590 |
} |
588 |
|
|
591 |
|
|
589 | 592 |
@Override |
590 | 593 |
public void setIsModified(boolean b) { |
591 | 594 |
// nothing |
592 | 595 |
} |
593 |
|
|
596 |
|
|
594 | 597 |
@Override |
595 | 598 |
public CorpusBuild getRootCorpusBuild() { |
596 | 599 |
return getMainCorpus(); |
... | ... | |
599 | 602 |
/** |
600 | 603 |
* Return the CQP START positions of the main corpus texts |
601 | 604 |
*/ |
605 |
@Override |
|
602 | 606 |
public int[] getTextStartLimits() throws CqiClientException, IOException, CqiServerError, InvalidCqpIdException { |
603 | 607 |
if (textLimits == null) { |
604 | 608 |
textLimits = getStartLimits("[text] expand left to text"); |
... | ... | |
609 | 613 |
/** |
610 | 614 |
* Return the CQP END positions of the main corpus texts |
611 | 615 |
*/ |
616 |
@Override |
|
612 | 617 |
public int[] getTextEndLimits() throws CqiClientException, IOException, CqiServerError, InvalidCqpIdException { |
613 | 618 |
if (textEndLimits == null) { |
614 | 619 |
String queryResultId = queryResultNamePrefix + UUID.randomUUID().toString(); |
615 | 620 |
CorpusManager.getCorpusManager().getCqiClient().cqpQuery( |
616 | 621 |
this.getQualifiedCqpId(), queryResultId, "[text] expand right to text"); //$NON-NLS-1$ |
617 |
QueryResult queryResult = new QueryResult(queryResultId, queryResultId, this, new CQLQuery("[text] expand right to text")); //$NON-NLS-1$
|
|
622 |
QueryResult queryResult = new QueryResult(queryResultId, queryResultId, this, new CQLQuery("[text] expand right to text")); //$NON-NLS-1$
|
|
618 | 623 |
textEndLimits = queryResult.getEnds(); |
619 | 624 |
} |
620 | 625 |
return textEndLimits; |
... | ... | |
625 | 630 |
* |
626 | 631 |
* @return the nb texts |
627 | 632 |
* @throws CqiClientException the cqi client exception |
628 |
* @throws CqiServerError
|
|
629 |
* @throws IOException
|
|
633 |
* @throws CqiServerError |
|
634 |
* @throws IOException |
|
630 | 635 |
*/ |
631 |
public int getNbTexts() throws CqiClientException, IOException, CqiServerError
|
|
632 |
{ |
|
636 |
@Override
|
|
637 |
public int getNbTexts() throws CqiClientException, IOException, CqiServerError {
|
|
633 | 638 |
if (nbtext == -1) { |
634 | 639 |
|
635 | 640 |
List<Integer> structsIncorpus = getTextNumberInCorpus(); |
... | ... | |
638 | 643 |
} |
639 | 644 |
return nbtext; |
640 | 645 |
} |
641 |
|
|
646 |
|
|
642 | 647 |
private List<Integer> getTextNumberInCorpus() throws CqiClientException, IOException, CqiServerError { |
643 | 648 |
|
644 | 649 |
StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$ |
... | ... | |
647 | 652 |
|
648 | 653 |
int[] structs = new int[nbtext]; |
649 | 654 |
int[][] structs_positions = new int[structs.length][2]; |
650 |
for (int i = 0 ; i < nbtext ; i++) {
|
|
655 |
for (int i = 0; i < nbtext; i++) {
|
|
651 | 656 |
structs[i] = i; |
652 | 657 |
structs_positions[i] = CorpusManager.getCorpusManager().getCqiClient().struc2Cpos(text_id_sup.getQualifiedName(), i); |
653 | 658 |
} |
654 | 659 |
|
655 |
List<Integer> structsIncorpus = new ArrayList<Integer>();
|
|
656 |
//filter structs with matches |
|
660 |
List<Integer> structsIncorpus = new ArrayList<>(); |
|
661 |
// filter structs with matches
|
|
657 | 662 |
List<Match> matches = this.getMatches(); |
658 | 663 |
int iText = 0; |
659 | 664 |
int iMatch = 0; |
... | ... | |
661 | 666 |
while (iText < structs.length && iMatch < matches.size()) { |
662 | 667 |
if (structs_positions[iText][1] < matches.get(iMatch).getStart()) { // match before text |
663 | 668 |
iText++; |
664 |
} else if (matches.get(iMatch).getEnd() < structs_positions[iText][0]) { // text before match |
|
669 |
} |
|
670 |
else if (matches.get(iMatch).getEnd() < structs_positions[iText][0]) { // text before match |
|
665 | 671 |
iMatch++; |
666 |
} else { // a match in the text |
|
672 |
} |
|
673 |
else { // a match in the text |
|
667 | 674 |
structsIncorpus.add(iText); |
668 | 675 |
iText++; |
669 | 676 |
} |
... | ... | |
678 | 685 |
* @throws IOException |
679 | 686 |
* @throws CqiServerError |
680 | 687 |
*/ |
688 |
@Override |
|
681 | 689 |
public String[] getCorpusTextIdsList() throws CqiClientException, IOException, CqiServerError { |
682 |
|
|
690 |
|
|
683 | 691 |
StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$ |
684 | 692 |
StructuralUnitProperty text_id_sup = text_su.getProperty("id"); //$NON-NLS-1$ |
685 | 693 |
|
686 | 694 |
List<Integer> list = getTextNumberInCorpus(); |
687 | 695 |
int[] structs = new int[list.size()]; |
688 |
for (int i = 0 ; i < list.size() ; i++) {
|
|
696 |
for (int i = 0; i < list.size(); i++) {
|
|
689 | 697 |
structs[i] = list.get(i); |
690 | 698 |
} |
691 |
|
|
699 |
|
|
692 | 700 |
return CorpusManager.getCorpusManager().getCqiClient().struc2Str(text_id_sup.getQualifiedName(), structs); |
693 | 701 |
} |
694 | 702 |
|
... | ... | |
700 | 708 |
* @throws CqiServerError the cqi server error |
701 | 709 |
* @throws CqiClientException the cqi client exception |
702 | 710 |
*/ |
703 |
public HashMap<String, Integer> getTextsIds() throws IOException, CqiServerError, CqiClientException
|
|
704 |
{ |
|
711 |
@Override
|
|
712 |
public HashMap<String, Integer> getTextsIds() throws IOException, CqiServerError, CqiClientException {
|
|
705 | 713 |
if (textids == null) { |
706 |
textids = new HashMap<String, Integer>();
|
|
714 |
textids = new HashMap<>(); |
|
707 | 715 |
List<Integer> list = getTextNumberInCorpus(); |
708 | 716 |
int[] structs = new int[list.size()]; |
709 |
for (int i = 0 ; i < list.size() ; i++) {
|
|
717 |
for (int i = 0; i < list.size(); i++) {
|
|
710 | 718 |
structs[i] = list.get(i); |
711 | 719 |
} |
712 |
|
|
720 |
|
|
713 | 721 |
StructuralUnit text_su = this.getStructuralUnit("text"); //$NON-NLS-1$ |
714 | 722 |
StructuralUnitProperty text_id_sup = text_su.getProperty("id"); //$NON-NLS-1$ |
715 |
|
|
723 |
|
|
716 | 724 |
String[] ids = CorpusManager.getCorpusManager().getCqiClient().struc2Str(text_id_sup.getQualifiedName(), structs); |
717 |
for(int i = 0 ; i < ids.length ; i++) {
|
|
725 |
for (int i = 0; i < ids.length; i++) {
|
|
718 | 726 |
textids.put(ids[i], structs[i]); |
719 | 727 |
} |
720 | 728 |
} |
721 | 729 |
return textids; |
722 | 730 |
} |
723 |
} |
|
731 |
} |
Formats disponibles : Unified diff