Revision 2767

tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/creationdelete partition et subcorpus.java (revision 2767)
1
//import org.eclipse.osgi.util.NLS;
2
//import org.txm.core.messages.TXMCoreMessages;
3
//import org.txm.searchengine.cqp.CQPSearchEngine;
4
//import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
5
//import org.txm.searchengine.cqp.corpus.query.Query;
6
//import org.txm.utils.logger.Log;
7
//import org.w3c.dom.Element;
8
//import org.w3c.dom.NodeList;
9

  
10
//import java.util.ArrayList;
11
//import java.util.List;
12
//
13
//import org.txm.core.messages.TXMCoreMessages;
14
//import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
15
//import org.txm.searchengine.cqp.corpus.query.Query;
16
//import org.txm.utils.logger.Log;
17
//import org.w3c.dom.Element;
18
//import org.w3c.dom.NodeList;
19

  
20
//
21
//import java.util.List;
22
//
23
//import org.eclipse.osgi.util.NLS;
24
//import org.txm.core.messages.TXMCoreMessages;
25
//import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
26
//import org.txm.searchengine.cqp.clientExceptions.InvalidCqpIdException;
27
//import org.txm.searchengine.cqp.core.functions.selection.SelectionResult;
28
//import org.txm.searchengine.cqp.corpus.query.Query;
29
//import org.txm.searchengine.cqp.corpus.query.QueryPart;
30
//import org.txm.utils.logger.Log;
31
//import org.w3c.dom.Element;
32
//
33
//
34
//
35
//	
36
//	/**
37
//	 * Creates a partition using a list of CQP queries and names each part.
38
//	 *
39
//	 * @param name the name
40
//	 * @param queries the queries
41
//	 * @param partnames the partnames
42
//	 * @param registered the registered
43
//	 * @return the partition
44
//	 * @throws CqiClientException the cqi client exception
45
//	 */
46
//	public Partition createPartition(String name, List<String> queries, List<String> partnames, boolean registered) throws Exception {
47
//		Partition partition = new Partition(this);
48
//		partition.setParameters(name, queries, partnames);
49
//		partition.compute();
50
//		if (!registered) {
51
//			partition.registerToParent();
52
//		}
53
//		return partition;
54
//	}
55
//
56
//	/**
57
//	 * Creates the partition.
58
//	 *
59
//	 * @param structure the structure
60
//	 * @param property the property
61
//	 * @param values the values
62
//	 * @param registered the registered
63
//	 * @return the partition
64
//	 * @throws CqiClientException the cqi client exception
65
//	 */
66
//	public Partition createPartition(String name, StructuralUnit structure, StructuralUnitProperty property, List<String> values, boolean registered) throws Exception {
67
//		Partition partition = new Partition(this);
68
//		partition.setParameters(name, property, values);
69
//		partition.compute();
70
//		if (!registered) {
71
//			partition.registerToParent();
72
//		}
73
//		return partition;
74
//	}
75
//
76
//	/**
77
//	 * Creates a subcorpus using workspace definition.
78
//	 *
79
//	 * @param elem the XML element
80
//	 * @return the subcorpus
81
//	 * @throws CqiClientException the cqi client exception
82
//	 */
83
//	public Subcorpus createSubcorpus(Element elem) throws CqiClientException {
84
//		Query query = new Query(elem.getAttribute("query")); //$NON-NLS-1$
85
//		String subcorpusName = elem.getAttribute("name"); //$NON-NLS-1$
86
//
87
//		Subcorpus subcorpus;
88
//		String subcorpusCqpId = subcorpusNamePrefix	+ getNextSubcorpusCounter();
89
//
90
//		// long start = System.currentTimeMillis();
91
//		try {
92
//			CQPSearchEngine.getCqiClient().cqpQuery(this.getQualifiedCqpId(), subcorpusCqpId,
93
//					query.getQueryString());
94
//			subcorpus = new Subcorpus(subcorpusCqpId, subcorpusName, this, query);
95
//			subcorpus.setSelfElement(elem);
96
//		} catch (Exception e) {
97
//			throw new CqiClientException(e);
98
//		}
99
//
100
//		return subcorpus;
101
//	}
102
//
103
//	/**
104
//	 * Create a named subcorpus from a query on this corpus.
105
//	 * 
106
//	 * @param query
107
//	 *            the query
108
//	 * @param subcorpusName
109
//	 *            the resulting subcorpus name
110
//	 * 
111
//	 * @return the resulting subcorpus
112
//	 * 
113
//	 * @throws CqiClientException
114
//	 *             the cqi client exception
115
//	 */
116
//	public Subcorpus createSubcorpus(Query query, String subcorpusName)
117
//			throws CqiClientException {
118
//		Subcorpus sc = createSubcorpus(query, subcorpusName, false);
119
//		return sc;
120
//	}
121
//
122
//	/**
123
//	 * Creates a subcorpus and save configuration in the workspace.
124
//	 *
125
//	 * @param query the query
126
//	 * @param subcorpusName the subcorpus name
127
//	 * @param registered the registered
128
//	 * @return the subcorpus
129
//	 * @throws CqiClientException the cqi client exception
130
//	 */
131
//	public Subcorpus createSubcorpus(Query query, String subcorpusName,
132
//			boolean registered) throws CqiClientException {
133
//		Subcorpus subcorpus;
134
//		String subcorpusCqpId = subcorpusNamePrefix + getNextSubcorpusCounter().toString();
135
//		Log.finest(TXMCoreMessages.CREATING_SUBCORPUS + this.getQualifiedCqpId()
136
//				+ " " + subcorpusName + " " + query.getQueryString()); //$NON-NLS-1$ //$NON-NLS-2$
137
//
138
//		long start = System.currentTimeMillis();
139
//		try {
140
//			CQPSearchEngine.getCqiClient().cqpQuery(
141
//					this.getQualifiedCqpId(), subcorpusCqpId,
142
//					query.getQueryString());
143
//			//System.out.println("SUBCORPUS: "+subcorpusCqpId+" q="+query.getQueryString());
144
//			subcorpus = new Subcorpus(subcorpusCqpId, subcorpusName, this, query);
145
//		} catch (Exception e) {
146
//			throw new CqiClientException(e);
147
//		}
148
//		long end = System.currentTimeMillis();
149
//		Log.finest(TXMCoreMessages.SUBCORPUS_CREATED + subcorpusName
150
//				+ TXMCoreMessages.in + (end - start));
151
//
152
//		if (!registered) subcorpus.registerToParent();
153
//		return subcorpus;
154
//	}
155
//
156
//	public Subcorpus createSubcorpus(String name, QueryResult queryResult) throws InvalidCqpIdException {
157
//		Subcorpus sub = new Subcorpus(queryResult.getCqpId(), name, this, null);
158
//		return sub;
159
//	}
160
//
161
//	public Subcorpus createSubcorpus(String name, String cqpid) throws InvalidCqpIdException {
162
//		Subcorpus sub = new Subcorpus(cqpid, name, this, null);
163
//		return sub;
164
//	}
165
//	
166
//	/**
167
//	 * Creates the subcorpus.
168
//	 *
169
//	 * @param elem the elem
170
//	 * @return the subcorpus
171
//	 * @throws CqiClientException the cqi client exception
172
//	 */
173
//	public Subcorpus createSubcorpus(String name, SelectionResult selectionResult) throws CqiClientException {
174
//		Subcorpus sub = createSubcorpus(this.getStructuralUnit("text"), this.getStructuralUnit("text").getProperty("id"), selectionResult, name); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
175
//		sub.setSelectionResult(selectionResult);
176
//		return sub;
177
//	}
178
//	
179
//	/**
180
//	 * Creates the subcorpus.
181
//	 *
182
//	 * @param structuralUnit the structural unit
183
//	 * @param structuralUnitProperty the structural unit property
184
//	 * @param values the values
185
//	 * @param subcorpusName the subcorpus name
186
//	 * @return the subcorpus
187
//	 * @throws CqiClientException the cqi client exception
188
//	 */
189
//	public Subcorpus createSubcorpus(StructuralUnit structuralUnit,
190
//			StructuralUnitProperty structuralUnitProperty, List<String> values,
191
//			String subcorpusName) throws CqiClientException {
192
//		if (values.size() == 0) {
193
//			Log.warning(TXMCoreMessages.noValuesGiven);
194
//			return null;
195
//		}
196
//		String value = ""; //$NON-NLS-1$
197
//		for (String v : values)
198
//			value += Query.addBackSlash(v) + "|"; //$NON-NLS-1$
199
//		value = value.substring(0, value.length() - 1);
200
//		
201
//		Query query = new QueryPart(structuralUnit, structuralUnitProperty, value);
202
//		return createSubcorpus(query, subcorpusName);
203
//		//return createSubcorpus(structuralUnit, structuralUnitProperty, value, subcorpusName);
204
//	}
205
//
206
//	/**
207
//	 * Create a subcorpus from a structural unit, a property on this structural
208
//	 * unit and a value for this property.
209
//	 *
210
//	 * @param structuralUnit the structural unit
211
//	 * @param structuralUnitProperty the structural unit property
212
//	 * @param value the value
213
//	 * @param subcorpusName the subcorpus name
214
//	 * @return the subcorpus
215
//	 * @throws CqiClientException the cqi client exception
216
//	 * @author Sylvain Loiseau
217
//	 */
218
//	public Subcorpus createSubcorpus(StructuralUnit structuralUnit,
219
//			StructuralUnitProperty structuralUnitProperty, String value,
220
//			String subcorpusName) throws CqiClientException {
221
//		Query query = new QueryPart(structuralUnit, structuralUnitProperty,
222
//				Query.addBackSlash(value));
223
//		// System.out.println("forged query : "+query.getQueryString());
224
//		return createSubcorpus(query, subcorpusName);
225
//	}
226
//
227
//	/**
228
//	 * Create a subcorpus from a structural unit, a property on this structural
229
//	 * unit and a value for this property.
230
//	 *
231
//	 * @param structuralUnit the structural unit
232
//	 * @param structuralUnitProperty the structural unit property
233
//	 * @param value the value
234
//	 * @param subcorpusName the subcorpus name
235
//	 * @return the subcorpus
236
//	 * @throws CqiClientException the cqi client exception
237
//	 * @author Sylvain Loiseau
238
//	 */
239
//	public Subcorpus createSubcorpusWithQueryString(StructuralUnit structuralUnit,
240
//			StructuralUnitProperty structuralUnitProperty, String value,
241
//			String subcorpusName) throws CqiClientException {
242
//		Query query = new QueryPart(structuralUnit, structuralUnitProperty,
243
//				value);
244
//		// System.out.println("forged query : "+query.getQueryString());
245
//		return createSubcorpus(query, subcorpusName);
246
//	}
247
//
248
//	/**
249
//	 * Drop all the partitions.
250
//	 * 
251
//	 * @throws CqiClientException
252
//	 *             the cqi client exception
253
//	 */
254
//	public void dropAllPartitions() throws CqiClientException {
255
//		List<Partition> _partitions = (List<Partition>) getChildren(Partition.class);
256
//		for (Partition partition : _partitions) {
257
//			this.dropPartition(partition);
258
//		}
259
//		_partitions = null;
260
//	}
261
//
262
//	/**
263
//	 * Drop all the subcorpora.
264
//	 * 
265
//	 * @throws CqiClientException
266
//	 *             the cqi client exception
267
//	 */
268
//	public void dropAllSubcorpora() throws CqiClientException {
269
//		//System.out.println("!! drop all subcorpora: "+subcorpora.size());
270
//		List<Subcorpus> subcorpora = getSubcorpora();
271
//		while(subcorpora.size() > 0) {
272
//			this.dropSubcorpus(subcorpora.get(0));
273
//		}
274
//	}
275
//
276
//	/**
277
//	 * Drops a partition.
278
//	 * 
279
//	 * @param partition
280
//	 *            the partition
281
//	 * 
282
//	 * @throws CqiClientException
283
//	 *             the cqi client exception
284
//	 */
285
//	public void dropPartition(Partition partition) throws CqiClientException {
286
//		Log.finest(SearchEngineCoreMessages.info_deletingPartition + partition.getName());
287
//		for (Part part : partition.getParts())
288
//			try {
289
//				CQPSearchEngine.getCqiClient().dropSubCorpus(part.getQualifiedCqpId());
290
//			} catch (Exception e) {
291
//				throw new CqiClientException(e);
292
//			}
293
//	}
294
//
295
//	/**
296
//	 * Drop query result.
297
//	 * 
298
//	 * @param queryResult
299
//	 *            the query result
300
//	 * 
301
//	 * @throws CqiClientException
302
//	 *             the cqi client exception
303
//	 */
304
//	public void dropQueryResult(QueryResult queryResult)
305
//			throws CqiClientException {
306
//		Log.finest(SearchEngineCoreMessages.deletingQueryResultP0 + queryResult.getName());
307
//		try {
308
//			CQPSearchEngine.getCqiClient().dropSubCorpus(queryResult.getQualifiedCqpId());
309
//		} catch (Exception e) {
310
//			throw new CqiClientException(e);
311
//		}
312
//	}
313
//
314
//	/**
315
//	 * Drops a subcorpus in CQP also its subcorpus and partitions.
316
//	 * 
317
//	 * @param subcorpus
318
//	 *            the subcorpus
319
//	 * 
320
//	 * @throws CqiClientException
321
//	 *             the cqi client exception
322
//	 */
323
//	public boolean dropSubcorpus(Corpus subcorpus) throws CqiClientException {
324
//		Log.finest(NLS.bind(TXMCoreMessages.DROP_SUBCORPUS, subcorpus.getName()));
325
//		subcorpus.dropAllSubcorpora();
326
//		subcorpus.dropAllPartitions();
327
//		try {
328
//			CQPSearchEngine.getCqiClient().dropSubCorpus(subcorpus.getQualifiedCqpId());
329
//		} catch (Exception e) {
330
//			throw new CqiClientException(e);
331
//		}
332
//		return true;
333
//	}
334
//
335
//
336
//
337
//
338

  
339
//	/* (non-Javadoc)
340
//	 * @see org.txm.objects.TxmObject#load()
341
//	 */
342
//	protected boolean _loadCorpus() {
343
//		//System.out.println("*** Load corpus: "+name);
344
//		if (getSelfElement() == null) {
345
//			return false;
346
//		}
347
//
348
//		// 1- texts queries then
349
//		// 2- get metadatas, pattributes, sattributes, editions, biblios,  uis,
350
//		super._load();  
351
//		// System.out.println("Load corpus : "+this.name);
352
//		this.loadMetadata(); // read <prop>s
353
//
354
//		// 3- build saved subcorpus and partition
355
//		//System.out.println("restore subcorpora: "+selfElement);
356
//		NodeList preBuildElems = getSelfElement().getElementsByTagName("preBuild"); //$NON-NLS-1$
357
//		if (preBuildElems.getLength() > 0) {
358
//			Element preBuildElem = (Element) preBuildElems.item(0);
359
//			NodeList subcorpusElems = preBuildElem.getElementsByTagName("subcorpus"); //$NON-NLS-1$
360
//			for (int i = 0 ; i < subcorpusElems.getLength() ; i++) {
361
//				Element subcorpusElem = (Element) subcorpusElems.item(i);
362
//				if (!subcorpusElem.getParentNode().equals(preBuildElem)) continue; //level 1 elements
363
//				//System.out.println("subcorpus "+subcorpusElem.getAttribute("name"));
364
//				try {
365
//					Subcorpus subcorp = this.createSubcorpus(subcorpusElem);
366
//					subcorp.load(subcorpusElem);
367
//				} catch (CqiClientException e) {
368
//					Log.warning(this.name + TXMCoreMessages.failedToRestoreSubcorpus + name
369
//							+ " : " + e); //$NON-NLS-1$
370
//				}
371
//			}
372
//
373
//			NodeList partitionElems = preBuildElem.getElementsByTagName("partition"); //$NON-NLS-1$
374
//			for (int i = 0 ; i < partitionElems.getLength() ; i++) {
375
//				Element partitionElem = (Element) partitionElems.item(i);
376
//				if (!partitionElem.getParentNode().equals(preBuildElem)) continue; //level 1 elements
377
//				String name = partitionElem.getAttribute("name"); //$NON-NLS-1$
378
//				List<String> names = new ArrayList<String>();
379
//				List<String> queries = new ArrayList<String>();
380
//
381
//				NodeList partElems = partitionElem.getElementsByTagName("part"); //$NON-NLS-1$
382
//				for (int j = 0; j < partElems.getLength(); j++) {
383
//					Element part = (Element) partElems.item(j);
384
//					names.add(part.getAttribute("name")); //$NON-NLS-1$
385
//					queries.add(part.getAttribute("query")); //$NON-NLS-1$
386
//				}
387
//				try {
388
//					//System.out.println("Create Partition with corpus "+this+" : "+name+", queries "+queries+", names "+names);
389
//					Partition partition = this.createPartition(name, queries, names, true);
390
//					partition.load(partitionElem);
391
//				} catch (Exception e) {
392
//					Log.warning(this.name + TXMCoreMessages.failedToRestorePartition + name
393
//							+ " : " + e); //$NON-NLS-1$
394
//					//c.getParentNode().removeChild(c);
395
//				}
396
//			}
397
//		}
398
//
399
//		return true;
400
//	}
401

  
402

  
403
///*
404
// * (non-Javadoc)
405
// * 
406
// * @see org.txm.searchengine.cqp.corpus.Corpus#getLocale()
407
// */
408
//@Override
409
//protected boolean _loadSubcorpus() {
410
//	if (getSelfElement() != null) {
411
//		this.query = new Query(getSelfElement().getAttribute("query")); //$NON-NLS-1$
412
//
413
//		NodeList subcorpusElems = getSelfElement().getElementsByTagName("subcorpus"); //$NON-NLS-1$
414
//		for (int i = 0 ; i < subcorpusElems.getLength() ; i++) {
415
//			Element subcorpusElem = (Element) subcorpusElems.item(i);
416
//			try {
417
//				Subcorpus subcorp = this.createSubcorpus(subcorpusElem);
418
//				subcorp.load(subcorpusElem);
419
//			} catch (CqiClientException e) {
420
//				Log.warning(this.name + TXMCoreMessages.failedToRestoreSubcorpus + name
421
//						+ " : " + e); //$NON-NLS-1$
422
//			}
423
//		}
424
//
425
//		NodeList partitionElems = getSelfElement().getElementsByTagName("partition"); //$NON-NLS-1$
426
//		for (int i = 0 ; i < partitionElems.getLength() ; i++) {
427
//			Element partitionElem = (Element) partitionElems.item(i);
428
//			String name = partitionElem.getAttribute("name"); //$NON-NLS-1$
429
//			List<String> names = new ArrayList<String>();
430
//			List<String> queries = new ArrayList<String>();
431
//
432
//			NodeList partElems = partitionElem.getElementsByTagName("part"); //$NON-NLS-1$
433
//			for (int j = 0; j < partElems.getLength(); j++) {
434
//				Element part = (Element) partElems.item(j);
435
//				names.add(part.getAttribute("name")); //$NON-NLS-1$
436
//				queries.add(part.getAttribute("query")); //$NON-NLS-1$
437
//			}
438
//			try {
439
//				//System.out.println("Create Partition with corpus "+this+" : "+name+", queries "+queries+", names "+names);
440
//				Partition partition = this.createPartition(name, queries, names, true);
441
//				partition.load(partitionElem);
442
//			} catch (Exception e) {
443
//				Log.warning(this.name + TXMCoreMessages.failedToRestorePartition + name
444
//						+ " : " + e); //$NON-NLS-1$
445
//				//c.getParentNode().removeChild(c);
446
//			}
447
//		}
448
//	}
449
//	initSelectionResult();
450
//	//System.out.println("Subcorpus.load: Selection of "+this+" = "+selectionResult);
451
//	//return super.load();
452
//	return true;
453
//}
454

  
455
//	/* (non-Javadoc)
456
//	 * @see org.txm.objects.TxmObject#load()
457
//	 */
458
//	@Override
459
//	protected boolean _loadPartition() {
460
//		if (this.getUUID().length() > 0) return true; // partition already persisted
461
//
462
//		if (this.hasBeenComputedOnce) return true; // partition already computed
463
//		
464
//		if (this.getSelfElement() != null && this.getParent() != null) {
465
//			NodeList partList = getSelfElement().getChildNodes();
466
//			for (int i = 0; i < partList.getLength(); i++) {
467
//				if (partList.item(i).getNodeType() == 1) {
468
//					Element c = (Element) partList.item(i);
469
//					if (c.getNodeName().equals("part")) //$NON-NLS-1$
470
//					{
471
//						String pname = c.getAttribute("name"); //$NON-NLS-1$
472
//						String pshortname = c.getAttribute("shortname"); //$NON-NLS-1$
473
//						String pquery = c.getAttribute("query"); //$NON-NLS-1$
474
//						for (Part part : getParts())
475
//							if (part.getName().equals(pname)) {
476
//								part.setName(pname);
477
//								part.setShortName(pshortname);
478
//								part.setQuery(pquery);
479
//							}
480
//					}
481
//				}
482
//			}
483
//			this.loadMetadata();
484
//			return true;
485
//		}
486
//
487
//		return false;
488
//	}
489

  
490

  
491
///**
492
// * Creates the part.
493
// *
494
// * @param partitionName the partition name
495
// * @param partName the part name
496
// * @param query the query
497
// * @return the part
498
// * @throws CqiClientException the cqi client exception
499
// */
500
//private Part createPart(String partitionName, String partName, Query query)	throws CqiClientException {
501
//	if (partName.length() == 0) {
502
//		partName = "-"; //$NON-NLS-1$
503
//	}
504
//	return createPart(partitionName, partName, query.getQueryString());
505
//}
506
//
507
///**
508
// * Create a part with a raw query.
509
// *
510
// * @param partitionName the partition name
511
// * @param partName the part name
512
// * @param query the query
513
// * @return the part
514
// * @throws CqiClientException the cqi client exception
515
// * 
516
// * @author Sylvain Loiseau, mdecorde
517
// */
518
//public Part createPart(String partitionName, String partName, String query) throws CqiClientException {
519
//	Part part;
520
//	String partCqpId = CqpObject.partNamePrefix + Corpus.getNextSubcorpusCounter();
521
//	Log.finest(NLS.bind(TXMCoreMessages.CREATING_PART,partName, query));
522
//	long start = System.currentTimeMillis();
523
//	try {
524
//		CQPSearchEngine.getCqiClient().cqpQuery(this.getParent().getQualifiedCqpId(), partCqpId, query);
525
//		part = new Part(partCqpId, partitionName, partName, this, new Query(query));
526
//
527
//		// FIXME: persistence tests: define the UUID as the concatenation of all part CQP id
528
////		this.uniqueID += partCqpId;
529
//
530
//	} catch (Exception e) {
531
//		try {
532
//			throw new CqiClientException(TXMCoreMessages.failedToCreatePartColon + partitionName + "_" + partName + e + " last error: " + CQPSearchEngine.getCqiClient().getLastCQPError()); //$NON-NLS-1$ //$NON-NLS-2$
533
//		} catch (Exception e1) {
534
//			System.out.println(TXMCoreMessages.failedToGetLastCQPErrorColon+e1);
535
//			org.txm.utils.logger.Log.printStackTrace(e1);
536
//			return null;
537
//		}
538
//	}
539
//	long end = System.currentTimeMillis();
540
//	Log.finest(NLS.bind(TXMCoreMessages.info_partCreatedInXMs, partitionName + "_" + partName, (end - start))); //$NON-NLS-1
541
//
542
//	return part;
543
//}
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/CQPCorpus.java (revision 2767)
403 403
			NodeList subcorpusElems = preBuildElem.getElementsByTagName("subcorpus"); //$NON-NLS-1$
404 404
			for (int i = 0; i < subcorpusElems.getLength(); i++) {
405 405
				Element subcorpusElem = (Element) subcorpusElems.item(i);
406
				if (!subcorpusElem.getParentNode().equals(preBuildElem))
406
				if (!subcorpusElem.getParentNode().equals(preBuildElem)) {
407 407
					continue; // level 1 elements
408
				// System.out.println("subcorpus "+subcorpusElem.getAttribute("name"));
409
				// try {
408
				}
410 409
				Subcorpus subcorp = new Subcorpus(this);
411 410
				subcorp._load(subcorpusElem);
412
				// subcorp.compute();
413
				// } catch (CqiClientException ex) {
414
				// Log.warning(this.pID + TXMCoreMessages.failedToRestoreSubcorpus + pID
415
				// + " : " + ex); //$NON-NLS-1$
416
				// }
417 411
			}
418 412
			
419 413
			NodeList partitionElems = preBuildElem.getElementsByTagName("partition"); //$NON-NLS-1$
......
432 426
					queries.add(part.getAttribute("query")); //$NON-NLS-1$
433 427
				}
434 428
				try {
435
					// System.out.println("Create Partition with corpus "+this+" : "+name+", queries
436
					// "+queries+", names "+names);
437 429
					Partition partition = new Partition(this);
438 430
					partition.setParameters(name, queries, names);
439
					
440
					// partition.setSelfElement(partitionElem);
441
					// partition.load();
442
					// partition.compute();
443 431
				}
444 432
				catch (Exception ex) {
445
					Log.warning(this.pID + TXMCoreMessages.failedToRestorePartition + name + " : " + ex); //$NON-NLS-1$
446
					// c.getParentNode().removeChild(c);
433
					Log.warning(TXMCoreMessages.bind(TXMCoreMessages.failedToRestorePartition, name, this.pID, ex));
447 434
				}
448 435
			}
449 436
		}
450 437
		
451
		// 4- initialize JPA persistence of annotations
452
		// try {
453
		// AnnotationManager.getInstance().initTemporaryAnnotationDatabase(this);
454
		// } catch(Exception e) {
455
		// System.out.println("Fail to load annotation service: "+e);
456
		// Log.printStackTrace(e);
457
		// }
458
		//
459 438
		return true;
460 439
	}
461 440
	
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/MainCorpus.java (revision 2767)
143 143
		
144 144
		HashMap<String, MainCorpus> corpora = CorpusManager.getCorpusManager().getCorpora();
145 145
		if (CorpusManager.getCorpusManager().hasCorpus(this)) {
146
			// Log.severe(NLS.bind("** The \"{0}\" MainCorpus object in the \"{1}\" project can not be computed: another one with the same CQP identifier has already been computed.", this.pID, this
147
			// .getProjectDirectory()));
146
			Log.fine(NLS.bind("** The \"{0}\" MainCorpus object in the \"{1}\" project can not be computed: another one with the same CQP identifier has already been computed.",
147
					this.pID, this.getProjectDirectory()));
148 148
			return true;
149 149
		}
150 150
		CorpusManager.getCorpusManager().add(this);
......
232 232
	public boolean _load(Element e) {
233 233
		boolean ret = super._load(e);
234 234
		
235
		// FIXME: test to create a project scope
236
		// CorpusScope scope = new CorpusScope(this.getName(), this.getProjectDirectory());
237
		// CorpusScope.addScope(scope);
238
		
239 235
		return ret;
240 236
	}
241 237
	
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Subcorpus.java (revision 2767)
196 196
					partition._load(partitionElem);
197 197
				}
198 198
				catch (Exception ex) {
199
					Log.warning(this.pID + TXMCoreMessages.failedToRestorePartition + name
200
							+ " : " + ex); //$NON-NLS-1$
201
					// c.getParentNode().removeChild(c);
199
					Log.warning(TXMCoreMessages.bind(TXMCoreMessages.failedToRestoreSubcorpus, name, this.pID, ex));
202 200
				}
203 201
			}
204 202
		}
tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 2767)
1213 1213
		return ret;
1214 1214
	}
1215 1215
	
1216
	// FIXME: SJ: this method sould not call persist on children if childrenAsWell == false?
1216
	// FIXME: SJ: this method should not call persist on children if childrenAsWell == false?
1217 1217
	public void persist(boolean childrenAsWell) {
1218 1218
		if (this.mustBePersisted()) {
1219 1219
			TXMPreferences.flush(this);
tmp/org.txm.core/src/java/org/txm/core/messages/messages.properties (revision 2767)
137 137

  
138 138
failedToLoadBaseParametersFromTheP0File = ** Failed to load the corpus parameters from the {0} file.
139 139

  
140
failedToRestorePartition = ** Failed to restore partition 
140
failedToRestorePartition = ** Failed to restore partition {0} of corpus {1}: {2}
141 141

  
142
failedToRestoreSubcorpus = ** Failed to restore subcorpus 
142
failedToRestoreSubcorpus = ** Failed to restore subcorpus {0} of corpus {1}: {2}
143 143

  
144 144
failedToStartMemCqiClientColon = ** Failed to start CQP in memory mode.
145 145

  
tmp/org.txm.core/src/java/org/txm/core/messages/messages_fr.properties (revision 2767)
135 135

  
136 136
failedToLoadBaseParametersFromTheP0File = ** Impossible de charger les paramètres de corpus depuis le fichier {0}.
137 137

  
138
failedToRestorePartition = ** Échec de la restauration de la partition 
138
failedToRestorePartition = ** Échec de la restauration de la partition {0} du corpus {1}: {2}
139 139

  
140
failedToRestoreSubcorpus = ** Échec de la restauration du sous-corpus 
140
failedToRestoreSubcorpus = ** Échec de la restauration du sous-corpus {0} du corpus {1}: {2}
141 141

  
142 142
failedToStartMemCqiClientColon = ** Impossible de démarrer CQP en mode mémoire.
143 143

  
tmp/org.txm.core/src/java/org/txm/objects/Project.java (revision 2767)
1354 1354
	public boolean save() {
1355 1355
		try {
1356 1356
			ProjectScope scope = this.getPreferencesScope();
1357
			scope.getNode("").flush(); //$NON-NLS-1$
1358 1357
			
1359 1358
			autoSaveParametersFromAnnotations();
1360 1359
			saveParameters();
......
1365 1364
				if (r.mustBePersisted()) {
1366 1365
					r.autoSaveParametersFromAnnotations();
1367 1366
					r.saveParameters();
1368
					TXMPreferences.flush(r);
1367
					// TXMPreferences.flush(r);
1369 1368
				}
1370 1369
			}
1371 1370
			
1371
			scope.getNode("").flush(); //$NON-NLS-1$
1372 1372
			Toolbox.notifyEngines(this, "save"); // save things before exporting or else
1373 1373
		}
1374 1374
		catch (Exception e) {
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/Load079BinaryCorpus.java (revision 2767)
40 40
import org.txm.utils.logger.Log;
41 41
import org.txm.utils.zip.Zip;
42 42

  
43
// TODO: Auto-generated Javadoc
44 43
/**
45 44
 * Create a base from binary files of a base.
46 45
 *
47 46
 * @author mdecorde
48 47
 */
49 48
public class Load079BinaryCorpus {
50

  
49
	
51 50
	public static boolean canLoad(File zipFile) {
52 51
		String basedirname = Zip.getRoot(zipFile);
53
		return Zip.hasEntries(zipFile, basedirname+"/import.xml", basedirname+"/data/", basedirname+"/txm/", basedirname+"/HTML/", basedirname+"/registry/");
52
		return Zip.hasEntries(zipFile, basedirname + "/import.xml", basedirname + "/data/", basedirname + "/txm/", basedirname + "/HTML/", basedirname + "/registry/");
54 53
	}
55

  
54
	
56 55
	/**
57
	 * Load a 0.7.9 binary corpus archive: 
56
	 * Load a 0.7.9 binary corpus archive:
58 57
	 * 
59 58
	 * 1- test if the corpus directory is already used
60 59
	 * 2- delete previous corpus version
61 60
	 * 3- unzip the archive
62 61
	 * 4- load the binary corpus directory
63 62
	 * 5- restart TXM engines
64
	 * @param replace 
65
	 * @throws Exception 
63
	 * 
64
	 * @param replace
65
	 * @throws Exception
66 66
	 */
67 67
	public static Project loadBinaryCorpusArchive(final File zipFile, IProgressMonitor monitor, boolean replace) throws Exception {
68

  
69
		final File corporaDir = Toolbox.workspace.getLocation(); //$NON-NLS-1$
68
		
69
		final File corporaDir = Toolbox.workspace.getLocation();
70 70
		corporaDir.mkdir();
71 71
		
72 72
		if (!canLoad(zipFile)) {
73
			System.out.println(TXMUIMessages.binaryCorpusIsNotATXM079CorpusNoImportXmlFile);	
73
			System.out.println(TXMUIMessages.binaryCorpusIsNotATXM079CorpusNoImportXmlFile);
74 74
			return null;
75 75
		}
76

  
76
		
77 77
		System.out.println(NLS.bind(TXMUIMessages.loadingTheP0BinaryCorpusAsATXM079Corpus, zipFile.getName()));
78 78
		
79 79
		String basedirname = Zip.getRoot(zipFile);
80

  
80
		
81 81
		Project p = Toolbox.workspace.getProject(basedirname.toUpperCase());
82 82
		if (p != null) {
83 83
			if (replace) {
84 84
				p.delete();
85
			} else {
85
			}
86
			else {
86 87
				System.out.println(NLS.bind(TXMUIMessages.abortingLoadingOfPOACorpusWithTheSameNameAlreadyExists, zipFile, basedirname.toUpperCase()));
87 88
				return null;
88 89
			}
......
91 92
		File corpusDirectory = new File(corporaDir, basedirname);
92 93
		if (replace) {
93 94
			DeleteDir.deleteDirectory(corpusDirectory);
94
		} else {
95
		}
96
		else {
95 97
			if (corpusDirectory.exists()) {
96 98
				System.out.println(NLS.bind(TXMUIMessages.abortingLoadingOfPOACorpusWithTheSameNameAlreadyExists, zipFile, corpusDirectory));
97 99
				return null;
98 100
			}
99 101
		}
100

  
101
		//ZIPPED FILE
102
		
103
		// ZIPPED FILE
102 104
		monitor.beginTask(TXMUIMessages.loadingBinaryCorpus, 100);
103 105
		monitor.subTask(TXMUIMessages.extractingBinaryCorpus);
104 106
		try {
105
			//System.out.println(NLS.bind(Messages.AddBase_29, zipFile, corporaDir));
107
			// System.out.println(NLS.bind(Messages.AddBase_29, zipFile, corporaDir));
106 108
			Zip.decompress(zipFile, corporaDir, false, monitor);
107 109
			if (!basedirname.equals(basedirname.toUpperCase())) { // manage old corpus with lower cased names
108 110
				new File(corporaDir, basedirname).renameTo(new File(corporaDir, basedirname.toUpperCase()));
109 111
				basedirname = basedirname.toUpperCase();
110 112
			}
111
		} catch (Exception e) {
113
		}
114
		catch (Exception e) {
112 115
			System.out.println(NLS.bind(TXMUIMessages.couldNotUnzipBinaryCorpusColon, e));
113 116
			org.txm.utils.logger.Log.printStackTrace(e);
114 117
			return null;
115 118
		}
116 119
		monitor.worked(50);
117

  
120
		
118 121
		monitor.subTask(TXMUIMessages.loadingTheCorpusInThePlatform);
119 122
		return loadBinaryCorpusAsDirectory(new File(corporaDir, basedirname), monitor);
120 123
	}
121

  
124
	
122 125
	/**
123 126
	 * load the content of the file if its a directory containing at least the sub folders :
124 127
	 * txm, html, data and registry.
......
131 134
		if (!(binCorpusDirectory.exists() && binCorpusDirectory.isDirectory())) {
132 135
			Log.severe(NLS.bind(TXMUIMessages.failedToLoadCorpusP0, binCorpusDirectory.getAbsolutePath()));
133 136
			System.out.println(NLS.bind(TXMUIMessages.failedToLoadCorpusP0, binCorpusDirectory.getAbsolutePath()));
134
			return null; 
137
			return null;
135 138
		}
136

  
137
		//File txmregistry = new File(Toolbox.getTxmHomePath(), "registry"); //$NON-NLS-1$
138
		//txmregistry.mkdir();
139
		
140
		// File txmregistry = new File(Toolbox.getTxmHomePath(), "registry"); //$NON-NLS-1$
141
		// txmregistry.mkdir();
139 142
		File txmcorpora = new File(Toolbox.getTxmHomePath(), "corpora"); //$NON-NLS-1$
140 143
		txmcorpora.mkdir();
141 144
		Project project = Toolbox.workspace.scanDirectory079(binCorpusDirectory);
142 145
		if (project == null) {
143
			Log.severe(NLS.bind(TXMUIMessages.failedToLoadCorpusFromDirectoryColonP0WeCannotFindTheNecessaryComponents, binCorpusDirectory)); 
146
			Log.severe(NLS.bind(TXMUIMessages.failedToLoadCorpusFromDirectoryColonP0WeCannotFindTheNecessaryComponents, binCorpusDirectory));
144 147
			return null;
145 148
		}
146

  
149
		
147 150
		MainCorpus c = new MainCorpus(project);
148 151
		BaseOldParameters params = new BaseOldParameters(new File(binCorpusDirectory, "import.xml"));
149 152
		params.load();
150 153
		c._load(params.getCorpusElement());
151
		if (c.compute(false)) {
152
			project.saveParameters(true);
154
		c.setDirty();
155
		if (c.compute(true)) {
156
			project.save();
153 157
			return project;
154
		} else {
158
		}
159
		else {
155 160
			project.delete();
156 161
			return null;
157 162
		}
158 163
	}
159
}
164
}

Also available in: Unified diff