Révision 1200

tmp/org.txm.concordance.core/src/org/txm/concordance/core/functions/Line.java (revision 1200)
299 299
		}
300 300

  
301 301
		return LangFormater.format(StringUtils.join(words, wordSeparator),
302
				concordance.getCorpus().getLang()); //$NON-NLS-1$
302
				concordance.getCorpus().getLanguage()); //$NON-NLS-1$
303 303
	}
304 304

  
305 305
	/**
......
349 349
			currentPos++; // next position
350 350
		}
351 351
		return LangFormater.format(StringUtils.join(words, wordSeparator),
352
				concordance.getCorpus().getLang()); //$NON-NLS-1$
352
				concordance.getCorpus().getLanguage()); //$NON-NLS-1$
353 353
	}
354 354

  
355 355
	/**
......
396 396
			currentPos++;
397 397
		}
398 398
		return LangFormater.format(StringUtils.join(words, wordSeparator),
399
				concordance.getCorpus().getLang()); 
399
				concordance.getCorpus().getLanguage()); 
400 400
	}
401 401
	
402 402
	/** The properties to process. */
......
430 430
			words.add(StringUtils.join(word, "_")); //$NON-NLS-1$
431 431
		}
432 432
		return LangFormater.format(StringUtils.join(words, " "), //$NON-NLS-1$
433
				concordance.getCorpus().getLang()); //$NON-NLS-1$
433
				concordance.getCorpus().getLanguage()); //$NON-NLS-1$
434 434
	}
435 435
	
436 436
	/**
......
458 458
			words.add(StringUtils.join(word, wordSeparator));
459 459
		}
460 460
		return LangFormater.format(StringUtils.join(words, wordSeparator),
461
				concordance.getCorpus().getLang()); //$NON-NLS-1$
461
				concordance.getCorpus().getLanguage()); //$NON-NLS-1$
462 462
	}
463 463
	
464 464
	/**
......
485 485
		}
486 486

  
487 487
		return LangFormater.format(StringUtils.join(words, " "), //$NON-NLS-1$
488
				concordance.getCorpus().getLang()); //$NON-NLS-1$
488
				concordance.getCorpus().getLanguage()); //$NON-NLS-1$
489 489
	}
490 490

  
491 491
	/**
tmp/org.txm.para.core/src/org/txm/para/core/functions/ParaBrowser.java (revision 1200)
214 214
				return new Pair<String, QueryResult>("error", null);
215 215
			} 
216 216
			return new Pair<String, QueryResult>(LangFormater.format(text, corpus
217
					.getLang()), result);
217
					.getLanguage()), result);
218 218
		}
219 219
		// return keywordsViewPropValues;
220 220
		return new Pair<String, QueryResult>("error no property", null);
tmp/org.txm.analec.feature/feature.xml (revision 1200)
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<feature
3
      id="org.txm.analec.feature"
3
      id="org.txm.annotation.urs.feature"
4 4
      label="Annotation URS (Unité-Relation-Schéma)"
5 5
      version="1.0.0.qualifier"
6 6
      provider-name="Textometrie.org">
......
83 83
   </requires>
84 84

  
85 85
   <plugin
86
         id="org.txm.analec.rcp"
86
         id="org.txm.annotation.urs.rcp"
87 87
         download-size="0"
88 88
         install-size="0"
89 89
         version="0.0.0"
tmp/org.txm.analec.feature/.project (revision 1200)
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<projectDescription>
3
	<name>org.txm.analec.feature</name>
3
	<name>org.txm.annotation.urs.feature</name>
4 4
	<comment></comment>
5 5
	<projects>
6 6
	</projects>
tmp/org.txm.analec.rcp/.project (revision 1200)
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<projectDescription>
3
	<name>org.txm.analec.rcp</name>
3
	<name>org.txm.annotation.urs.rcp</name>
4 4
	<comment></comment>
5 5
	<projects>
6 6
	</projects>
......
26 26
		<nature>org.eclipse.pde.PluginNature</nature>
27 27
		<nature>org.eclipse.jdt.core.javanature</nature>
28 28
	</natures>
29
	<filteredResources>
30
		
31
	</filteredResources>
32 29
</projectDescription>
tmp/org.txm.analec.rcp/src/org/eclipse/jface/fieldassist/TXMSimpleContentProposalProvider.java (revision 1200)
13 13

  
14 14
import java.util.ArrayList;
15 15

  
16
import org.txm.analec.preferences.AnalecPreferencePage;
17
import org.txm.analec.preferences.AnalecPreferences;
16
import org.txm.annotation.urs.preferences.AnalecPreferencePage;
17
import org.txm.annotation.urs.preferences.AnalecPreferences;
18 18
import org.txm.core.preferences.TXMPreferences;
19 19
import org.txm.rcp.TxmPreferences;
20 20

  
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/imports/AnalecAnnotationsImporter.java (revision 1200)
1
package org.txm.annotation.urs.imports;
2

  
3
import java.io.File;
4
import java.io.FilenameFilter;
5
import java.io.IOException;
6
import java.io.InputStream;
7
import java.net.MalformedURLException;
8
import java.util.ArrayList;
9
import java.util.Arrays;
10
import java.util.HashMap;
11
import java.util.List;
12

  
13
import javax.xml.stream.XMLInputFactory;
14
import javax.xml.stream.XMLStreamConstants;
15
import javax.xml.stream.XMLStreamException;
16
import javax.xml.stream.XMLStreamReader;
17

  
18
import org.apache.commons.lang.StringUtils;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.txm.Toolbox;
21
import org.txm.importer.PersonalNamespaceContext;
22
import org.txm.searchengine.cqp.AbstractCqiClient;
23
import org.txm.searchengine.cqp.CQPSearchEngine;
24
import org.txm.searchengine.cqp.corpus.MainCorpus;
25
import org.txm.searchengine.cqp.corpus.QueryResult;
26
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
27
import org.txm.utils.logger.Log;
28

  
29
import visuAnalec.donnees.Corpus;
30
import visuAnalec.elements.Relation;
31
import visuAnalec.elements.Schema;
32
import visuAnalec.elements.Unite;
33
import visuAnalec.fichiers.FichiersGlozz;
34
import visuAnalec.vue.Vue;
35

  
36
public class AnalecAnnotationsImporter {
37

  
38
	protected MainCorpus mainCorpus;
39
	protected Corpus analecCorpus;
40
	protected File annotationsDirectory;
41
	protected Vue analecVue;
42
	protected IProgressMonitor monitor;
43
	protected XMLInputFactory factory;
44
	protected File aamFile;
45
	protected static PersonalNamespaceContext Nscontext = new PersonalNamespaceContext();
46

  
47
	public AnalecAnnotationsImporter(IProgressMonitor monitor, File outputDirectory, File aamFile, MainCorpus mainCorpus, Corpus analecCorpus, Vue analecVue) {
48
		this.annotationsDirectory = outputDirectory;
49
		this.aamFile = aamFile;
50
		this.mainCorpus = mainCorpus;
51
		this.analecCorpus = analecCorpus;
52
		this.analecVue = analecVue;
53
		this.monitor = monitor;
54
	}
55

  
56
	public boolean process() throws Exception {
57
		if (!annotationsDirectory.exists()) {
58
			System.out.println("Error: annotationsDirectory does not exist: "+annotationsDirectory.getAbsolutePath());
59
			return false;
60
		}
61
		if (!annotationsDirectory.isDirectory()) {
62
			System.out.println("Error: annotationsDirectory is not a directory: "+annotationsDirectory.getAbsolutePath());
63
			return false;
64
		}
65
		if (!aamFile.exists()) {
66
			System.out.println("Error: aamFile does not exist: "+aamFile.getAbsolutePath());
67
			return false;
68
		}
69
		
70
		if (!FichiersGlozz.importerModeleGlozz(analecCorpus, aamFile)) {
71
			System.out.println("Error while importing Glozz model: "+aamFile);
72
			return false;
73
		}
74
		
75
		File[] ursFiles = annotationsDirectory.listFiles(new FilenameFilter() {
76
			@Override
77
			public boolean accept(File dir, String name) {
78
				return name.matches(".+-urs\\.xml");
79
			}
80
		});
81

  
82
		if (ursFiles == null) {
83
			System.out.println("No XML files found in "+annotationsDirectory);
84
			return false;
85
		}
86
		if (ursFiles.length == 0) {
87
			System.out.println("No XML files found in "+annotationsDirectory);
88
			return false;
89
		}
90
		Arrays.sort(ursFiles);
91

  
92
		factory = XMLInputFactory.newInstance();
93
		List<String> cqpTextIds = mainCorpus.getProject().getTextsID();
94

  
95
		List<Integer> all_result_summary = Arrays.asList(0,0,0,0,0,0,0,0);
96
		
97
		if (monitor != null) monitor.subTask("Processing "+ursFiles.length+" texts...");
98
		for (File xmlTXMFile : ursFiles) {
99
			String textid = xmlTXMFile.getName().substring(0, xmlTXMFile.getName().length() - 8);
100
			System.out.println("Processing text: "+textid);
101
			if (cqpTextIds.contains(textid)) {
102
				if (monitor != null) monitor.subTask("Processing "+textid+" text...");
103
				// N unit, N unit error, N unit no match error, N unit too much match error, N Relation, N Relation error, N Schema, N Schema error
104
				List<Integer> result_summary = processText(textid, xmlTXMFile);
105
				
106
				System.out.println(textid+" import report: ");
107
				System.out.println(" N Units added: "+result_summary.get(0));
108
				System.out.println(" N Units error: "+result_summary.get(1));
109
				System.out.println(" N Units no match error: "+result_summary.get(2));
110
				System.out.println(" N Units too much match error: "+result_summary.get(3));
111
				System.out.println(" N Relations added: "+result_summary.get(4));
112
				System.out.println(" N Relations error: "+result_summary.get(5));
113
				System.out.println(" N Schemas added: "+result_summary.get(6));
114
				System.out.println(" N Schemas error: "+result_summary.get(7));
115
				
116
				for (int i = 0 ; i < all_result_summary.size() ; i++) all_result_summary.set(i, all_result_summary.get(i)+result_summary.get(i));
117

  
118
			} else {
119
				System.out.println("Warning: cannot found text with ID="+textid+" in current CQP corpus.");
120
			}
121
		}
122
		
123
		System.out.println("Final import report: ");
124
		System.out.println(" N Units added: "+all_result_summary.get(0));
125
		System.out.println(" N Units error: "+all_result_summary.get(1));
126
		System.out.println(" N Units no match error: "+all_result_summary.get(2));
127
		System.out.println(" N Units too much match error: "+all_result_summary.get(3));
128
		System.out.println(" N Relations added: "+all_result_summary.get(4));
129
		System.out.println(" N Relations error: "+all_result_summary.get(5));
130
		System.out.println(" N Schemas added: "+all_result_summary.get(6));
131
		System.out.println(" N Schemas error: "+all_result_summary.get(7));
132

  
133
		return true;
134
	}
135

  
136
	private List<Integer> processText(String textid, File xmlTXMFile) throws Exception {
137
		AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
138
		// N unit, N unit error, N unit no match error, N unit too much match error, N Relation, N Relation error, N Schema, N Schema error
139
		int nUnitsAdded = 0;
140
		int nUnitsError = 0;
141
		int nUnitsNoMatchError = 0;
142
		int nUnitsTooMuchMatchError = 0;
143
		int nRelationsAdded = 0;
144
		int nRelationsError = 0;
145
		int nSchemaAdded = 0;
146
		int nSchemaError = 0;
147
		
148
		unites.clear();
149
		relations.clear();
150
		schemas.clear();
151
		elementProperties.clear();
152

  
153
		if (!parseXMLTXMFile(xmlTXMFile)) return null;
154

  
155
//		if (unites.size() > 0) System.out.println(unites);
156
//		if (relations.size() > 0) System.out.println(relations);
157
//		if (schemas.size() > 0) System.out.println(schemas);
158
//		if (elementProperties.size() > 0) System.out.println(elementProperties);
159
//		for (String u : unites.keySet()) if (!elementProperties.containsKey(u+"-fs")) System.out.println("MISSIGN ELEM PROPERTIES: "+u);
160
//		for (String u : relations.keySet()) if (!elementProperties.containsKey(u+"-fs")) System.out.println("MISSIGN ELEM PROPERTIES: "+u);
161
//		for (String u : schemas.keySet()) if (!elementProperties.containsKey(u+"-fs")) System.out.println("MISSIGN ELEM PROPERTIES: "+u);
162

  
163
		for (String id : unites.keySet()) {
164
			String ana = unites.get(id)[0];
165
			String type = unites.get(id)[1];
166
			String deb = unites.get(id)[2];
167
			String fin = unites.get(id)[3];
168
			if (elementProperties.containsKey(ana)) {
169

  
170
				try {
171
					CQLQuery query = new CQLQuery("[_.text_id=\""+textid+"\" & id=\""+deb+"|"+fin+"\"]");
172
					QueryResult result = mainCorpus.query(query, "TMP", true);
173
					int[] starts = result.getStarts();
174
					result.drop();
175
					if (starts.length == 1) {
176
						//System.out.println("create unite: "+type+" ["+deb+", "+fin+"]");
177
						Unite unite = analecCorpus.addUniteSaisie(type, starts[0], starts[0]);
178
						HashMap<String, String> props = elementProperties.get(ana);
179
						for (String prop : props.keySet()) {
180
							unite.putProp(prop, props.get(prop));
181
						}
182
						unitesRef.put(id, unite);
183
						nUnitsAdded++;
184
					} else if (starts.length == 2) {
185
						Unite unite = analecCorpus.addUniteSaisie(type, starts[0], starts[1]);
186
						//System.out.println("create unite: "+type+" ["+deb+", "+fin+"]");
187
						HashMap<String, String> props = elementProperties.get(ana);
188
						for (String prop : props.keySet()) {
189
							unite.putProp(prop, props.get(prop));
190
						}
191
						unitesRef.put(id, unite);
192
						nUnitsAdded++;
193
					} else {
194
						nUnitsError++;
195
						if (starts.length == 0) {
196
							System.out.println("WARNING: no position found for query "+query+".");
197
							nUnitsNoMatchError++;
198
						} else {
199
							System.out.println("WARNING: too many positions found for query "+query+" -> "+Arrays.toString(starts));
200
							nUnitsTooMuchMatchError++;
201
						}
202
					}
203
				} catch(Exception e) {
204
					System.out.println("Error while getting word positions of id="+deb+" and id="+fin+": "+e.getLocalizedMessage());
205
					Log.printStackTrace(e);
206
				}
207
			} else {
208
				System.out.println("Warning no properties found for element id="+id+" and ana="+ana);
209
			}
210
		}
211

  
212
		for (String id : relations.keySet()) {
213
			String ana = relations.get(id)[0];
214
			String type = relations.get(id)[1];
215
			String target = relations.get(id)[2];
216

  
217
			if (elementProperties.containsKey(ana)) {
218

  
219
				String[] wordsref = target.split(" ");
220
				String[] wordsid = new String[wordsref.length];
221
				for (int i = 0 ; i < wordsref.length ; i++) wordsid[i] = wordsref[i].substring(1);
222
				try {
223
					Unite elt1 = unitesRef.get(wordsid[0]);
224
					Unite elt2 = unitesRef.get(wordsid[1]);
225
					if (elt1 != null && elt2 != null) {
226
						//System.out.println("create relation: "+type+" ["+deb+", "+fin+"]");
227

  
228
						Relation relation = analecCorpus.addRelationSaisie(type, elt1, elt2);
229
						HashMap<String, String> props = elementProperties.get(ana);
230
						for (String prop : props.keySet()) {
231
							relation.putProp(prop, props.get(prop));
232
						}
233
						nRelationsAdded++;
234
					} else {
235
						System.out.println("ERROR: relation element not found "+Arrays.toString(wordsref));
236
						nRelationsError++;
237
					}
238
				} catch(Exception e) {
239

  
240
				}
241
			} else {
242
				System.out.println("Warning no properties found for element id="+id);
243
			}
244
		}
245

  
246
		for (String id : schemas.keySet()) {
247
			String ana = schemas.get(id)[0];
248
			String type = schemas.get(id)[1];
249
			String target = schemas.get(id)[2];
250
			if (elementProperties.containsKey(ana)) {
251
				String[] unitsref = target.split(" ");
252
				try {
253
					//System.out.println("create relation: "+type+" ["+deb+", "+fin+"]");
254
					Schema schema = new Schema(type);
255
					for (String unitid : unitsref) {
256
						unitid = unitid.substring(1); // remove '#'
257
						if (unitesRef.containsKey(unitid)) {
258
							Unite unite = unitesRef.get(unitid);
259
							schema.ajouter(unite);
260
						} else {
261
							System.out.println("Warning: missing unit id: "+unitid);
262
							nSchemaError++;
263
						}
264
					}
265
					analecCorpus.addSchemaLu(schema);
266
					HashMap<String, String> props = elementProperties.get(ana);
267
					for (String prop : props.keySet()) {
268
						schema.putProp(prop, props.get(prop));
269
					}
270
					nSchemaAdded++;
271
				} catch(Exception e) {
272
					System.out.println("Error while creating schema with id="+id);
273
				}
274
			} else {
275
				System.out.println("Warning no properties found for element id="+id);
276
			}
277
		}
278

  
279
		return Arrays.asList(nUnitsAdded, nUnitsError, nUnitsNoMatchError, nUnitsTooMuchMatchError,
280
		nRelationsAdded, nRelationsError,
281
		nSchemaAdded, nSchemaError);
282
	}
283

  
284
	private boolean parseXMLTXMFile(File xmlTXMFile) throws XMLStreamException, MalformedURLException, IOException {
285
		InputStream inputData = xmlTXMFile.toURI().toURL().openStream();
286
		factory = XMLInputFactory.newInstance();
287
		XMLStreamReader parser = factory.createXMLStreamReader(inputData);
288

  
289
		String currentType = null;
290
		String currentN = null;
291
		String currentAna = null;
292
		String currentName = null;
293
		String currentPropValue = null;
294

  
295
		int processMode = 0; // 0 nothing, 1 elements 2 properties
296

  
297
		if (!goToStandOff(parser)) {
298
			System.out.println("Error: cannot find the 'standOff' element in "+xmlTXMFile);
299
			return false;
300
		}
301
		String localname = null;
302
		for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
303
			switch (event) {
304
			case XMLStreamConstants.START_ELEMENT:
305
				localname = parser.getLocalName();
306

  
307
				if (localname.equals("annotationGrp")) {
308
					currentType = parser.getAttributeValue(null, "type");
309
					currentN = parser.getAttributeValue(null, "subtype");
310
					if (currentType != null && currentN != null) {
311
						processMode = 1;
312
					} else {
313
						System.out.println("Warning found "+localname+" without 'type' and 'n' attribute");
314
						processMode = 0;
315
					}
316
				} else if (localname.equals("div")) {
317
					String type = parser.getAttributeValue(null, "type");
318
					if (type == null) type = "";
319
					if (type.endsWith("-fs"))
320
					processMode = 2;
321
				} 
322

  
323
				if (processMode == 1) {
324
					if (localname.equals("span") || localname.equals("link")) {
325
						String id = parser.getAttributeValue(null, "id");
326
						String ana = parser.getAttributeValue(null, "ana");
327
						//System.out.println("SPAN id="+id +" ana="+ana+" currentType="+currentType+" currentN="+currentN);
328
						if ("Unit".equals(currentType)) {
329
							String from = parser.getAttributeValue(null, "from");
330
							String to = parser.getAttributeValue(null, "to");
331
							registerUnite(id, ana, currentN, from, to);
332
						} else if ("Relation".equals(currentType)) {
333
							String target = parser.getAttributeValue(null, "target");
334
							registerRelation(id, ana, currentN, target);
335
						} else if ("Schema".equals(currentType)) {
336
							String target = parser.getAttributeValue(null, "target");
337
							registerSchema(id, ana, currentN, target);
338
						}
339
					}
340
				} else if (processMode == 2) {
341
					if (localname.equals("fs")) {
342
						currentAna = parser.getAttributeValue(null, "id");
343
						if (elementProperties.get(currentAna) != null) System.out.println("WARNING: duplicated element properties: "+currentAna);
344
						elementProperties.put(currentAna, new HashMap<String, String>());
345
					} else if (localname.equals("f")) {
346
						currentName= parser.getAttributeValue(null, "name");
347
						currentPropValue = "";
348
					}
349
				} else {
350
					// nothing to do
351
				} 
352

  
353
				break;		
354
			case XMLStreamConstants.CHARACTERS:
355
				if (processMode == 2 && currentAna != null && currentName != null) {
356
					currentPropValue += parser.getText();
357
				}
358
				break;
359
			case XMLStreamConstants.END_ELEMENT:
360
				localname = parser.getLocalName();
361
				if (localname.equals("standOff")) { // stop all
362
					parser.close();
363
					inputData.close();
364
					return true;
365
				} else if (processMode == 1 && localname.equals("annotationGrp")) { // stop all
366
					currentType = null;
367
					currentN = null;
368
					processMode = 0;
369
				} else if (processMode == 2 && localname.equals("div")) {
370
					processMode = 0;
371
				}
372

  
373
				if (processMode == 1) {
374

  
375
				} else if (processMode == 2) {
376
					if (localname.equals("fs")) {
377
						currentAna = null;
378
					} else if (localname.equals("f")) {
379
						if (currentName != null && currentAna != null) {
380
							elementProperties.get(currentAna).put(currentName, currentPropValue);
381
						}
382
						currentName = null;
383
					}
384
				} else {
385
					// nothing to do
386
				}
387

  
388
				break;
389

  
390
			case XMLStreamConstants.END_DOCUMENT:
391
				parser.close();
392
				inputData.close();
393
				return false;
394
			}
395
		}
396
		parser.close();
397
		inputData.close();
398

  
399

  
400
		return false; // standOff not found
401
	}
402

  
403
	HashMap<String, HashMap<String, String>> elementProperties = new HashMap<String, HashMap<String, String>>();
404
	HashMap<String, String[]> unites = new HashMap<String, String[]>(); // id -> {ana, type, from, to}
405
	HashMap<String, Unite> unitesRef = new HashMap<String, Unite>(); // id -> Unite
406
	private void registerUnite(String id, String ana, String type, String from, String to) {
407
		String[] data = {ana.substring(1), type, from.substring(5), to.substring(5)};
408
		if (unites.containsKey(id)) {
409
			System.out.println("Warning: duplicated Unite id: "+id);
410
		} else {
411
			unites.put(id, data);
412
		}
413
	}
414
	HashMap<String, String[]> relations = new HashMap<String, String[]>(); // id -> {ana, type, target}
415
	private void registerRelation(String id, String ana, String type, String target) {
416
		String[] data = {ana.substring(1), type, target};
417
		if (relations.containsKey(id)) {
418
			System.out.println("Warning: duplicated Relation id: "+id);
419
		} else {
420
			relations.put(id, data);
421
		}
422
	}
423
	HashMap<String, String[]> schemas = new HashMap<String, String[]>(); // id -> {ana, type, target}
424
	private void registerSchema(String id, String ana, String type, String target) {
425
		String[] data = {ana.substring(1), type, target};
426
		//System.out.println("R schema: "+id+" : "+Arrays.toString(data));
427
		if (schemas.containsKey(id)) {
428
			System.out.println("Warning: duplicated Schema id: "+id);
429
		} else {
430
			schemas.put(id, data);
431
		}
432
	}
433

  
434
	private boolean goToStandOff(XMLStreamReader parser) throws XMLStreamException {
435
		for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
436
			switch (event) {
437
			case XMLStreamConstants.START_ELEMENT:
438
				String localname = parser.getLocalName();
439
				if (localname.equals("standOff")) return true;
440
				break;		
441
			}
442
		}
443
		return false;
444
	}
445
}
0 446

  
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/imports/DOMAnalecAnnotationsImporter.java (revision 1200)
1
package org.txm.annotation.urs.imports;
2

  
3
import java.io.File;
4
import java.io.FilenameFilter;
5
import java.util.HashMap;
6

  
7
import javax.xml.stream.XMLInputFactory;
8

  
9
import org.eclipse.core.runtime.IProgressMonitor;
10
import org.txm.Toolbox;
11
import org.txm.importer.PersonalNamespaceContext;
12
import org.txm.searchengine.cqp.AbstractCqiClient;
13
import org.txm.searchengine.cqp.CQPSearchEngine;
14
import org.txm.searchengine.cqp.corpus.MainCorpus;
15
import org.txm.utils.xml.DomUtils;
16
import org.w3c.dom.Document;
17
import org.w3c.dom.Element;
18
import org.w3c.dom.NodeList;
19

  
20
import visuAnalec.donnees.Corpus;
21
import visuAnalec.vue.Vue;
22

  
23
public class DOMAnalecAnnotationsImporter {
24

  
25
	MainCorpus mainCorpus;
26
	Corpus analecCorpus;
27
	File annotationsDirectory;
28
	private Vue analecVue;
29
	private IProgressMonitor monitor;
30
	private XMLInputFactory factory;
31
	protected static PersonalNamespaceContext Nscontext = new PersonalNamespaceContext();
32

  
33
	public DOMAnalecAnnotationsImporter(IProgressMonitor monitor, File outputDirectory, MainCorpus mainCorpus, Corpus analecCorpus, Vue analecVue) {
34
		this.annotationsDirectory = outputDirectory;
35
		this.mainCorpus = mainCorpus;
36
		this.analecCorpus = analecCorpus;
37
		this.analecVue = analecVue;
38
		this.monitor = monitor;
39
	}
40

  
41
	public boolean process() throws Exception {
42
		if (!annotationsDirectory.exists()) return false;
43
		if (!annotationsDirectory.isDirectory()) return false;
44

  
45
		File[] ursFiles = annotationsDirectory.listFiles(new FilenameFilter() {
46
			@Override
47
			public boolean accept(File dir, String name) {
48
				return name.matches(".+-urs\\.xml");
49
			}
50
		});
51

  
52
		if (ursFiles == null) {
53
			System.out.println("No XML files found in "+annotationsDirectory);
54
			return false;
55
		}
56
		if (ursFiles.length == 0) {
57
			System.out.println("No XML files found in "+annotationsDirectory);
58
			return false;
59
		}
60

  
61
		factory = XMLInputFactory.newInstance();
62

  
63
		for (File xmlAnalec : ursFiles) {
64
			String textid = xmlAnalec.getName().substring(0, xmlAnalec.getName().length() - 8);
65
			System.out.println("Processing text: "+textid);
66

  
67
			processText(textid, xmlAnalec);
68
		}
69

  
70
		return true;
71
	}
72

  
73
	private void processText(String textid, File xmlAnalec) throws Exception {
74
		AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
75

  
76
		HashMap<String, HashMap<String, String>> elementProperties = new HashMap<String, HashMap<String, String>>();
77

  
78
		Document doc = DomUtils.load(xmlAnalec);
79
		NodeList textElements = doc.getElementsByTagName("stdf");
80
		for (int iText = 0 ; iText < textElements.getLength() ; ) {
81
			Element text = (Element)textElements.item(iText);
82

  
83
			NodeList backElements = text.getElementsByTagName("annotations");
84
			for (int iBack = 0 ; iBack < backElements.getLength() ; ) {
85
				Element back = (Element)backElements.item(iBack);
86

  
87
				NodeList divElements = text.getElementsByTagName("div");
88
				for (int ifvLib = 0 ; ifvLib < divElements.getLength() ; ifvLib++) {
89
					Element divElement = (Element)divElements.item(ifvLib);
90
					String n = divElement.getAttribute("type");
91
					if (n == null) n = "";
92
					if (n.endsWith("-fs")) {
93
						getElementPropertiesFromFvLibElement(elementProperties, divElement);
94
					}
95
				}
96
				
97
				NodeList children = back.getElementsByTagName("spanGrp");
98
				for (int iChild = 0 ; iChild < children.getLength() ; iChild++) {
99
					Element spanGrpElement = (Element)children.item(iChild);
100
					String type = spanGrpElement.getAttribute("type");
101
					String n = spanGrpElement.getAttribute("subtype");
102
					if (type.equals("Unit")) {
103
						getUnitesFromSpanGrp(spanGrpElement, n);
104
					}
105
				}
106
				
107
				children = back.getElementsByTagName("joinGrp");
108
				for (int iChild = 0 ; iChild < children.getLength() ; iChild++) {
109
					Element joinGrpElement = (Element)children.item(iChild);
110
					String type = joinGrpElement.getAttribute("type");
111
					String n = joinGrpElement.getAttribute("subtype");
112
					if (type.equals("Relation")) {
113
						getRelationsFromJoinGrp(joinGrpElement, n);
114
					}
115
				}
116
				
117
				children = back.getElementsByTagName("joinGrp");
118
				for (int iChild = 0 ; iChild < children.getLength() ; iChild++) {
119
					Element joinGrpElement = (Element)children.item(iChild);
120
					String type = joinGrpElement.getAttribute("type");
121
					String n = joinGrpElement.getAttribute("subtype");
122
					if (type.equals("Schema")) {
123
						getSchemasFromJoinGrp(joinGrpElement, n);
124
					}
125
				}
126

  
127
				break; // stop at first back
128
			}
129

  
130
			break; // stop at first text
131
		}
132
	}
133

  
134
	private void getSchemasFromJoinGrp(Element joinGrpElement, String n) {
135
		NodeList children = joinGrpElement.getElementsByTagName("join");
136
		for (int iChild = 0 ; iChild < children.getLength() ; iChild++) {
137
			Element joinElement = (Element)children.item(iChild);
138
			String id = joinElement.getAttribute("id");
139
			String target = joinElement.getAttribute("target");
140
			String ana = joinElement.getAttribute("ana");
141
		}
142
	}
143

  
144
	private void getRelationsFromJoinGrp(Element joinGrpElement, String n) {
145
		// TODO Auto-generated method stub
146
		
147
	}
148

  
149
	private void getUnitesFromSpanGrp(Element spanGrpElement, String n) {
150
		// TODO Auto-generated method stub
151
		
152
	}
153

  
154
	private void getElementPropertiesFromFvLibElement(HashMap<String, HashMap<String, String>> elementProperties, Element divElement) {
155
		NodeList fsElements = divElement.getElementsByTagName("fs");
156
		for (int iChild = 0 ; iChild < fsElements.getLength() ; iChild++) {
157
			Element fsElement = (Element)fsElements.item(iChild);
158
			String id = fsElement.getAttribute("id");
159

  
160
			if (elementProperties.containsKey(id)) {
161
				System.out.println("Warning: duplicated fsElement id: "+id);
162
			} else {
163
				HashMap<String, String> properties = new HashMap<String, String>();
164
				elementProperties.put(id, properties);
165
				NodeList fElements = fsElement.getElementsByTagName("f");
166
				for (int iChild2 = 0 ; iChild2 < fElements.getLength() ; iChild2++) {
167
					Element fElement = (Element)fElements.item(iChild2);
168
					String name = fElement.getAttribute("name");
169
					if (properties.containsKey(name)) {
170
						System.out.println("Warning: duplicated fElement name: "+name+" in "+id+" fsElement.");
171
					} else {
172
						properties.put(name, fElement.getTextContent().trim());
173
					}
174
				}
175
			}
176
		}
177
	}
178
}
0 179

  
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/ImportTEIAnnotations.java (revision 1200)
1
package org.txm.annotation.urs.commands;
2

  
3
import java.io.File;
4

  
5
import org.eclipse.core.commands.AbstractHandler;
6
import org.eclipse.core.commands.ExecutionEvent;
7
import org.eclipse.core.commands.ExecutionException;
8
import org.eclipse.core.runtime.IProgressMonitor;
9
import org.eclipse.core.runtime.IStatus;
10
import org.eclipse.core.runtime.Status;
11
import org.kohsuke.args4j.Option;
12
import org.txm.annotation.urs.AnalecCorpora;
13
import org.txm.annotation.urs.Messages;
14
import org.txm.annotation.urs.imports.AnalecAnnotationsImporter;
15
import org.txm.rcp.swt.widget.parameters.ParametersDialog;
16
import org.txm.rcp.utils.JobHandler;
17
import org.txm.rcp.views.corpora.CorporaView;
18
import org.txm.searchengine.cqp.corpus.MainCorpus;
19
import org.txm.utils.logger.Log;
20

  
21
import visuAnalec.donnees.Corpus;
22
import visuAnalec.vue.Vue;
23
/**
24
 * Export the Analec annotation of the selected Corpus
25
 * 
26
 * @author mdecorde
27
 *
28
 */
29
public class ImportTEIAnnotations  extends AbstractHandler {
30

  
31
	@Option(name="directory",usage="the directory containing the XML-TEI-URS annotations files", widget="Folder", required=true, def="annotations")
32
	File directory;
33
	@Option(name="aamFile",usage="The Glozz model file", widget="FileOpen", required=true, def="model.aam")
34
	File aamFile;
35
	//@Option(name="standoffAnnotations",usage="select this if the directory contains standoff annotation files", widget="Boolean", required=true, def="false")
36
	//boolean standoffAnnotations;
37
	@Option(name="resetAnnotations",usage="Remove the old annotations", widget="Boolean", required=true, def="false")
38
	boolean resetAnnotations;
39
	/* (non-Javadoc)
40
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
41
	 */
42
	@Override
43
	public Object execute(ExecutionEvent event) throws ExecutionException {
44
		try {
45
			// Open the parameters input dialog box
46
			if (!ParametersDialog.open(this)) return null;
47

  
48
			Object first = CorporaView.getFirstSelectedObject();
49
			if (!(first instanceof org.txm.searchengine.cqp.corpus.CQPCorpus)) {
50
				System.out.println(Messages.ImportTEIAnnotations_0+first);
51
				return null;
52
			}
53
			
54
			final MainCorpus mainCorpus = ((org.txm.searchengine.cqp.corpus.CQPCorpus)first).getMainCorpus();
55
			final Corpus analecCorpus = AnalecCorpora.getCorpus(mainCorpus);
56
			final Vue vue = AnalecCorpora.getVue(mainCorpus);
57
			
58
			JobHandler job = new JobHandler(mainCorpus.getName()+Messages.ImportTEIAnnotations_1) {
59
				
60
				@Override
61
				protected IStatus run(IProgressMonitor monitor) {
62
					try {
63
						if (resetAnnotations) {
64
							analecCorpus.clearAnnot();
65
						}
66
						
67
						if (!importer(monitor, directory, aamFile, true, mainCorpus, analecCorpus, vue)) {
68
							System.out.println(Messages.ImportTEIAnnotations_2);
69
							return Status.CANCEL_STATUS;
70
						} else {
71
							return Status.OK_STATUS;
72
						}
73
					} catch (Throwable e) {
74
						System.out.println(Messages.ImportTEIAnnotations_3+e.getLocalizedMessage());
75
						Log.printStackTrace(e);
76
						return Status.CANCEL_STATUS;
77
					}
78
				}
79
			};
80
			job.schedule();
81
			
82
		} catch (Exception e) {
83
			System.out.println(Messages.ImportTEIAnnotations_4+e);
84
			Log.printStackTrace(e);
85
		}
86
		return null;
87
	}
88

  
89
	/**
90
	 * <pre>
91
	 * IProgressMonitor monitor = getIProgressMonitor();
92
	 * File directory = new File("resultdir");
93
	 * File aamFile = new File("model.aam");
94
	 * Boolean stdf = true;
95
	 * String name = "BROWN";
96
	 * MainCorpus mainCorpus = CorpusManager.getCorpusManager().getCorpus(name)
97
	 * Corpus analecCorpus = AnalecCorpora.getCorpus(name.toUpperCase());
98
	 * Vue vue = AnalecCorpora.getVue(name);
99
	 * 
100
     * ImportTEIAnnotations.importer(monitor, directory, aamFile, stdf, mainCorpus, analecCorpus, vue);
101
     *</pre>
102
	 * @param monitor
103
	 * @param annotationDirectory
104
	 * @param aamFile
105
	 * @param standoffAnnotations
106
	 * @param mainCorpus
107
	 * @param analecCorpus
108
	 * @param vue
109
	 * @return
110
	 * @throws Exception
111
	 */
112
	public static boolean importer(IProgressMonitor monitor, File annotationDirectory, File aamFile, boolean standoffAnnotations, MainCorpus mainCorpus, Corpus analecCorpus, Vue vue) throws Exception {
113
//		if (!standoffAnnotations) { // use stax because files are too big for DOM process
114
//			AnalecAnnotationsImporter importer = new AnalecAnnotationsImporter(monitor, annotationDirectory, mainCorpus, analecCorpus, vue);
115
//			boolean ret = importer.process();
116
//			if (ret) System.out.println("Done: "+analecCorpus.getToutesUnites().size()+" unites "+analecCorpus.getToutesRelations().size()+" relations "+analecCorpus.getTousSchemas().size()+" schemas.");
117
//			return ret;
118
//		} else {
119
//			DOMAnalecAnnotationsImporter importer = new DOMAnalecAnnotationsImporter(monitor, annotationDirectory, mainCorpus, analecCorpus, vue);
120
//			boolean ret = importer.process();
121
//			if (ret) System.out.println("Done: "+analecCorpus.getToutesUnites().size()+" unites "+analecCorpus.getToutesRelations().size()+" relations "+analecCorpus.getTousSchemas().size()+" schemas.");
122
//			return ret;
123
//		}
124
		//TODO: DOMAnalecAnnotationsImporter not finished
125
		AnalecAnnotationsImporter importer = new AnalecAnnotationsImporter(monitor, annotationDirectory, aamFile, mainCorpus, analecCorpus, vue);
126
		boolean ret = importer.process();
127
		
128
		if (ret) {
129
			System.out.println(Messages.ImportTEIAnnotations_5+analecCorpus.getToutesUnites().size()+Messages.ImportTEIAnnotations_6+analecCorpus.getToutesRelations().size()+Messages.ImportTEIAnnotations_7+analecCorpus.getTousSchemas().size()+Messages.ImportTEIAnnotations_8);
130
			mainCorpus.setIsModified(true);
131
			CorporaView.refreshObject(mainCorpus);
132
		}
133
		return ret;
134
	}
135
}
0 136

  
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/SaveCorpus.java (revision 1200)
1
package org.txm.annotation.urs.commands;
2

  
3
import java.io.File;
4

  
5
import org.eclipse.core.commands.AbstractHandler;
6
import org.eclipse.core.commands.ExecutionEvent;
7
import org.eclipse.core.commands.ExecutionException;
8
import org.eclipse.ui.IEditorPart;
9
import org.eclipse.ui.IEditorReference;
10
import org.eclipse.ui.IWorkbenchPage;
11
import org.eclipse.ui.handlers.HandlerUtil;
12
import org.txm.annotation.urs.AnalecCorpora;
13
import org.txm.annotation.urs.Messages;
14
import org.txm.edition.rcp.editors.SynopticEditionEditor;
15
import org.txm.rcp.TXMWindows;
16
import org.txm.rcp.views.corpora.CorporaView;
17
import org.txm.searchengine.cqp.corpus.MainCorpus;
18

  
19
import visuAnalec.donnees.Corpus;
20
import visuAnalec.fichiers.FichiersJava;
21

  
22
public class SaveCorpus  extends AbstractHandler {
23

  
24
	/** The ID. */
25
	public static String ID = "org.txm.analec.commands.LoadAnnotationStructure"; //$NON-NLS-1$
26
	Corpus corpus;
27
	/** The selection. */
28

  
29
	/* (non-Javadoc)
30
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
31
	 */
32
	@Override
33
	public Object execute(ExecutionEvent event) throws ExecutionException {
34

  
35
		Object first = CorporaView.getFirstSelectedObject();
36
		if (!(first instanceof org.txm.searchengine.cqp.corpus.CQPCorpus)) {
37
			System.out.println(Messages.SaveCorpus_0+first);
38
			return null;
39
		}
40
		final MainCorpus mainCorpus = ((org.txm.searchengine.cqp.corpus.CQPCorpus)first).getMainCorpus();
41
		save(mainCorpus, event);
42

  
43
		return null;
44
	}
45

  
46
	public static boolean save(final MainCorpus mainCorpus, ExecutionEvent event) {
47
		File binaryCorpusDirectory = mainCorpus.getProjectDirectory();
48
		File fichierCorpus = new File(binaryCorpusDirectory, "/analec/"+mainCorpus.getID()+".ec"); //$NON-NLS-1$ //$NON-NLS-2$
49
		Corpus corpus = AnalecCorpora.getCorpus(mainCorpus);
50
		System.out.println(Messages.SaveCorpus_3+corpus+Messages.SaveCorpus_1+fichierCorpus);
51
		if (!AnalecCorpora.saveCorpus(mainCorpus)) {
52
			System.out.println(Messages.SaveCorpus_5);
53
			return false;
54
		}
55

  
56
		mainCorpus.setIsModified(false);
57
		if (event != null) {
58
			HandlerUtil.getActiveShell(event).getDisplay().syncExec(new Runnable() {
59
				@Override
60
				public void run() {
61
					CorporaView.refreshObject(mainCorpus);
62
					
63
					// find out which editor is using the MainCorpus
64
					for (IWorkbenchPage page : TXMWindows.getActiveWindow().getPages()) {
65
						for (IEditorReference editor_ref : page.getEditorReferences()) {
66
							IEditorPart editor = editor_ref.getEditor(false);
67
							if (editor != null && editor instanceof SynopticEditionEditor) {
68
								if (mainCorpus.equals(((SynopticEditionEditor)editor).getCorpus())) {
69
									((SynopticEditionEditor) editor).fireIsDirty();
70
								}
71
							}
72
						}
73
					}
74
				}
75
			});
76
		}
77
		return true;
78
	}
79
}
0 80

  
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/ImportGlozzCorpus.java (revision 1200)
1
package org.txm.annotation.urs.commands;
2

  
3
import java.io.File;
4
import java.io.FilenameFilter;
5
import java.util.Arrays;
6

  
7
import org.apache.commons.io.FilenameUtils;
8
import org.eclipse.core.commands.AbstractHandler;
9
import org.eclipse.core.commands.ExecutionEvent;
10
import org.eclipse.core.commands.ExecutionException;
11
import org.eclipse.core.runtime.IProgressMonitor;
12
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.core.runtime.Status;
14
import org.kohsuke.args4j.Option;
15
import org.txm.Toolbox;
16
import org.txm.annotation.urs.AnalecAnnotationReIndexer;
17
import org.txm.annotation.urs.AnalecCorpora;
18
import org.txm.annotation.urs.Messages;
19
import org.txm.objects.Project;
20
import org.txm.rcp.handlers.scripts.ExecuteImportScript;
21
import org.txm.rcp.swt.widget.parameters.ParametersDialog;
22
import org.txm.rcp.utils.JobHandler;
23
import org.txm.searchengine.cqp.CQPSearchEngine;
24
import org.txm.searchengine.cqp.corpus.CorpusManager;
25
import org.txm.searchengine.cqp.corpus.MainCorpus;
26
import org.txm.utils.AsciiUtils;
27
import org.txm.utils.DeleteDir;
28
import org.txm.utils.io.IOUtils;
29
import org.txm.utils.logger.Log;
30

  
31
import visuAnalec.donnees.Corpus;
32
import visuAnalec.fichiers.FichiersGlozz;
33
import visuAnalec.fichiers.FichiersJava;
34

  
35
public class ImportGlozzCorpus  extends AbstractHandler {
36

  
37

  
38

  
39
	//	@Option(name="aafile",usage="an example file", widget="File", required=true, def="text.aa")
40
	//	File aafile;
41

  
42
	//	@Option(name="acfile",usage="an example file", widget="File", required=true, def="annotations.ac")
43
	//	File acfile
44

  
45
	@Option(name="glozzDirectory",usage="A folder containing the Glozz files: aa ac and aam", widget="Folder", required=true, def="glozz")
46
	File glozzDirectory;
47

  
48
	@Option(name="aamfile",usage="The aam file to use", widget="File", required=true, def="model.aam")
49
	File aamfile;
50
	private String name;
51

  
52
	/* (non-Javadoc)
53
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
54
	 */
55
	@Override
56
	public Object execute(ExecutionEvent event) throws ExecutionException {
57
		try {
58
			// Open the parameters input dialog box
59
			if (!ParametersDialog.open(this)) return null;
60

  
61
			// END OF PARAMETERS
62
			if (!glozzDirectory.exists()) {
63
				System.out.println(Messages.ImportGlozzCorpus_0);
64
				return null;
65
			}
66

  
67
			name = glozzDirectory.getName();
68
			name = AsciiUtils.buildId(name);
69

  
70
			final File srcDir = new File(glozzDirectory, name);
71
			System.out.println(Messages.ImportGlozzCorpus_1);
72
			DeleteDir.deleteDirectory(srcDir);
73
			srcDir.mkdir();
74

  
75
			final File ecDir = new File(glozzDirectory, "ec"); //$NON-NLS-1$
76
			System.out.println(Messages.ImportGlozzCorpus_3);
77
			DeleteDir.deleteDirectory(ecDir);
78
			ecDir.mkdir();
79

  
80

  
81
			if (!srcDir.exists()) {
82
				System.out.println(Messages.ImportGlozzCorpus_4);
83
				return null;
84
			}
85

  
86
			if (!ecDir.exists()) {
87
				System.out.println(Messages.ImportGlozzCorpus_5);
88
				return null;
89
			}
90

  
91
			// write the TXT file WITH paragraphs
92
			File[] aaFiles = glozzDirectory.listFiles(new FilenameFilter() {
93
				@Override
94
				public boolean accept(File dir, String name) {
95
					return name.endsWith(".aa"); //$NON-NLS-1$
96
				}
97
			});
98
			File[] acFiles = glozzDirectory.listFiles(new FilenameFilter() {
99
				@Override
100
				public boolean accept(File dir, String name) {
101
					return name.endsWith(".ac"); //$NON-NLS-1$
102
				}
103
			});
104

  
105
			if (aaFiles == null || aaFiles.length == 0) {
106
				System.out.println(Messages.ImportGlozzCorpus_8+glozzDirectory);
107
				return false;
108
			}
109
			if (acFiles == null || acFiles.length == 0) {
110
				System.out.println(Messages.ImportGlozzCorpus_9+glozzDirectory);
111
				return false;
112
			}
113
			if (aaFiles.length != acFiles.length) {
114
				System.out.println(Messages.ImportGlozzCorpus_10+glozzDirectory);
115
				return false;
116
			}
117

  
118
			System.out.println(Messages.ImportGlozzCorpus_11+glozzDirectory);
119
			Arrays.sort(acFiles);
120
			Arrays.sort(aaFiles);
121
			for (int i = 0 ; i < aaFiles.length ; i++) {
122
				File acFile = acFiles[i];
123
				File aaFile = aaFiles[i];
124
				String name = acFile.getName();
125
				int idx = name.indexOf("."); //$NON-NLS-1$
126
				if (idx > 0) name = name.substring(0, idx);
127

  
128
				File txtFile = new File(srcDir, name+".txt"); //$NON-NLS-1$
129
				File ecFile = new File(ecDir, name+".ec"); //$NON-NLS-1$
130
				Corpus tmpAnalecCorpus = new Corpus(); // need a temporary corpus
131

  
132
				if (!FichiersGlozz.importerGlozz(tmpAnalecCorpus, acFile, aaFile)) {
133
					System.out.println(Messages.ImportGlozzCorpus_15);
134
					return null;
135
				}
136

  
137
				final String texte = tmpAnalecCorpus.getTexte();
138
				int debParag = 0;
139
				Integer[] finPars = tmpAnalecCorpus.getFinParagraphes();
140
				StringBuffer newTexte = new StringBuffer(texte.length() + finPars.length);
141
				for (int iParagraph = 0 ; iParagraph < finPars.length ; iParagraph++) {
142
					newTexte.append(texte.substring(debParag, finPars[iParagraph])).append("\n"); //$NON-NLS-1$
143
					debParag = finPars[iParagraph];
144
				}
145

  
146
				IOUtils.write(txtFile, newTexte.toString()); // write the TXT file for TXM TXT import module
147
				FichiersJava.enregistrerCorpus(tmpAnalecCorpus, ecFile); // write for later
148

  
149
				if (!txtFile.exists()) {
150
					System.out.println(Messages.ImportGlozzCorpus_17);
151
					return null;
152
				}
153
			}
154

  
155
			Project project = Toolbox.workspace.getProject(name.toUpperCase());
156
			if (project != null) {
157
				CQPSearchEngine.getEngine().stop();
158
				project.delete();
159
			}
160
			project = new Project(Toolbox.workspace, name.toUpperCase());
161
			project.setName(name.toUpperCase());
162
			project.setSourceDirectory(srcDir.getAbsolutePath());
163
			project.setImportModuleName("txt");
164
			project.getEditionDefinition("default").setBuildEdition(true);
165
			
166
			JobHandler job = ExecuteImportScript.executeScript(project);
167
			if (job == null) { // job is scheduled in ExecuteImportScript.executeScript
168
				System.out.println(Messages.ImportGlozzCorpus_23);
169
				return null;
170
			}
171

  
172
			JobHandler job2 = new JobHandler(Messages.ImportGlozzCorpus_24) {
173

  
174
				@Override
175
				protected IStatus run(IProgressMonitor monitor) {
176
					try {
177
						MainCorpus corpus = CorpusManager.getCorpusManager().getCorpus(name.toUpperCase());
178
						if (corpus == null) {
179
							System.out.println("The CQP corpus was not created. Aborting.");
180
							return Status.CANCEL_STATUS;
181
						}
182
						Corpus analecCorpus = AnalecCorpora.getCorpus(corpus);
183
						analecCorpus.clearAll(); // remove all : annotations, structure
184
						File[] ecFiles = ecDir.listFiles();
185
						Arrays.sort(ecFiles);
186
						for (File ecFile : ecFiles) {
187
							FichiersJava.concatener(ecFile, analecCorpus);
188
						}
189

  
190
						System.out.println(Messages.ImportGlozzCorpus_25+aamfile);
191
						if (!FichiersGlozz.importerModeleGlozz(analecCorpus, aamfile)) {
192
							System.out.println(Messages.ImportGlozzCorpus_26);
193
							return Status.CANCEL_STATUS;
194
						}
195
						//					
196
						//					System.out.println("Importing Glozz corpus from: "+acfile+" and "+aafile);
197
						//					if (!FichiersGlozz.importerGlozz(analecCorpus, acfile, aafile)) {
198
						//						System.out.println("Error while importing Glozz corpus.");
199
						//						return null;
200
						//					}
201

  
202
						System.out.println(Messages.ImportGlozzCorpus_27);
203
						AnalecCorpora.removeCorpus(corpus); // remove old corpus if any
204

  
205
						AnalecAnnotationReIndexer aari = new AnalecAnnotationReIndexer(corpus, analecCorpus);
206
						if (!aari.process()) {
207
							System.out.println(Messages.ImportGlozzCorpus_28);
208
							return Status.CANCEL_STATUS;
209
						}
210

  
211
						System.out.println(Messages.ImportGlozzCorpus_29);
212
						AnalecCorpora.saveCorpus(analecCorpus);
213
						AnalecCorpora.getVue(analecCorpus).retablirVueParDefaut();
214
						System.out.println(Messages.ImportGlozzCorpus_30);
215
						analecCorpus.setTexte(""); // free memory //$NON-NLS-1$
216
						DeleteDir.deleteDirectory(ecDir); // cleaning
217
						DeleteDir.deleteDirectory(srcDir); // cleaning
218

  
219
						return Status.OK_STATUS;
220
					} catch (Exception e) {
221
						System.out.println(Messages.ImportGlozzCorpus_32+e.getLocalizedMessage());
222
						Log.printStackTrace(e);
223
						return Status.CANCEL_STATUS;
224
					}
225
				}
226
			};
227
			job2.startJob(true); // wait for the TXT import job to finish
228
			return null;
229
		} catch (Exception e) {
230
			// TODO Auto-generated catch block
231
			e.printStackTrace();
232
		}
233
		return null;
234
	}
235
}
0 236

  
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/LoadVue.java (revision 1200)
1
package org.txm.annotation.urs.commands;
2

  
3
import java.io.File;
4

  
5
import org.eclipse.core.commands.AbstractHandler;
6
import org.eclipse.core.commands.ExecutionEvent;
7
import org.eclipse.core.commands.ExecutionException;
8
import org.eclipse.jface.viewers.ISelection;
9
import org.eclipse.jface.viewers.IStructuredSelection;
10
import org.eclipse.ui.handlers.HandlerUtil;
11
import org.txm.Toolbox;
12
import org.txm.annotation.urs.AnalecCorpora;
13
import org.txm.annotation.urs.Messages;
14
import org.txm.rcp.views.corpora.CorporaView;
15
import org.txm.searchengine.cqp.corpus.MainCorpus;
16

  
17
import visuAnalec.donnees.Corpus;
18
import visuAnalec.fichiers.FichiersJava;
19
import visuAnalec.vue.Vue;
20

  
21
public class LoadVue  extends AbstractHandler {
22

  
23
	/** The ID. */
24
	public static String ID = "org.txm.analec.commands.LoadAnnotationStructure"; //$NON-NLS-1$
25

  
26
	/** The selection. */
27

  
28
	/* (non-Javadoc)
29
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
30
	 */
31
	@Override
32
	public Object execute(ExecutionEvent event) throws ExecutionException {
33
		
34
		Object first = CorporaView.getFirstSelectedObject();
35
		if (!(first instanceof org.txm.searchengine.cqp.corpus.CQPCorpus)) {
36
			System.out.println(Messages.LoadVue_0+first);
37
			return null;
38
		}
39
		
40
		MainCorpus mainCorpus = ((org.txm.searchengine.cqp.corpus.CQPCorpus)first).getMainCorpus();
41
		
42
		load(mainCorpus);
43
		return null;
44
	}
45
	
46
	public boolean load(MainCorpus mainCorpus) {
47
		System.out.println(Messages.LoadVue_1+mainCorpus.getName());
48
		Vue vue = AnalecCorpora.getVue(mainCorpus);
49
		if (!FichiersJava.ouvrirVue(vue)) {
50
			System.out.println(Messages.LoadVue_2);
51
			return false;
52
		}
53
		
54
		System.out.println(Messages.LoadVue_3);
55
		return true;
56
	}
57
}
0 58

  
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/LoadStructure.java (revision 1200)
1
package org.txm.annotation.urs.commands;
2

  
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.jface.viewers.ISelection;
7
import org.eclipse.jface.viewers.IStructuredSelection;
8
import org.eclipse.ui.handlers.HandlerUtil;
9
import org.txm.annotation.urs.AnalecCorpora;
10
import org.txm.annotation.urs.Messages;
11
import org.txm.rcp.views.corpora.CorporaView;
12
import org.txm.searchengine.cqp.corpus.MainCorpus;
13

  
14
import visuAnalec.donnees.Corpus;
15
import visuAnalec.donnees.VisuStructure;
16
import visuAnalec.fichiers.FichiersJava;
17

  
18
public class LoadStructure  extends AbstractHandler {
19

  
20
	/** The ID. */
21
	public static String ID = "org.txm.analec.commands.LoadAnnotationStructure"; //$NON-NLS-1$
22

  
23
	/** The selection. */
24

  
25
	/* (non-Javadoc)
26
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
27
	 */
28
	@Override
29
	public Object execute(ExecutionEvent event) throws ExecutionException {
30
		
31
		Object first = CorporaView.getFirstSelectedObject();
32
		if (!(first instanceof org.txm.searchengine.cqp.corpus.CQPCorpus)) {
33
			System.out.println(Messages.LoadStructure_0+first);
34
			return null;
35
		}
36
		
37
		MainCorpus mainCorpus = ((org.txm.searchengine.cqp.corpus.CQPCorpus)first).getMainCorpus();
38
		Corpus corpus = AnalecCorpora.getCorpus(mainCorpus);
39
//		if (VisuStructure.isOpen()) {
40
//			System.out.println("Structure de corpus en cours d'édition. Abandon.");
41
//			return null;
42
//		}
43
		
44
		
45
		return null;
46
	}
47
	
48
	public static boolean load(Corpus corpus) {
49
		System.out.println(Messages.LoadStructure_1+corpus);
50
		if (!FichiersJava.ouvrirStructure(corpus)) {
51
			System.out.println(Messages.LoadStructure_2);
52
			return false;
53
		}
54
		System.out.println(Messages.LoadStructure_3);
55
		return true;
56
	}
57
}
0 58

  
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/ExportGlozzCorpus.java (revision 1200)
1
package org.txm.annotation.urs.commands;
2

  
3
import java.io.File;
4
import java.io.IOException;
5

  
6
import org.eclipse.core.commands.AbstractHandler;
7
import org.eclipse.core.commands.ExecutionEvent;
8
import org.eclipse.core.commands.ExecutionException;
9
import org.eclipse.core.runtime.IProgressMonitor;
10
import org.eclipse.core.runtime.IStatus;
11
import org.eclipse.core.runtime.Status;
12
import org.kohsuke.args4j.Option;
13
import org.txm.annotation.urs.Messages;
14
import org.txm.annotation.urs.export.ExportToGlozzMacro;
15
import org.txm.rcp.swt.widget.parameters.ParametersDialog;
16
import org.txm.rcp.utils.JobHandler;
17
import org.txm.rcp.views.corpora.CorporaView;
18
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
19
import org.txm.searchengine.cqp.corpus.MainCorpus;
20
import org.txm.searchengine.cqp.serverException.CqiServerError;
21
import org.txm.utils.logger.Log;
22

  
23
public class ExportGlozzCorpus  extends AbstractHandler {
24

  
25
	@Option(name="exportDirectory",usage="the result directory ", widget="Folder", required=true, def="result directory")
26
	File exportDirectory;
27
	@Option(name="unit_type",usage="A unit type to export", widget="String", required=true, def="MENTION")
28
	String unit_type;
29

  
30
	/* (non-Javadoc)
31
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
32
	 */
33
	@Override
34
	public Object execute(ExecutionEvent event) throws ExecutionException {
35
		try {
36
			// Open the parameters input dialog box
37
			if (!ParametersDialog.open(this)) return null;
38

  
39
			Object first = CorporaView.getFirstSelectedObject();
40
			if (!(first instanceof org.txm.searchengine.cqp.corpus.CQPCorpus)) {
41
				System.out.println(Messages.ExportGlozzCorpus_0+first);
42
				return null;
43
			}
44

  
45
			final MainCorpus mainCorpus = ((org.txm.searchengine.cqp.corpus.CQPCorpus)first).getMainCorpus();
46

  
47
			JobHandler job = new JobHandler(mainCorpus.getName()+Messages.ExportGlozzCorpus_1) {
48

  
49
				@Override
50
				protected IStatus run(IProgressMonitor monitor) {
51
					this.runInit(monitor);
52
					try {
53
						export(exportDirectory, mainCorpus, unit_type);
54
					} catch (ThreadDeath e) {
55
						System.out.println(Messages.ExportGlozzCorpus_2);
56
					} catch (Throwable e) {
57
						System.out.println(Messages.ExportGlozzCorpus_3+e.getLocalizedMessage());
58
						Log.printStackTrace(e);
59
						return Status.CANCEL_STATUS;
60
					}
61
					return Status.OK_STATUS;
62
				}
63
			};
64
			job.schedule();
65

  
66
			return null;
67
		} catch (Throwable e) {
68
			System.out.println(Messages.ExportGlozzCorpus_4+e.getLocalizedMessage());
69
			Log.printStackTrace(e);
70
		}
71
		return null;
72
	}
73
	
74
	public static void export(File exportDirectory, MainCorpus mainCorpus, String unit_type) throws NumberFormatException, IOException, CqiServerError, CqiClientException {
75
		ExportToGlozzMacro exporter = new ExportToGlozzMacro();
76
		File exportFile = new File(exportDirectory, mainCorpus.getID());
77
		exporter.doExport(mainCorpus, unit_type, exportFile.getAbsolutePath());
78
		return;
79
	}
80
}
0 81

  
tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/commands/EditVue.java (revision 1200)
1
package org.txm.annotation.urs.commands;
2

  
3
import java.awt.Dimension;
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff