Revision 1804

tmp/org.txm.index.rcp/src/org/txm/index/rcp/editors/IndexEditor.java (revision 1804)
211 211
		layoutData.grabExcessHorizontalSpace = true;
212 212
		queryWidget.setLayoutData(layoutData);
213 213
		queryWidget.addKeyListener(computeKeyListener);
214

  
214
		queryWidget.getQueryWidget().addModifyListener(computeKeyListener);
215 215
		
216 216
		// Word properties selector
217 217
		propertiesSelector = new PropertiesSelector<WordProperty>(this.getMainParametersComposite(), SWT.NONE);
tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/editors/ConcordanceEditor.java (revision 1804)
1928 1928

  
1929 1929
		StructuredSelection select = (StructuredSelection) viewer.getSelection();
1930 1930
		if (select == null) return false;
1931
		
1931 1932
		Line line = (Line) select.getFirstElement();
1932 1933
		if (line == null) return false;
1933 1934

  
1934 1935
		try {
1935
			IConfigurationElement[] config = Platform.getExtensionRegistry()
1936
					.getConfigurationElementsFor(BACKTOTEXT_COMMAND_ID);
1936
			IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(BACKTOTEXT_COMMAND_ID);
1937 1937
			for (IConfigurationElement e : config) {
1938 1938
				Object o = e.createExecutableExtension("class"); // //$NON-NLS-1$
1939 1939
				if (o instanceof BackToTextCommand) {
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Subcorpus.java (revision 1804)
55 55
import org.w3c.dom.NodeList;
56 56

  
57 57
/**
58
 * The Class Subcorpus.
58
 * The Class Subcorpus represent a MainCorpus subcorpus
59 59
 * 
60 60
 * @author jmague
61 61
 */
62 62
public class Subcorpus extends CQPCorpus {
63 63

  
64

  
65
	private SelectionResult selectionResult;
66
	protected QueryResult qresult;
67

  
68

  
69
	
70 64
	/**
71 65
	 * Query used to build the corpus.
72 66
	 */
73 67
	@Parameter(key=TXMPreferences.QUERY)
74 68
	protected CQLQuery pQuery;
75

  
76 69
	
70
	protected QueryResult qresult;
71
	
72
	protected SelectionResult selectionResult;
73
	
77 74
	/**
78 75
	 * 
79 76
	 * @param corpus
......
110 107
	 * @throws InvalidCqpIdException the invalid cqp id exception
111 108
	 * {@link CQPCorpus#createSubcorpus(CQLQuery, String)}
112 109
	 */
113
	protected void setParameters(String pID, String name, CQLQuery query) throws InvalidCqpIdException {
114
		this.pID = pID;
115
		this.pQuery = query;
116
		this.userName = name;
117
	}
118

  
119
	/**
120
	 * Instantiates a new subcorpus.
121
	 * 
122
	 * Not intended to be used directly.
123
	 *
124
	 * @param pID the cqp id
125
	 * @param name the name
126
	 * @param parent the parent
127
	 * @param query the query
128
	 * @throws InvalidCqpIdException the invalid cqp id exception
129
	 * {@link CQPCorpus#createSubcorpus(CQLQuery, String)}
130
	 */
131 110
	protected boolean _compute() throws Exception {
132 111
		if (this.pQuery != null) {
133 112
			this.qresult = null; // reset
......
139 118
		return qresult != null;
140 119
	}
141 120

  
142
	/**
143
	 * Sets the query to use.
144
	 * @param query
145
	 */
146
	public void setQuery(CQLQuery query) {
147
		this.pQuery = query;
148
	}
149

  
150
	/**
151
	 * Returns the number of occurrences in the subcorpus.
121
	/*
122
	 * retro compatability method for import.xml file
152 123
	 * 
153
	 * @return the size
154
	 * 
155
	 * @throws CqiClientException
156
	 *             the cqi client exception
157
	 * 
158
	 * @see org.txm.searchengine.cqp.corpus.CQPCorpus#getSize()
124
	 * @see org.txm.searchengine.cqp.corpus.Corpus#getLocale()
159 125
	 */
160 126
	@Override
161
	public int getSize() throws CqiClientException {
162
		if (!hasBeenComputedOnce) return 0;
163
		
164
		if (this.size == -1) {
165
			//Log.finest(TXMCoreMessages.bind(TXMCoreMessages.SUBCORPUS_SIZE, new Object[]{this.pName, "N/A"}));
166
			long start = System.currentTimeMillis();
127
	protected boolean _load(Element e) {
128
		if (e != null) {
129
			this.userName = e.getAttribute(NAME);
130
			this.pID = "S"+getNextSubcorpusCounter();
131
			this.pQuery = new CQLQuery(e.getAttribute("query")); //$NON-NLS-1$
167 132

  
168
			try {
169
				AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient();
170
				String qid= this.getQualifiedCqpId();
171
				int nMatch = cqiClient.subCorpusSize(qid);
172
				//System.out.println("n matchs: "+nMatch);
173
				if (nMatch == 0) {
174
					this.size = 0;
133
			NodeList subcorpusElems = e.getElementsByTagName("subcorpus"); //$NON-NLS-1$
134
			for (int i = 0 ; i < subcorpusElems.getLength() ; i++) {
135
				Element subcorpusElem = (Element) subcorpusElems.item(i);
136
				try {
137
					Subcorpus subcorp = new Subcorpus(this);
138
					subcorp._load(subcorpusElem);
139
				} catch (Exception ex) {
140
					Log.warning(this.pID + TXMCoreMessages.failedToRestoreSubcorpus + subcorpusElem.getAttribute("name")
141
					+ " : " + ex); //$NON-NLS-1$
175 142
				}
176
				else {
177
					int[] match = cqiClient.dumpSubCorpus(getQualifiedCqpId(), NetCqiClient.CQI_CONST_FIELD_MATCH, 0, nMatch - 1);
178
					int[] matchend = cqiClient.dumpSubCorpus(getQualifiedCqpId(), NetCqiClient.CQI_CONST_FIELD_MATCHEND, 0, nMatch - 1);
179
					if (match.length != matchend.length) {
180
						throw new UnexpectedAnswerException();
181
					}
182
					this.size = 0;
143
			}
183 144

  
184
					for (int i = 0; i < match.length; i++) {
185
						size += matchend[i] - match[i] + 1;
186
					}
145
			NodeList partitionElems = e.getElementsByTagName("partition"); //$NON-NLS-1$
146
			for (int i = 0 ; i < partitionElems.getLength() ; i++) {
147
				Element partitionElem = (Element) partitionElems.item(i);
148
				String name = partitionElem.getAttribute("name"); //$NON-NLS-1$
149
				List<String> names = new ArrayList<String>();
150
				List<String> queries = new ArrayList<String>();
151

  
152
				NodeList partElems = partitionElem.getElementsByTagName("part"); //$NON-NLS-1$
153
				for (int j = 0; j < partElems.getLength(); j++) {
154
					Element part = (Element) partElems.item(j);
155
					names.add(part.getAttribute("name")); //$NON-NLS-1$
156
					queries.add(part.getAttribute("query")); //$NON-NLS-1$
187 157
				}
188
			} catch (Exception e) {
189
				throw new CqiClientException(e);
158
				try {
159
					//System.out.println("Create Partition with corpus "+this+" : "+name+", queries "+queries+", names "+names);
160
					Partition partition = new Partition(this);
161
					partition.setParameters(name, queries, names);
162
					//partition.setSelfElement(partitionElem);
163
					partition._load(partitionElem);
164
				} catch (Exception ex) {
165
					Log.warning(this.pID + TXMCoreMessages.failedToRestorePartition + name
166
							+ " : " + ex); //$NON-NLS-1$
167
					//c.getParentNode().removeChild(c);
168
				}
190 169
			}
191
			long end = System.currentTimeMillis();
192
			Log.finest(NLS.bind(SearchEngineCoreMessages.sizeOfSubcorpusP0P1ComputedInP2Ms, new Object[]{this.pID, this.size, (end - start)}));
193 170
		}
194
		return this.size;
171
		initSelectionResult(e);
172
		//System.out.println("Subcorpus.load: Selection of "+this+" = "+selectionResult);
173
		//return super.load();
174
		return true;
195 175
	}
196 176

  
177
	@Override
178
	public boolean canCompute() {
179
		return pID != null && userName != null && (pQuery != null || qresult != null);
180
	}
181
	
197 182
	/*
198 183
	 * (non-Javadoc)
199 184
	 * 
200 185
	 * @see
201
	 * org.txm.searchengine.cqp.corpus.CqpObject#getQualifiedCqpId()
186
	 * org.txm.searchengine.cqp.corpus.CqpObject#checkCqpId(java.lang
187
	 * .String)
202 188
	 */
203 189
	@Override
204
	public String getQualifiedCqpId() {
205
		return getMainCorpus().getCqpId() + ":" + this.pID; //$NON-NLS-1$
190
	public boolean checkCqpId(String pID) throws InvalidCqpIdException {
191
		if (!AbstractCqiClient.checkSubcorpusId(pID))
192
			throw new InvalidCqpIdException(TXMCoreMessages.bind(CQPSearchEngineCoreMessages.p0IsNotAValidCQPIDForASubcorpusItMustBeAnUppercaseCharacterFollowedByLowercaseCharacters, pID));
193
		return true;
206 194
	}
207 195

  
208
	/*
209
	 * (non-Javadoc)
210
	 * 
211
	 * @see org.txm.searchengine.cqp.corpus.Corpus#getProperties()
212
	 */
213 196
	@Override
214
	public List<WordProperty> getProperties() throws CqiClientException {
215
		return getMainCorpus().getProperties();
197
	public void clean() {
198
		super.clean();
199
		
200
		// nothing to do if the corpus has not yet been computed
201
		if(this.hasBeenComputedOnce) {
202
			try {
203
				AbstractCqiClient CQI = CorpusManager.getCorpusManager().getCqiClient();
204
				if (CQPSearchEngine.isInitialized()) {
205
					CQI.dropSubCorpus(this.getQualifiedCqpId());
206
				}
207
			}
208
			catch (Exception e) {
209
				Log.severe(e.getLocalizedMessage());
210
				Log.severe(TXMCoreMessages.bind("Qualified CQP id: {0}.", this.getQualifiedCqpId()));
211
				Log.printStackTrace(e);
212
			}
213
		}
214
		
215
		qresult = null;
216
		selectionResult = null;
216 217
	}
217 218

  
218
	/*
219
	 * (non-Javadoc)
220
	 * 
221
	 * @see
222
	 * org.txm.searchengine.cqp.corpus.Corpus#getProperty(java.lang.
223
	 * String)
224
	 */
225 219
	@Override
226
	public WordProperty getProperty(String name) throws CqiClientException {
227
		return getMainCorpus().getProperty(name);
220
	public String getDetails() {
221
		try {
222
			return "T "+this.getSize();
223
		} catch (CqiClientException e) {
224
			return this.getName()+ " (" + this.getQualifiedCqpId()+")";
225
		}
228 226
	}
229 227

  
230
	/*
231
	 * (non-Javadoc)
232
	 * 
233
	 * @see org.txm.searchengine.cqp.corpus.Corpus#getStructuralUnits()
234
	 */
235 228
	@Override
236
	public List<StructuralUnit> getStructuralUnits() throws CqiClientException {
237
		return getMainCorpus().getStructuralUnits();
229
	public List<Match> getMatches() {
230
		try {
231
			return qresult.getMatches();
232
		} catch (CqiClientException e) {
233
			// TODO Auto-generated catch block
234
			org.txm.utils.logger.Log.printStackTrace(e);
235
			return new ArrayList<Match>();
236
		}
238 237
	}
239 238

  
239
	public int getNMatch() {
240
		try {
241
			return qresult.getNMatch();
242
		} catch (CqiClientException e) {
243
			// TODO Auto-generated catch block
244
			org.txm.utils.logger.Log.printStackTrace(e);
245
			return 0;
246
		}
247
	}
248

  
240 249
	/*
241 250
	 * (non-Javadoc)
242 251
	 * 
243
	 * @see
244
	 * org.txm.searchengine.cqp.corpus.Corpus#getStructuralUnit(java
245
	 * .lang.String)
252
	 * @see org.txm.searchengine.cqp.corpus.Corpus#getProperties()
246 253
	 */
247 254
	@Override
248
	public StructuralUnit getStructuralUnit(String name)
249
			throws CqiClientException {
250
		return getMainCorpus().getStructuralUnit(name);
255
	public List<WordProperty> getProperties() throws CqiClientException {
256
		return getMainCorpus().getProperties();
251 257
	}
252 258

  
253 259
	/*
254 260
	 * (non-Javadoc)
255 261
	 * 
256 262
	 * @see
257
	 * org.txm.searchengine.cqp.corpus.CqpObject#checkCqpId(java.lang
258
	 * .String)
263
	 * org.txm.searchengine.cqp.corpus.Corpus#getProperty(java.lang.
264
	 * String)
259 265
	 */
260 266
	@Override
261
	public boolean checkCqpId(String pID) throws InvalidCqpIdException {
262
		if (!AbstractCqiClient.checkSubcorpusId(pID))
263
			throw new InvalidCqpIdException(TXMCoreMessages.bind(CQPSearchEngineCoreMessages.p0IsNotAValidCQPIDForASubcorpusItMustBeAnUppercaseCharacterFollowedByLowercaseCharacters, pID));
264
		return true;
267
	public WordProperty getProperty(String name) throws CqiClientException {
268
		return getMainCorpus().getProperty(name);
265 269
	}
266 270

  
267 271
	// protected void finalize() throws Throwable {
......
280 284
	// }
281 285

  
282 286
	/*
283
	 * retro compatability method for import.xml file
287
	 * (non-Javadoc)
284 288
	 * 
285
	 * @see org.txm.searchengine.cqp.corpus.Corpus#getLocale()
289
	 * @see
290
	 * org.txm.searchengine.cqp.corpus.CqpObject#getQualifiedCqpId()
286 291
	 */
287 292
	@Override
288
	protected boolean _load(Element e) {
289
		if (e != null) {
290
			this.userName = e.getAttribute(NAME);
291
			this.pID = "S"+getNextSubcorpusCounter();
292
			this.pQuery = new CQLQuery(e.getAttribute("query")); //$NON-NLS-1$
293

  
294
			NodeList subcorpusElems = e.getElementsByTagName("subcorpus"); //$NON-NLS-1$
295
			for (int i = 0 ; i < subcorpusElems.getLength() ; i++) {
296
				Element subcorpusElem = (Element) subcorpusElems.item(i);
297
				try {
298
					Subcorpus subcorp = new Subcorpus(this);
299
					subcorp._load(subcorpusElem);
300
				} catch (Exception ex) {
301
					Log.warning(this.pID + TXMCoreMessages.failedToRestoreSubcorpus + subcorpusElem.getAttribute("name")
302
					+ " : " + ex); //$NON-NLS-1$
303
				}
304
			}
305

  
306
			NodeList partitionElems = e.getElementsByTagName("partition"); //$NON-NLS-1$
307
			for (int i = 0 ; i < partitionElems.getLength() ; i++) {
308
				Element partitionElem = (Element) partitionElems.item(i);
309
				String name = partitionElem.getAttribute("name"); //$NON-NLS-1$
310
				List<String> names = new ArrayList<String>();
311
				List<String> queries = new ArrayList<String>();
312

  
313
				NodeList partElems = partitionElem.getElementsByTagName("part"); //$NON-NLS-1$
314
				for (int j = 0; j < partElems.getLength(); j++) {
315
					Element part = (Element) partElems.item(j);
316
					names.add(part.getAttribute("name")); //$NON-NLS-1$
317
					queries.add(part.getAttribute("query")); //$NON-NLS-1$
318
				}
319
				try {
320
					//System.out.println("Create Partition with corpus "+this+" : "+name+", queries "+queries+", names "+names);
321
					Partition partition = new Partition(this);
322
					partition.setParameters(name, queries, names);
323
					//partition.setSelfElement(partitionElem);
324
					partition._load(partitionElem);
325
				} catch (Exception ex) {
326
					Log.warning(this.pID + TXMCoreMessages.failedToRestorePartition + name
327
							+ " : " + ex); //$NON-NLS-1$
328
					//c.getParentNode().removeChild(c);
329
				}
330
			}
331
		}
332
		initSelectionResult(e);
333
		//System.out.println("Subcorpus.load: Selection of "+this+" = "+selectionResult);
334
		//return super.load();
335
		return true;
293
	public String getQualifiedCqpId() {
294
		return getMainCorpus().getCqpId() + ":" + this.pID; //$NON-NLS-1$
336 295
	}
337 296

  
338 297
	//	/**
......
377 336
		return pQuery;
378 337
	}
379 338

  
380
	/* (non-Javadoc)
381
	 * @see java.lang.Object#toString()
382
	 */
383 339
	@Override
384
	public String toString() {
385
		return this.getName();
340
	public String getResultType() {
341
		return "Corpus";
386 342
	}
387 343

  
388
	//TODO merge SelectionResult and Subcorpus ?
389
	public void setSelectionResult(SelectionResult selectionResult) {
390
		this.selectionResult = selectionResult;
391
		//TODO persists the selectionResult ?
392
		//		if (this.getSelfElement() != null) {
393
		//			//remove old node if any
394
		//			NodeList selectionList = getSelfElement().getElementsByTagName("selection"); //$NON-NLS-1$
395
		//			for (int i = 0 ; i < selectionList.getLength() ; i++)
396
		//				getSelfElement().removeChild(selectionList.item(i));
397
		//
398
		//			Document doc = this.getParent().getSelfElement().getOwnerDocument();
399
		//			Element selectionElem = doc.createElement("selection"); // the selection element //$NON-NLS-1$
400
		//			for (String txt : selectionResult) // the text ids
401
		//			{
402
		//				Element textElem = doc.createElement("selText"); //$NON-NLS-1$
403
		//				textElem.setAttribute("id", txt); //$NON-NLS-1$
404
		//				selectionElem.appendChild(textElem);
405
		//			}
406
		//			for (String crit : selectionResult.critera.keySet()) // the critera
407
		//			{
408
		//				ArrayList<String> values = selectionResult.critera.get(crit);
409
		//				for (String value : values) {
410
		//					Element criteraElem = doc.createElement("selCrit"); //$NON-NLS-1$
411
		//					criteraElem.setAttribute("id", crit); //$NON-NLS-1$
412
		//					criteraElem.setAttribute("value", value); //$NON-NLS-1$
413
		//					selectionElem.appendChild(criteraElem);
414
		//				}
415
		//			}
416
		//			getSelfElement().appendChild(selectionElem);// append selection elem to self
417
		//		}
418
	}
419

  
420
	public SelectionResult initSelectionResult(Element e) {
421

  
422
		if (e != null) {
423
			selectionResult = new SelectionResult();
424
			NodeList selectionList = e.getElementsByTagName("selection"); //$NON-NLS-1$
425
			for (int i = 0 ; i < selectionList.getLength() ;) {
426
				Element selection = (Element) selectionList.item(i); // the selection element
427

  
428
				NodeList textList = selection.getElementsByTagName("selText"); // get text ids //$NON-NLS-1$
429
				for (int j = 0 ; j < textList.getLength() ; j++) {
430
					Element text = (Element) textList.item(j);
431
					selectionResult.add(text.getAttribute("id")); //$NON-NLS-1$
432
				}
433

  
434
				NodeList critList = selection.getElementsByTagName("selCrit"); // get the criteria //$NON-NLS-1$
435
				for (int j = 0 ; j < critList.getLength() ; j++) {
436
					Element crit = (Element) critList.item(j);
437
					String name = crit.getAttribute("id"); // the name of the critera //$NON-NLS-1$
438
					if (!selectionResult.critera.containsKey(name)) // create new list if new critera
439
						selectionResult.critera.put(name, new ArrayList<String>());
440
					selectionResult.critera.get(name).add(crit.getAttribute("value")); // add the value //$NON-NLS-1$
441
				}
442
				break; // process only one selection node
443
			}
444
		}
445
		return selectionResult;
446
	}
447

  
448 344
	public SelectionResult getSelectionResult() {
449 345
		return selectionResult;
450 346
	}
451 347

  
452 348
	@Override
453
	public int[] getTextEndLimits() throws CqiClientException, IOException,
454
	CqiServerError, InvalidCqpIdException {
455
		return this.getMainCorpus().getTextEndLimits();
349
	public String getSimpleName() {
350
		return this.getName();
456 351
	}
457 352

  
353
	/**
354
	 * Returns the number of occurrences in the subcorpus.
355
	 * 
356
	 * @return the size
357
	 * 
358
	 * @throws CqiClientException
359
	 *             the cqi client exception
360
	 * 
361
	 * @see org.txm.searchengine.cqp.corpus.CQPCorpus#getSize()
362
	 */
458 363
	@Override
459
	public int[] getTextStartLimits() throws CqiClientException, IOException,
460
	CqiServerError, InvalidCqpIdException {
461
		return this.getMainCorpus().getTextStartLimits();
462
	}
364
	public int getSize() throws CqiClientException {
365
		if (!hasBeenComputedOnce) return 0;
366
		
367
		if (this.size == -1) {
368
			//Log.finest(TXMCoreMessages.bind(TXMCoreMessages.SUBCORPUS_SIZE, new Object[]{this.pName, "N/A"}));
369
			long start = System.currentTimeMillis();
463 370

  
464
	@Override
465
	public List<Match> getMatches() {
466
		try {
467
			return qresult.getMatches();
468
		} catch (CqiClientException e) {
469
			// TODO Auto-generated catch block
470
			org.txm.utils.logger.Log.printStackTrace(e);
471
			return new ArrayList<Match>();
472
		}
473
	}
371
			try {
372
				AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient();
373
				String qid= this.getQualifiedCqpId();
374
				int nMatch = cqiClient.subCorpusSize(qid);
375
				//System.out.println("n matchs: "+nMatch);
376
				if (nMatch == 0) {
377
					this.size = 0;
378
				}
379
				else {
380
					int[] match = cqiClient.dumpSubCorpus(getQualifiedCqpId(), NetCqiClient.CQI_CONST_FIELD_MATCH, 0, nMatch - 1);
381
					int[] matchend = cqiClient.dumpSubCorpus(getQualifiedCqpId(), NetCqiClient.CQI_CONST_FIELD_MATCHEND, 0, nMatch - 1);
382
					if (match.length != matchend.length) {
383
						throw new UnexpectedAnswerException();
384
					}
385
					this.size = 0;
474 386

  
475
	public int getNMatch() {
476
		try {
477
			return qresult.getNMatch();
478
		} catch (CqiClientException e) {
479
			// TODO Auto-generated catch block
480
			org.txm.utils.logger.Log.printStackTrace(e);
481
			return 0;
387
					for (int i = 0; i < match.length; i++) {
388
						size += matchend[i] - match[i] + 1;
389
					}
390
				}
391
			} catch (Exception e) {
392
				throw new CqiClientException(e);
393
			}
394
			long end = System.currentTimeMillis();
395
			Log.finest(NLS.bind(SearchEngineCoreMessages.sizeOfSubcorpusP0P1ComputedInP2Ms, new Object[]{this.pID, this.size, (end - start)}));
482 396
		}
397
		return this.size;
483 398
	}
484 399

  
485 400
	@Override
......
488 403
		return this.getMainCorpus().getStartLimits(sup);
489 404
	}
490 405

  
406
	/*
407
	 * (non-Javadoc)
408
	 * 
409
	 * @see
410
	 * org.txm.searchengine.cqp.corpus.Corpus#getStructuralUnit(java
411
	 * .lang.String)
412
	 */
491 413
	@Override
492
	public String getSimpleName() {
493
		return this.getName();
414
	public StructuralUnit getStructuralUnit(String name)
415
			throws CqiClientException {
416
		return getMainCorpus().getStructuralUnit(name);
494 417
	}
495 418

  
419
	/*
420
	 * (non-Javadoc)
421
	 * 
422
	 * @see org.txm.searchengine.cqp.corpus.Corpus#getStructuralUnits()
423
	 */
496 424
	@Override
497
	public String getDetails() {
498
		try {
499
			return "T "+this.getSize();
500
		} catch (CqiClientException e) {
501
			return this.getName()+ " (" + this.getQualifiedCqpId()+")";
502
		}
425
	public List<StructuralUnit> getStructuralUnits() throws CqiClientException {
426
		return getMainCorpus().getStructuralUnits();
503 427
	}
504 428

  
505 429
	@Override
506
	public void clean() {
507
		super.clean();
508
		
509
		// nothing to do if the corpus has not yet been computed
510
		if(this.hasBeenComputedOnce) {
511
			try {
512
				AbstractCqiClient CQI = CorpusManager.getCorpusManager().getCqiClient();
513
				if (CQPSearchEngine.isInitialized()) {
514
					CQI.dropSubCorpus(this.getQualifiedCqpId());
515
				}
516
			}
517
			catch (Exception e) {
518
				Log.severe(e.getLocalizedMessage());
519
				Log.severe(TXMCoreMessages.bind("Qualified CQP id: {0}.", this.getQualifiedCqpId()));
520
				Log.printStackTrace(e);
521
			}
522
		}
430
	public int[] getTextEndLimits() throws CqiClientException, IOException,
431
	CqiServerError, InvalidCqpIdException {
432
		return this.getMainCorpus().getTextEndLimits();
523 433
	}
524 434

  
525 435
	@Override
526
	public boolean canCompute() {
527
		return pID != null && userName != null && (pQuery != null || qresult != null);
436
	public int[] getTextStartLimits() throws CqiClientException, IOException,
437
	CqiServerError, InvalidCqpIdException {
438
		return this.getMainCorpus().getTextStartLimits();
528 439
	}
529 440

  
530
	@Override
531
	public boolean setParameters(TXMParameters parameters) {
532
		// TODO Auto-generated method stub
533
		System.err.println("Subcorpus.setParameters(): not yet implemented.");
534
		return true;
535
	}
441
	public SelectionResult initSelectionResult(Element e) {
536 442

  
537
	@Override
538
	public boolean saveParameters() throws Exception {
539
		if (pQuery != null) {
540
			this.saveParameter(TBXPreferences.QUERY, pQuery.getQueryString());
443
		if (e != null) {
444
			selectionResult = new SelectionResult();
445
			NodeList selectionList = e.getElementsByTagName("selection"); //$NON-NLS-1$
446
			for (int i = 0 ; i < selectionList.getLength() ;) {
447
				Element selection = (Element) selectionList.item(i); // the selection element
448

  
449
				NodeList textList = selection.getElementsByTagName("selText"); // get text ids //$NON-NLS-1$
450
				for (int j = 0 ; j < textList.getLength() ; j++) {
451
					Element text = (Element) textList.item(j);
452
					selectionResult.add(text.getAttribute("id")); //$NON-NLS-1$
453
				}
454

  
455
				NodeList critList = selection.getElementsByTagName("selCrit"); // get the criteria //$NON-NLS-1$
456
				for (int j = 0 ; j < critList.getLength() ; j++) {
457
					Element crit = (Element) critList.item(j);
458
					String name = crit.getAttribute("id"); // the name of the critera //$NON-NLS-1$
459
					if (!selectionResult.critera.containsKey(name)) // create new list if new critera
460
						selectionResult.critera.put(name, new ArrayList<String>());
461
					selectionResult.critera.get(name).add(crit.getAttribute("value")); // add the value //$NON-NLS-1$
462
				}
463
				break; // process only one selection node
464
			}
541 465
		}
542
		return true;
466
		return selectionResult;
543 467
	}
544 468

  
545 469
	@Override
......
552 476
		return true;
553 477
	}
554 478

  
555

  
556 479
	@Override
557
	@Deprecated
558
	public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception {
559
		return false;
480
	public boolean saveParameters() throws Exception {
481
		if (pQuery != null) {
482
			this.saveParameter(TBXPreferences.QUERY, pQuery.getQueryString());
483
		}
484
		return true;
560 485
	}
561 486

  
562
	@Override
563
	public String getResultType() {
564
		return "Corpus";
487
	/**
488
	 * Instantiates a new subcorpus.
489
	 * 
490
	 * Not intended to be used directly.
491
	 *
492
	 * @param pID the cqp id
493
	 * @param name the name
494
	 * @param parent the parent
495
	 * @param query the query
496
	 * @throws InvalidCqpIdException the invalid cqp id exception
497
	 * {@link CQPCorpus#createSubcorpus(CQLQuery, String)}
498
	 */
499
	protected void setParameters(String pID, String name, CQLQuery query) throws InvalidCqpIdException {
500
		this.pID = pID;
501
		this.pQuery = query;
502
		this.userName = name;
565 503
	}
566 504

  
567 505
	/**
......
578 516

  
579 517
		this.dirty = false;
580 518
	}
519

  
520
	@Override
521
	public boolean setParameters(TXMParameters parameters) {
522
		// TODO Auto-generated method stub
523
		System.err.println("Subcorpus.setParameters(): not yet implemented.");
524
		return true;
525
	}
526

  
527
	/**
528
	 * Sets the query to use.
529
	 * @param query
530
	 */
531
	public void setQuery(CQLQuery query) {
532
		this.pQuery = query;
533
	}
534

  
535

  
536
	//TODO merge SelectionResult and Subcorpus ?
537
	public void setSelectionResult(SelectionResult selectionResult) {
538
		this.selectionResult = selectionResult;
539
		//TODO persists the selectionResult ?
540
		//		if (this.getSelfElement() != null) {
541
		//			//remove old node if any
542
		//			NodeList selectionList = getSelfElement().getElementsByTagName("selection"); //$NON-NLS-1$
543
		//			for (int i = 0 ; i < selectionList.getLength() ; i++)
544
		//				getSelfElement().removeChild(selectionList.item(i));
545
		//
546
		//			Document doc = this.getParent().getSelfElement().getOwnerDocument();
547
		//			Element selectionElem = doc.createElement("selection"); // the selection element //$NON-NLS-1$
548
		//			for (String txt : selectionResult) // the text ids
549
		//			{
550
		//				Element textElem = doc.createElement("selText"); //$NON-NLS-1$
551
		//				textElem.setAttribute("id", txt); //$NON-NLS-1$
552
		//				selectionElem.appendChild(textElem);
553
		//			}
554
		//			for (String crit : selectionResult.critera.keySet()) // the critera
555
		//			{
556
		//				ArrayList<String> values = selectionResult.critera.get(crit);
557
		//				for (String value : values) {
558
		//					Element criteraElem = doc.createElement("selCrit"); //$NON-NLS-1$
559
		//					criteraElem.setAttribute("id", crit); //$NON-NLS-1$
560
		//					criteraElem.setAttribute("value", value); //$NON-NLS-1$
561
		//					selectionElem.appendChild(criteraElem);
562
		//				}
563
		//			}
564
		//			getSelfElement().appendChild(selectionElem);// append selection elem to self
565
		//		}
566
	}
567

  
568
	/* (non-Javadoc)
569
	 * @see java.lang.Object#toString()
570
	 */
571
	@Override
572
	public String toString() {
573
		return this.getName();
574
	}
575

  
576
	@Override
577
	@Deprecated
578
	public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception {
579
		return false;
580
	}
581 581
}
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/CQPCorpus.java (revision 1804)
2 2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3 3
// Lyon 2, University of Franche-Comté, University of Nice
4 4
// Sophia Antipolis, University of Paris 3.
5
// 
5
//
6 6
// The TXM platform is free software: you can redistribute it
7 7
// and/or modify it under the terms of the GNU General Public
8 8
// License as published by the Free Software Foundation,
9 9
// either version 2 of the License, or (at your option) any
10 10
// later version.
11
// 
11
//
12 12
// The TXM platform is distributed in the hope that it will be
13 13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14 14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 15
// PURPOSE. See the GNU General Public License for more
16 16
// details.
17
// 
17
//
18 18
// You should have received a copy of the GNU General
19 19
// Public License along with the TXM platform. If not, see
20 20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
21
//
22
//
23
//
24 24
// $LastChangedDate: 2016-11-29 16:47:07 +0100 (Tue, 29 Nov 2016) $
25 25
// $LastChangedRevision: 3349 $
26
// $LastChangedBy: mdecorde $ 
26
// $LastChangedBy: mdecorde $
27 27
//
28 28
package org.txm.searchengine.cqp.corpus;
29 29

  
......
57 57
import org.w3c.dom.NodeList;
58 58

  
59 59
/**
60
 * The Class Corpus. A corpus is either a whole corpus, as managed by CQP or a subcorpus.
60
 * The Class Corpus. A corpus is either a whole corpus, as managed by CQP or a
61
 * subcorpus.
61 62
 * 
62 63
 * @see org.txm.searchengine.cqp.corpus.MainCorpus
63 64
 * @see org.txm.searchengine.cqp.corpus.Subcorpus
......
66 67
 */
67 68
public abstract class CQPCorpus extends org.txm.objects.CorpusBuild implements CqpObject {
68 69

  
70
	protected static HashMap<Class<?>, ArrayList<?>> cache = new HashMap<Class<?>, ArrayList<?>>();
71

  
72
	private static final int CACHE_MAXIMUM_SIZE = 5;
73

  
74
	/** The nocorpus. */
75
	protected static int nocorpus = 1;
76

  
77
	/** The prefix r. */
78
	protected static String prefixR = "Corpus"; //$NON-NLS-1$
79
	private static Integer QUERY_COUNTER = new Integer(0);
80
	protected static Integer SUBCORPUS_COUNTER = new Integer(0);
81
	protected static String WORD = TXMPreferences.DEFAULT_UNIT_PROPERTY;
82

  
83
	public static final Comparator<WordProperty> wordFirstComparator = new Comparator<WordProperty>() {
84
		@Override
85
		public int compare(WordProperty o1, WordProperty o2) {
86
			if (o1.getName().equals("word"))
87
				return -1;
88
			if (o2.getName().equals("word"))
89
				return 1;
90
			return o1.compareTo(o2);
91
		}
92
	};
93

  
69 94
	/**
95
	 * store an object for a maximum of 5 object cached per object
70 96
	 * 
71
	 * @param project
97
	 * @param forObject
98
	 * @param toCache
99
	 * @return
72 100
	 */
73
	protected CQPCorpus(Project project) {
74
		super(project);
101
	public static Object cache(Object toCache) {
102
		if (toCache == null)
103
			return null;
104

  
105
		ArrayList<?> ocCache = getObjectCacheForClass(toCache.getClass());
106
		if (ocCache.size() > CACHE_MAXIMUM_SIZE) {
107
			ocCache.remove(0); // oldest value
108
		}
109
		return toCache;
75 110
	}
76
	
111

  
77 112
	/**
113
	 * Returns the first parent object that is a Subcorpus, a Corpus or a
114
	 * MainCorpus. Returns the object itself if its class is one of the the three
115
	 * listed below.
78 116
	 * 
79
	 * @param corpus
117
	 * @return
80 118
	 */
81
	public CQPCorpus(CQPCorpus corpus) {
82
		super(corpus);
119
	synchronized public static CQPCorpus getFirstParentCorpus(TXMResult result) {
120
		CQPCorpus corpus = (CQPCorpus) result.getFirstParent(Subcorpus.class);
121
		if (corpus == null) {
122
			corpus = (CQPCorpus) result.getFirstParent(CQPCorpus.class);
123
		}
124
		if (corpus == null) {
125
			corpus = (CQPCorpus) getParentMainCorpus(result);
126
		}
127
		return corpus;
83 128
	}
84
	
129
	public static String getNextQueryCounter() {
130
		QUERY_COUNTER++;
131
		return QUERY_COUNTER.toString();
132
	}
133
	public static String getNextSubcorpusCounter() {
134
		SUBCORPUS_COUNTER++;
135
		return SUBCORPUS_COUNTER.toString();
136
	}
137

  
85 138
	/**
139
	 * retrieve all cached objects for an object
86 140
	 * 
87
	 * @param partition
141
	 * @param forObject
142
	 * @param c
143
	 * @return
88 144
	 */
89
	public CQPCorpus(Partition partition) {
90
		super(partition);
145
	public static HashMap<Class<?>, ArrayList<?>> getObjectCache() {
146
		return cache;
91 147
	}
92
	
148

  
93 149
	/**
94
	 * Empty the corpus cache
150
	 * retrieve all cached objects of a certain class for an object
151
	 * 
152
	 * @param forObject
153
	 * @param c
154
	 * @return
95 155
	 */
96
	@Override
97
	public void clean() {
98
		if (cache != null) {
99
			cache.clear();
156
	public static ArrayList<?> getObjectCacheForClass(Class<?> c) {
157
		HashMap<Class<?>, ArrayList<?>> oCache = getObjectCache();
158
		if (!oCache.containsKey(c)) {
159
			oCache.put(c, new ArrayList<Object>());
100 160
		}
161
		return oCache.get(c);
101 162
	}
102
	
163

  
103 164
	/**
104
	 * recursive method to clone a result
165
	 * Gets the main corpus parent.
105 166
	 * 
106
	 * @param newParent
107
	 *            necessary for cloning children in the right clone parent
108
	 * @param all
109
	 * @return
167
	 * @return the first parent of class MainCorpus or the object itself if it is
168
	 *         its class.
110 169
	 */
111
	protected TXMResult clone(TXMResult newParent, boolean all) {
112
		CQPCorpus c = (CQPCorpus) super.clone(newParent, all);
113
		c.pID = "S"+getNextSubcorpusCounter();
114
		return c;
170
	synchronized public static TXMResult getParentMainCorpus(TXMResult result) {
171
		return result.getFirstParent(MainCorpus.class);
115 172
	}
116 173

  
117 174
	/**
175
	 * remove a cached object
118 176
	 * 
119
	 * @param parametersNodePath
177
	 * @param forObject
178
	 * @param toCache
179
	 * @return
120 180
	 */
121
	public CQPCorpus(String parametersNodePath) {
122
		super(parametersNodePath);
181
	public static ArrayList<?> uncache(Class classToUnCache) {
182
		if (classToUnCache == null)
183
			return null;
184

  
185
		return cache.remove(classToUnCache);
123 186
	}
124 187

  
125
	
126
	public static String getNextQueryCounter() {
127
		QUERY_COUNTER++;
128
		return QUERY_COUNTER.toString();
188
	/**
189
	 * remove a cached object
190
	 * 
191
	 * @param forObject
192
	 * @param toCache
193
	 * @return
194
	 */
195
	public static boolean uncache(Object toUnCache) {
196
		if (toUnCache == null)
197
			return false;
198

  
199
		ArrayList<?> ocCache = getObjectCacheForClass(toUnCache.getClass());
200
		return ocCache.remove(toUnCache);
129 201
	}
130
	public static String getNextSubcorpusCounter() {
131
		SUBCORPUS_COUNTER++;
132
		return SUBCORPUS_COUNTER.toString();
133
	}
134 202

  
203
	/** All private infos of the corpus. */
204
	protected String charset = "latin1"; //$NON-NLS-1$
205

  
206
	/**
207
	 * Gets the locale of the corpus.
208
	 * 
209
	 * @return the locale
210
	 */
211
	protected String lang = null;
212

  
213
	/** The language. */
214
	protected String language = "???"; //$NON-NLS-1$
215

  
216
	/** The corpus lexical units properties. */
217
	protected List<WordProperty> lexicalUnitsProperties;
218

  
135 219
	/** The size. */
136 220
	protected int size = -1;
137 221

  
222
	// /**
223
	// * Creates a new object mapping a CQP corpus. This constructor is not
224
	// * intended to be used directly. Use {@link CorpusManager#getCorpus(String)}
225
	// * .
226
	// *
227
	// * @param pID
228
	// * the id of the cqp corpus
229
	// *
230
	// * @throws InvalidCqpIdException
231
	// * the invalid cqp id exception
232
	// */
233
	// protected Corpus(Corpus parentCorpus) throws InvalidCqpIdException {
234
	// super(parentCorpus);
235
	// if (parentCorpus ins)
236
	//// checkCqpId(pID);
237
	//// this.pID = pID;
238
	////
239
	//// // FIXME: at this moment, store the CQPID as UUIDD for persistence tests
240
	//// this.uniqueID = this.pID;
241
	// }
242
	//
243
	// /**
244
	// * Creates a new object mapping a CQP corpus. This constructor is not
245
	// * intended to be used directly. Use {@link CorpusManager#getCorpus(String)}
246
	// * .
247
	// *
248
	// * @param pID
249
	// * the id of the cqp corpus
250
	// *
251
	// * @throws InvalidCqpIdException
252
	// * the invalid cqp id exception
253
	// */
254
	// protected Corpus(Corpus parentCorpus) throws InvalidCqpIdException {
255
	// super(null, null, pID);
256
	//// checkCqpId(pID);
257
	//// this.pID = pID;
258
	////
259
	//// // FIXME: at this moment, store the CQPID as UUIDD for persistence tests
260
	//// this.uniqueID = this.pID;
261
	// }
262

  
138 263
	/** The corpus structural units. */
139 264
	protected List<StructuralUnit> structuralUnits;
140 265

  
141
	/** The corpus lexical units properties. */
142
	protected List<WordProperty> lexicalUnitsProperties;
266
	/** The symbol. */
267
	protected String symbol;
143 268

  
269
	protected StructuralUnitProperty textIdStructuralUnitProperty;
270
	// public HashSet<Object> getStoredData(Class class1) {
271
	//
272
	// if (!storedData.containsKey(class1)) {
273
	// storedData.put(class1, new HashSet<Object>());
274
	// }
275
	//
276
	// return storedData.get(class1);
277
	// }
278
	//
279
	// /**
280
	// * TODO: fix this hack to store Lexicons
281
	// *
282
	// * @param o a lexicon
283
	// */
284
	// public void storeData(Object o) {
285
	// if (storedData.containsKey(o.getClass())) {
286
	// storedData.put(o.getClass(), new HashSet<Object>());
287
	// }
288
	//
289
	// HashSet<Object> hash = storedData.get(o.getClass());
290
	// hash.add(o);
291
	// }
292

  
144 293
	protected int[] textLimits;
145 294

  
146
	/** All private infos of the corpus. */
147
	private String charset = "latin1"; //$NON-NLS-1$
295
	protected StructuralUnit textStructuralUnit;
148 296

  
149
	/** The language. */
150
	private String language = "???"; //$NON-NLS-1$
151
	
297
	protected WordProperty wordProperty = null;
298

  
152 299
	/**
153
	 * Gets the locale of the corpus.
154 300
	 * 
155
	 * @return the locale
301
	 * @param corpus
156 302
	 */
157
	String lang = null;
303
	public CQPCorpus(CQPCorpus corpus) {
304
		super(corpus);
305
	}
158 306

  
159
	/** The nocorpus. */
160
	protected static int nocorpus = 1;
307
	/**
308
	 * 
309
	 * @param partition
310
	 */
311
	public CQPCorpus(Partition partition) {
312
		super(partition);
313
	}
161 314

  
162
	/** The prefix r. */
163
	protected static String prefixR = "Corpus"; //$NON-NLS-1$
315
	/**
316
	 * 
317
	 * @param project
318
	 */
319
	protected CQPCorpus(Project project) {
320
		super(project);
321
	}
164 322

  
165
	/** The symbol. */
166
	private String symbol;
323
	// /**
324
	// * Drop all the partitions.
325
	// *
326
	// * @throws CqiClientException
327
	// * the cqi client exception
328
	// */
329
	// public void dropAllPartitions() throws CqiClientException {
330
	// List<Partition> _partitions = (List<Partition>) getChildren(Partition.class);
331
	// for (Partition partition : _partitions) {
332
	// this.dropPartition(partition);
333
	// }
334
	// _partitions = null;
335
	// }
167 336

  
168
	protected static String WORD = TXMPreferences.DEFAULT_UNIT_PROPERTY;
337
	/**
338
	 * 
339
	 * @param parametersNodePath
340
	 */
341
	public CQPCorpus(String parametersNodePath) {
342
		super(parametersNodePath);
343
	}
169 344

  
170
	protected WordProperty wordProperty = null;
345
	// /**
346
	// * Drops a partition.
347
	// *
348
	// * @param partition
349
	// * the partition
350
	// *
351
	// * @throws CqiClientException
352
	// * the cqi client exception
353
	// */
354
	// public void dropPartition(Partition partition) throws CqiClientException {
355
	// Log.finest(SearchEngineCoreMessages.info_deletingPartition +
356
	// partition.getName());
357
	// for (Part part : partition.getParts())
358
	// try {
359
	// CorpusManager.getCorpusManager().getCqiClient().dropSubCorpus(part.getQualifiedCqpId());
360
	// } catch (Exception e) {
361
	// throw new CqiClientException(e);
362
	// }
363
	// }
171 364

  
172
	protected static Integer SUBCORPUS_COUNTER = new Integer(0);
365
	/*
366
	 * (non-Javadoc)
367
	 * 
368
	 * @see org.txm.objects.TxmObject#load()
369
	 */
370
	protected boolean _load(Element e) {
371
		// System.out.println("*** Load corpus: "+name);
372
		if (e == null) {
373
			Log.warning(TXMCoreMessages.warningColonCantLoadCorpus + this);
374
			Log.warning(TXMCoreMessages.informationsFromWorkspaceSelfElementNull);
375
			return false;
376
		}
173 377

  
174
	private static Integer QUERY_COUNTER = new Integer(0);
378
		// 1- texts queries then
379
		// 2- get metadatas, pattributes, sattributes, editions, biblios, uis,
380
		super._load(e);
381
		// System.out.println("Load corpus : "+this.name);
382
		// this.loadMetadata(); // read <prop>s
175 383

  
176
//	/**
177
//	 * Creates a new object mapping a CQP corpus. This constructor is not
178
//	 * intended to be used directly. Use {@link CorpusManager#getCorpus(String)}
179
//	 * .
180
//	 * 
181
//	 * @param pID
182
//	 *            the id of the cqp corpus
183
//	 * 
184
//	 * @throws InvalidCqpIdException
185
//	 *             the invalid cqp id exception
186
//	 */
187
//	protected Corpus(Corpus parentCorpus) throws InvalidCqpIdException {
188
//		super(parentCorpus);
189
//		if (parentCorpus ins)
190
////		checkCqpId(pID);
191
////		this.pID = pID;
192
////		
193
////		// FIXME: at this moment, store the CQPID as UUIDD for persistence tests
194
////		this.uniqueID = this.pID;
195
//	}
196
//	
197
//	/**
198
//	 * Creates a new object mapping a CQP corpus. This constructor is not
199
//	 * intended to be used directly. Use {@link CorpusManager#getCorpus(String)}
200
//	 * .
201
//	 * 
202
//	 * @param pID
203
//	 *            the id of the cqp corpus
204
//	 * 
205
//	 * @throws InvalidCqpIdException
206
//	 *             the invalid cqp id exception
207
//	 */
208
//	protected Corpus(Corpus parentCorpus) throws InvalidCqpIdException {
209
//		super(null, null, pID);
210
////		checkCqpId(pID);
211
////		this.pID = pID;
212
////		
213
////		// FIXME: at this moment, store the CQPID as UUIDD for persistence tests
214
////		this.uniqueID = this.pID;
215
//	}
216
	
384
		// 3- build saved subcorpus and partition
385
		// System.out.println("restore subcorpora: "+selfElement);
386
		NodeList preBuildElems = e.getElementsByTagName("preBuild"); //$NON-NLS-1$
387
		if (preBuildElems.getLength() > 0) {
388
			Element preBuildElem = (Element) preBuildElems.item(0);
389
			NodeList subcorpusElems = preBuildElem.getElementsByTagName("subcorpus"); //$NON-NLS-1$
390
			for (int i = 0; i < subcorpusElems.getLength(); i++) {
391
				Element subcorpusElem = (Element) subcorpusElems.item(i);
392
				if (!subcorpusElem.getParentNode().equals(preBuildElem))
393
					continue; // level 1 elements
394
				// System.out.println("subcorpus "+subcorpusElem.getAttribute("name"));
395
				// try {
396
				Subcorpus subcorp = new Subcorpus(this);
397
				subcorp._load(subcorpusElem);
398
				// subcorp.compute();
399
				// } catch (CqiClientException ex) {
400
				// Log.warning(this.pID + TXMCoreMessages.failedToRestoreSubcorpus + pID
401
				// + " : " + ex); //$NON-NLS-1$
402
				// }
403
			}
404

  
405
			NodeList partitionElems = preBuildElem.getElementsByTagName("partition"); //$NON-NLS-1$
406
			for (int i = 0; i < partitionElems.getLength(); i++) {
407
				Element partitionElem = (Element) partitionElems.item(i);
408
				if (!partitionElem.getParentNode().equals(preBuildElem))
409
					continue; // level 1 elements
410
				String name = partitionElem.getAttribute("name"); //$NON-NLS-1$
411
				List<String> names = new ArrayList<String>();
412
				List<String> queries = new ArrayList<String>();
413

  
414
				NodeList partElems = partitionElem.getElementsByTagName("part"); //$NON-NLS-1$
415
				for (int j = 0; j < partElems.getLength(); j++) {
416
					Element part = (Element) partElems.item(j);
417
					names.add(part.getAttribute("name")); //$NON-NLS-1$
418
					queries.add(part.getAttribute("query")); //$NON-NLS-1$
419
				}
420
				try {
421
					// System.out.println("Create Partition with corpus "+this+" : "+name+", queries
422
					// "+queries+", names "+names);
423
					Partition partition = new Partition(this);
424
					partition.setParameters(name, queries, names);
425

  
426
					// partition.setSelfElement(partitionElem);
427
					// partition.load();
428
					// partition.compute();
429
				} catch (Exception ex) {
430
					Log.warning(this.pID + TXMCoreMessages.failedToRestorePartition + name + " : " + ex); //$NON-NLS-1$
431
					// c.getParentNode().removeChild(c);
432
				}
433
			}
434
		}
435

  
436
		// 4- initialize JPA persistence of annotations
437
		// try {
438
		// AnnotationManager.getInstance().initTemporaryAnnotationDatabase(this);
439
		// } catch(Exception e) {
440
		// System.out.println("Fail to load annotation service: "+e);
441
		// Log.printStackTrace(e);
442
		// }
443
		//
444
		return true;
445
	}
446

  
217 447
	/**
218
	 * Creates a subcorpus using workspace definition.
219
	 *
220
	 * @param elem the XML element
221
	 * @return the subcorpus
222
	 * @throws CqiClientException the cqi client exception
448
	 * Empty the corpus cache
223 449
	 */
224
	public Subcorpus createSubcorpus(Element elem) throws CqiClientException {
225
		CQLQuery query = new CQLQuery(elem.getAttribute("query")); //$NON-NLS-1$
226
		String subcorpusName = elem.getAttribute("name"); //$NON-NLS-1$
450
	@Override
451
	public void clean() {
452
		if (cache != null) {
453
			cache.clear();
454
		}
455
		
456
		charset = "latin1"; //$NON-NLS-1$
457
		lang = null;
458
		language = "???"; //$NON-NLS-1$
459
		lexicalUnitsProperties = null;
460
		size = -1;
461
		structuralUnits = null;
462
		symbol = null;
463
		textIdStructuralUnitProperty = null;
464
		textLimits = null;
465
		textStructuralUnit = null;
466
		wordProperty = null;
467
	}
227 468

  
228
		Subcorpus subcorpus;
229
		String subcorpusCqpId = subcorpusNamePrefix	+ getNextSubcorpusCounter();
469
	/**
470
	 * recursive method to clone a result
471
	 * 
472
	 * @param newParent
473
	 *            necessary for cloning children in the right clone parent
474
	 * @param all
475
	 * @return
476
	 */
477
	protected TXMResult clone(TXMResult newParent, boolean all) {
478
		CQPCorpus c = (CQPCorpus) super.clone(newParent, all);
479
		c.pID = "S" + getNextSubcorpusCounter();
480
		return c;
481
	}
230 482

  
231
		// long start = System.currentTimeMillis();
232
		try {
233
			CorpusManager.getCorpusManager().getCqiClient().cqpQuery(this.getQualifiedCqpId(), subcorpusCqpId,
234
					query.getQueryString());
235
			subcorpus = new Subcorpus(this);
236
			subcorpus.setParameters(subcorpusCqpId, subcorpusName, query);
237
			subcorpus.compute();
238
		} catch (Exception e) {
239
			throw new CqiClientException(e);
483
	@Override
484
	public int compareTo(TXMResult o) {
485
		// Compare node weights
486
		int output = super.compareTo(o);
487
		// Compare simple names if weights are equal
488
		if (this.pID == null) {
489
			return -1;
240 490
		}
241

  
242
		return subcorpus;
491
		if (o.getSimpleName() == null)
492
			return 1;
493
		if (output == 0) {
494
			output = this.getSimpleName().compareTo(o.getSimpleName());
495
		}
496
		return output;
243 497
	}
244 498

  
245 499
	/**
......
255 509
	 * @throws CqiClientException
256 510
	 *             the cqi client exception
257 511
	 */
258
	public Subcorpus createSubcorpus(CQLQuery query, String subcorpusName)
259
			throws CqiClientException {
512
	public Subcorpus createSubcorpus(CQLQuery query, String subcorpusName) throws CqiClientException {
260 513
		Subcorpus sc = createSubcorpus(query, subcorpusName, false);
261 514
		return sc;
262 515
	}
......
264 517
	/**
265 518
	 * Creates a subcorpus and save configuration in the workspace.
266 519
	 *
267
	 * @param query the query
268
	 * @param subcorpusName the subcorpus name
269
	 * @param registered the registered
520
	 * @param query
521
	 *            the query
522
	 * @param subcorpusName
523
	 *            the subcorpus name
524
	 * @param registered
525
	 *            the registered
270 526
	 * @return the subcorpus
271
	 * @throws CqiClientException the cqi client exception
527
	 * @throws CqiClientException
528
	 *             the cqi client exception
272 529
	 */
273 530
	public Subcorpus createSubcorpus(CQLQuery query, String subcorpusName, boolean registered) throws CqiClientException {
274
		
531

  
275 532
		Subcorpus subcorpus;
276 533
		String subcorpusCqpId = subcorpusNamePrefix + getNextSubcorpusCounter().toString();
277 534
		Log.finest(TXMCoreMessages.bind(SearchEngineCoreMessages.info_creatingSubcorpusXFromCorpusYWithTheQueryZ, subcorpusName, this.getQualifiedCqpId(), query.getQueryString()));
278 535

  
279 536
		long start = System.currentTimeMillis();
280 537
		try {
281
			CorpusManager.getCorpusManager().getCqiClient().cqpQuery(
282
					this.getQualifiedCqpId(), subcorpusCqpId, query.getQueryString());
283
			//System.out.println("SUBCORPUS: "+subcorpusCqpId+" q="+query.getQueryString());
538
			CorpusManager.getCorpusManager().getCqiClient().cqpQuery(this.getQualifiedCqpId(), subcorpusCqpId, query.getQueryString());
539
			// System.out.println("SUBCORPUS: "+subcorpusCqpId+"
540
			// q="+query.getQueryString());
284 541
			subcorpus = new Subcorpus(this);
285 542
			subcorpus.setParameters(subcorpusCqpId, subcorpusName, query);
286 543
			subcorpus.compute();
......
288 545
			throw new CqiClientException(e);
289 546
		}
290 547
		long end = System.currentTimeMillis();
291
		
548

  
292 549
		Log.fine(TXMCoreMessages.bind(SearchEngineCoreMessages.subcorpusP0CreatedInP1Ms, subcorpusName, (end - start)));
293 550

  
294
//		if (!registered) subcorpus.registerToParent();
551
		// if (!registered) subcorpus.registerToParent();
295 552
		return subcorpus;
296 553
	}
297 554

  
555
	/**
556
	 * Creates a subcorpus using workspace definition.
557
	 *
558
	 * @param elem
559
	 *            the XML element
560
	 * @return the subcorpus
561
	 * @throws CqiClientException
562
	 *             the cqi client exception
563
	 */
564
	public Subcorpus createSubcorpus(Element elem) throws CqiClientException {
565
		CQLQuery query = new CQLQuery(elem.getAttribute("query")); //$NON-NLS-1$
566
		String subcorpusName = elem.getAttribute("name"); //$NON-NLS-1$
567

  
568
		Subcorpus subcorpus;
569
		String subcorpusCqpId = subcorpusNamePrefix + getNextSubcorpusCounter();
570

  
571
		// long start = System.currentTimeMillis();
572
		try {
573
			CorpusManager.getCorpusManager().getCqiClient().cqpQuery(this.getQualifiedCqpId(), subcorpusCqpId, query.getQueryString());
574
			subcorpus = new Subcorpus(this);
575
			subcorpus.setParameters(subcorpusCqpId, subcorpusName, query);
576
			subcorpus.compute();
577
		} catch (Exception e) {
578
			throw new CqiClientException(e);
579
		}
580

  
581
		return subcorpus;
582
	}
583

  
298 584
	public Subcorpus createSubcorpus(String name, QueryResult queryResult) throws Exception {
299 585
		Subcorpus sub = new Subcorpus(this);
300 586
		sub.setParameters(queryResult.getCqpId(), name, queryResult);
......
302 588
		return sub;
303 589
	}
304 590

  
305
	public Subcorpus createSubcorpus(String name, String cqpid) throws Exception {
306
		Subcorpus sub = new Subcorpus(this);
307
		sub.setParameters(cqpid, name, new QueryResult(cqpid, name, this, null));
308
		sub.compute();
309
		return sub;
310
	}
311
	
312 591
	/**
313 592
	 * Creates the subcorpus.
314 593
	 *
315
	 * @param elem the elem
594
	 * @param elem
595
	 *            the elem
316 596
	 * @return the subcorpus
317
	 * @throws CqiClientException the cqi client exception
597
	 * @throws CqiClientException
598
	 *             the cqi client exception
318 599
	 */
319 600
	public Subcorpus createSubcorpus(String name, SelectionResult selectionResult) throws CqiClientException {
320 601
		Subcorpus sub = createSubcorpus(this.getStructuralUnit("text"), this.getStructuralUnit("text").getProperty("id"), selectionResult, name); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
321 602
		sub.setSelectionResult(selectionResult);
322 603
		return sub;
323 604
	}
324
	
605

  
606
	public Subcorpus createSubcorpus(String name, String cqpid) throws Exception {
607
		Subcorpus sub = new Subcorpus(this);
608
		sub.setParameters(cqpid, name, new QueryResult(cqpid, name, this, null));
609
		sub.compute();
610
		return sub;
611
	}
612

  
325 613
	/**
326 614
	 * Creates the subcorpus.
327 615
	 *
328
	 * @param structuralUnit the structural unit
329
	 * @param structuralUnitProperty the structural unit property
330
	 * @param values the values
331
	 * @param subcorpusName the subcorpus name
616
	 * @param structuralUnit
617
	 *            the structural unit
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff