Revision 2466

tmp/org.txm.properties.core/src/org/txm/properties/core/functions/Properties.java (revision 2466)
74 74
	 *            a MainCorpus or a SubCorpus
75 75
	 */
76 76
	public Properties(TXMResult selection) {
77
		super(null, selection);
77
		this(null, selection);
78 78
	}
79 79
	
80 80
	/**
tmp/org.txm.properties.core/src/org/txm/properties/core/functions/CorpusPropertiesComputer.java (revision 2466)
27 27
import org.txm.searchengine.cqp.corpus.WordProperty;
28 28
import org.txm.utils.logger.Log;
29 29

  
30
public class CorpusPropertiesComputer extends PropertiesComputer<CQPCorpus>{
31

  
30
public class CorpusPropertiesComputer extends PropertiesComputer<CQPCorpus> {
31
	
32 32
	public CorpusPropertiesComputer(Properties props, CQPCorpus result) {
33 33
		super(props, result);
34 34
	}
35

  
35
	
36 36
	@Override
37 37
	public List<String> getComputableInformations() {
38 38
		return Arrays.asList("all");
39 39
	}
40

  
40
	
41 41
	@Override
42 42
	public LinkedHashMap<String, String> getInformation(String name) {
43
		LinkedHashMap<String, String> data = new LinkedHashMap<String, String>();
43
		LinkedHashMap<String, String> data = new LinkedHashMap<>();
44 44
		data.put("all", dump(props.pMaxPropertiesToDisplay));
45 45
		return data;
46 46
	}
47

  
47
	
48 48
	@Override
49 49
	public String getInformationHTML(String info) {
50 50
		return htmlDump();
51 51
	}
52

  
52
	
53 53
	// Numbers
54 54
	/** The T. */
55 55
	int numberOfWords = 0; // number of word
56

  
56
	
57 57
	/** The N properties. */
58 58
	int NProperties = 0; // number of word properties
59 59
	// HashMap<String, Integer> propertiesCounts = new HashMap<String, Integer>();
60 60
	// // properties counts
61
	
61 62
	/** The properties values. */
62
	HashMap<String, List<String>> propertiesValues = new HashMap<String, List<String>>(); // properties values
63

  
63
	HashMap<String, List<String>> propertiesValues = new HashMap<>(); // properties values
64
	
64 65
	/** The N structures. */
65 66
	int NStructures = 0; // number of structures
66

  
67
	
67 68
	/** The structures counts. */
68
	HashMap<String, Integer> structuresCounts = new HashMap<String, Integer>(); // structures counts
69

  
69
	HashMap<String, Integer> structuresCounts = new HashMap<>(); // structures counts
70
	
70 71
	/** The internal architecture. */
71
	List<String> internalArchitecture = new ArrayList<String>(); // cqp structures = propertiesCounts keys but ordered
72

  
72
	List<String> internalArchitecture = new ArrayList<>(); // cqp structures = propertiesCounts keys but ordered
73
	
73 74
	/** The hierarchie counts. */
74
	HashMap<String, Integer> hierarchieCounts = new HashMap<String, Integer>(); // hierarchic structures counts
75

  
75
	HashMap<String, Integer> hierarchieCounts = new HashMap<>(); // hierarchic structures counts
76
	
76 77
	/** The internal architecture properties. */
77
	HashMap<String, HashMap<String, List<String>>> internalArchitectureProperties = new HashMap<String, HashMap<String, List<String>>>(); // hierarchic structures counts
78

  
78
	HashMap<String, HashMap<String, List<String>>> internalArchitectureProperties = new HashMap<>(); // hierarchic structures counts
79
	
79 80
	/** The internal architecture properties counts. */
80
	HashMap<String, HashMap<String, Integer>> internalArchitecturePropertiesCounts = new HashMap<String, HashMap<String, Integer>>(); // hierarchic structures counts
81

  
81
	HashMap<String, HashMap<String, Integer>> internalArchitecturePropertiesCounts = new HashMap<>(); // hierarchic structures counts
82
	
82 83
	// Annotations description
83 84
	/** The annotations types. */
84
	HashMap<String, Integer> annotationsTypes = new HashMap<String, Integer>(); // for each annotation its description
85

  
85
	HashMap<String, Integer> annotationsTypes = new HashMap<>(); // for each annotation its description
86
	
86 87
	/** The annotations origins. */
87
	HashMap<String, Integer> annotationsOrigins = new HashMap<String, Integer>(); // for each annoation its origin description
88

  
88
	HashMap<String, Integer> annotationsOrigins = new HashMap<>(); // for each annoation its origin description
89
	
89 90
	/** The properties. */
90 91
	List<WordProperty> properties;
91

  
92
	
92 93
	/** The structures. */
93 94
	List<StructuralUnit> structures;
94 95
	
96
	@Override
95 97
	public String getName() {
96 98
		String filename = result.getMainCorpus() + "-" + result.getName(); //$NON-NLS-1$
97 99
		if (result instanceof MainCorpus) {
......
106 108
	public void stepGeneralInfos() {
107 109
		try {
108 110
			properties = result.getProperties();
109
			List<WordProperty> pproperties = new ArrayList<WordProperty>(properties);
111
			List<WordProperty> pproperties = new ArrayList<>(properties);
110 112
			for (WordProperty p : properties) {
111 113
				if (p.getName().equals("id")) {
112 114
					pproperties.remove(p);
......
114 116
			}
115 117
			properties = pproperties;
116 118
			NProperties = properties.size();
117
		} catch (CqiClientException e) {
119
		}
120
		catch (CqiClientException e) {
118 121
			Log.severe(TXMCoreMessages.bind(PropertiesCoreMessages.error_failedToAccessPropertieOfCorpusP0, result.getName()));
119 122
			Log.printStackTrace(e);
120 123
			return;
121 124
		}
122

  
125
		
123 126
		try {
124 127
			numberOfWords = result.getSize();// corpus.getLexicon(corpus.getProperty("id")).nbrOfToken();
125
		} catch (CqiClientException e) {
128
		}
129
		catch (CqiClientException e) {
126 130
			Log.severe(TXMCoreMessages.bind(PropertiesCoreMessages.error_failedToAccessLexiconOfCorpusP0, result.getName()));
127 131
			Log.printStackTrace(e);
128 132
			return;
129 133
		}
130 134
	}
131

  
135
	
132 136
	/**
133 137
	 * step2. randomly position are choose
134 138
	 */
135 139
	public void stepLexicalProperties() {
136 140
		propertiesValues.clear();
137

  
141
		
138 142
		AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient();
139 143
		for (Property p : properties) {
140 144
			// int size;
......
144 148
				// propertiesCounts.put(p.getName(), size);
145 149
				// List<String> list =
146 150
				// Arrays.asList(corpus.getLexicon(p).getForms(this.maxvalue));
147

  
151
				
148 152
				int[] positions = new int[Math.min(props.pMaxPropertiesToDisplay, numberOfWords)];
149 153
				for (int i = 0; i < Math.min(props.pMaxPropertiesToDisplay, numberOfWords); i++) {
150 154
					positions[i] = i;
151 155
				}
152

  
156
				
153 157
				// ArrayList<String> values = new ArrayList<String>();
154
				LinkedHashSet<String> values = new LinkedHashSet<String>(cqiClient.getSingleData(p, positions));
155
				propertiesValues.put(p.getName(), new ArrayList<String>(values));
156
			} catch (Exception e) {
158
				LinkedHashSet<String> values = new LinkedHashSet<>(cqiClient.getSingleData(p, positions));
159
				propertiesValues.put(p.getName(), new ArrayList<>(values));
160
			}
161
			catch (Exception e) {
157 162
				Log.printStackTrace(e);
158 163
			}
159 164
		}
160 165
	}
161

  
166
	
162 167
	/**
163 168
	 * Step structural units.
164 169
	 */
165 170
	public void stepStructuralUnits() {
166 171
		try {
167 172
			structures = result.getOrderedStructuralUnits();
168

  
169
			List<StructuralUnit> sstructures = new ArrayList<StructuralUnit>(structures);
173
			
174
			List<StructuralUnit> sstructures = new ArrayList<>(structures);
170 175
			for (StructuralUnit su : structures) {
171 176
				if (su.getName().equals("txmcorpus")) {
172 177
					sstructures.remove(su);
173 178
				}
174 179
			}
175 180
			structures = sstructures;
176
		} catch (CqiClientException e) {
181
		}
182
		catch (CqiClientException e) {
177 183
			Log.severe(TXMCoreMessages.bind(PropertiesCoreMessages.error_failedToAccessStructuresOfCorpusP0, result.getName()));
178 184
			Log.printStackTrace(e);
179 185
			return;
......
185 191
			hierarchieCounts.put(su.getName(), -1);
186 192
			internalArchitectureProperties.put(su.getName(), new HashMap<String, List<String>>());
187 193
			internalArchitecturePropertiesCounts.put(su.getName(), new HashMap<String, Integer>());
188

  
194
			
189 195
			if (su.getProperties().size() > 0) {
190 196
				for (StructuralUnitProperty sup : su.getProperties()) {// for each of its property
191 197
					try {
192 198
						List<String> allvalues = sup.getValues(result);
193 199
						internalArchitectureProperties.get(su.getName()).put(sup.getName(), allvalues.subList(0, Math.min(allvalues.size(), props.pMaxPropertiesToDisplay)));
194 200
						internalArchitecturePropertiesCounts.get(su.getName()).put(sup.getName(), allvalues.size());
195
					} catch (Exception e) {
196
						ArrayList<String> list = new ArrayList<String>(1);
201
					}
202
					catch (Exception e) {
203
						ArrayList<String> list = new ArrayList<>(1);
197 204
						list.add(PropertiesCoreMessages.error);
198 205
						internalArchitectureProperties.get(su.getName()).put(sup.getName(), list);
199 206
						internalArchitecturePropertiesCounts.get(su.getName()).put(sup.getName(), -1);
......
210 217
	 */
211 218
	public String htmlDump() {
212 219
		StringBuffer buff = new StringBuffer();
213

  
220
		
214 221
		buff.append("<? version=\"1.0\" encoding=\"UTF-8\"?>\n" + //$NON-NLS-1$
215 222
				"<html>" + //$NON-NLS-1$
216 223
				"<head>" + //$NON-NLS-1$
217 224
				"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>" + //$NON-NLS-1$
218 225
				"</head>" + //$NON-NLS-1$
219 226
				"<body>\n"); //$NON-NLS-1$
220
		buff.append("<h2 style'font-family:\"Arial\";'>" + PropertiesCoreMessages.descriptionOf + this.result.getName() + " (id=" + this.result.getID() + ")</h2>\n"); //$NON-NLS-2$ //$NON-NLS-1$
221

  
227
		buff.append("<h2 style'font-family:\"Arial\";'>" + PropertiesCoreMessages.descriptionOf + this.result.getName() + " (CQP ID=" + this.result.getID() + ")</h2>\n"); //$NON-NLS-2$ //$NON-NLS-1$
228
		
222 229
		Project projet = this.result.getProject();
223
		if (projet.getCreationDate() != null) {
224
			buff.append(NLS.bind(PropertiesCoreMessages.createdTheP0, TXMResult.PRETTY_LOCALIZED_TIME_FORMAT.format(projet.getCreationDate())));
225
		}
226
		if (projet.getLastComputingDate() != null) {
227
			buff.append(NLS.bind(PropertiesCoreMessages.updatedTheP0, TXMResult.PRETTY_LOCALIZED_TIME_FORMAT.format(projet.getLastComputingDate())));
228
		}
229
		
230
		// if (projet.getCreationDate() != null) {
231
		// buff.append(NLS.bind(PropertiesCoreMessages.createdTheP0, TXMResult.PRETTY_LOCALIZED_TIME_FORMAT.format(projet.getCreationDate())));
232
		// }
233
		// if (projet.getLastComputingDate() != null) {
234
		// buff.append(NLS.bind(PropertiesCoreMessages.updatedTheP0, TXMResult.PRETTY_LOCALIZED_TIME_FORMAT.format(projet.getLastComputingDate())));
235
		// }
236
		//
230 237
		if (projet.getDescription() != null && projet.getDescription().length() > 0) {
231 238
			buff.append("<p><h3>Description</h3>" + projet.getDescription() + "</p>"); //$NON-NLS-1$ //$NON-NLS-2$
232 239
		}
233

  
240
		
234 241
		buff.append("<h3 style'font-family:\"Arial\";'>" + PropertiesCoreMessages.generalStatistics_2 + "</h3>\n"); //$NON-NLS-1$ //$NON-NLS-2$
235

  
242
		
236 243
		// counts
237 244
		buff.append("<ul>\n"); //$NON-NLS-1$
238 245
		buff.append("<li>" + NLS.bind(PropertiesCoreMessages.numberOfWordsP0, numberOfWords) + "</li>\n"); //$NON-NLS-1$ //$NON-NLS-2$
239

  
240
		buff.append("<li>" + PropertiesCoreMessages.numberOfWordProperties + (properties.size()) + " ("+StringUtils.join(properties, ", ")+")</li>\n"); //$NON-NLS-2$ //$NON-NLS-1$
241
		buff.append("<li>" + PropertiesCoreMessages.numberOfStructuralUnits + (structures.size()) + " ("+StringUtils.join(structures, ", ")+")</li>\n"); //$NON-NLS-2$ //$NON-NLS-1$
246
		
247
		buff.append("<li>" + PropertiesCoreMessages.numberOfWordProperties + (properties.size()) + " (" + StringUtils.join(properties, ", ") + ")</li>\n"); //$NON-NLS-2$ //$NON-NLS-1$
248
		buff.append("<li>" + PropertiesCoreMessages.numberOfStructuralUnits + (structures.size()) + " (" + StringUtils.join(structures, ", ") + ")</li>\n"); //$NON-NLS-2$ //$NON-NLS-1$
242 249
		buff.append("</ul>\n"); //$NON-NLS-1$
243

  
250
		
244 251
		// Propriétés d'occurrences
245 252
		buff.append("<h3 style'font-family:\"Arial\";'>" + NLS.bind(PropertiesCoreMessages.lexicalUnitsPropertiesMaxP0Values, props.pMaxPropertiesToDisplay) + "</h3>\n"); //$NON-NLS-1$ //$NON-NLS-2$
246
		ArrayList<String> properties = new ArrayList<String>(propertiesValues.keySet());
253
		ArrayList<String> properties = new ArrayList<>(propertiesValues.keySet());
247 254
		Collections.sort(properties);
248 255
		buff.append("<ul>\n"); //$NON-NLS-1$
249 256
		for (String s : properties) {
......
260 267
			}
261 268
		}
262 269
		buff.append("</ul>\n"); //$NON-NLS-1$
263

  
270
		
264 271
		// Propriété de structures
265 272
		buff.append("<h3 style'font-family:\"Arial\";'>" + NLS.bind(PropertiesCoreMessages.structuralUnitsPropertiesMaxP0Values, props.pMaxPropertiesToDisplay) + "</h3>\n"); //$NON-NLS-1$ //$NON-NLS-2$
266 273
		buff.append("<ul>\n"); //$NON-NLS-1$
......
268 275
			StringBuffer subbuffer = new StringBuffer();
269 276
			if (s.equals("txmcorpus")) //$NON-NLS-1$
270 277
				continue;// ignore the txmcorpus structure
271

  
272
			properties = new ArrayList<String>(internalArchitectureProperties.get(s).keySet());
273

  
278
			
279
			properties = new ArrayList<>(internalArchitectureProperties.get(s).keySet());
280
			
274 281
			subbuffer.append("<li> " + s + "\n<ul>\n"); //$NON-NLS-1$ //$NON-NLS-2$
275 282
			if (internalArchitectureProperties.get(s).keySet().size() == 0)
276 283
				subbuffer.append("<li>" + PropertiesCoreMessages.noProperty + "</li>\n"); //$NON-NLS-1$ //$NON-NLS-2$
277

  
284
			
278 285
			// System.out.println("struct: "+s+" >> "+properties);
279 286
			Collections.sort(properties);
280 287
			// System.out.println("struct: "+s+" >sort> "+properties);
......
284 291
				{
285 292
					// System.out.println("struct: "+s+" >> "+ps);
286 293
					int valuecount = internalArchitecturePropertiesCounts.get(s).get(ps);
287
					ArrayList<String> values = new ArrayList<String>(internalArchitectureProperties.get(s).get(ps));
294
					ArrayList<String> values = new ArrayList<>(internalArchitectureProperties.get(s).get(ps));
288 295
					subbuffer.append("<li> " + ps + " (" + valuecount + ") = "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
289 296
					// System.out.println("VALUES: "+values);
290 297
					Collections.sort(values);
......
295 302
							subbuffer.append(psv.replace("<", "&lt;")); //$NON-NLS-1$ //$NON-NLS-2$
296 303
						else
297 304
							subbuffer.append("\"\""); //$NON-NLS-1$
298

  
305
						
299 306
						if (i == values.size() - 1)
300 307
							subbuffer.append("."); //$NON-NLS-1$
301 308
						else
302 309
							subbuffer.append(", "); //$NON-NLS-1$
303

  
310
						
304 311
						if (i >= props.pMaxPropertiesToDisplay) {
305 312
							subbuffer.append("..."); //$NON-NLS-1$
306 313
							break;
......
322 329
		buff.append("</ul>\n"); //$NON-NLS-1$
323 330
		buff.append("</body>\n"); //$NON-NLS-1$
324 331
		buff.append("</html>\n"); //$NON-NLS-1$
325

  
332
		
326 333
		return buff.toString();
327 334
	}
328

  
335
	
329 336
	/**
330 337
	 * dump the result in the console.
331 338
	 *
......
335 342
	 */
336 343
	public String dump(int maxvalue) {
337 344
		StringBuffer buff = new StringBuffer();
338

  
345
		
339 346
		buff.append(PropertiesCoreMessages.generalStatistics);
340 347
		buff.append(PropertiesCoreMessages.t + String.format(Locale.FRANCE, "%,d", numberOfWords) + "\n"); //$NON-NLS-1$
341 348
		buff.append(PropertiesCoreMessages.wordProperties + String.format("%,d", NProperties) + "\n"); //$NON-NLS-1$
......
347 354
		buff.append(PropertiesCoreMessages.s + String.format("%,d", NStructures) + "\n"); //$NON-NLS-1$
348 355
		for (String s : structuresCounts.keySet())
349 356
			buff.append(" - " + s + "\n");// +structuresCounts.get(s)+"\n"); //$NON-NLS-1$ //$NON-NLS-2$
350

  
357
			
351 358
		/*
352 359
		 * buff.append("* Structural Units counts\n"); for(String s :
353 360
		 * internalArchitecture) buff.append(" - "+s+" "+hierarchieCounts.get(s)+"\n");
......
359 366
				if (!(s.equals("text") && (ps.equals("project") || ps.equals("base") || ps.equals("id")))) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
360 367
				{
361 368
					buff.append("   - " + ps + "(" + internalArchitectureProperties.get(s).get(ps).size() + ") = "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
362

  
369
					
363 370
					int valuecount = 0;
364 371
					for (String psv : internalArchitectureProperties.get(s).get(ps)) {
365 372
						buff.append(psv);
......
370 377
						if (valuecount < internalArchitectureProperties.get(s).get(ps).size())
371 378
							buff.append(", "); //$NON-NLS-1$
372 379
					}
373

  
380
					
374 381
					buff.append("\n"); //$NON-NLS-1$
375 382
				}
376 383
			}
377 384
		}
378

  
385
		
379 386
		return buff.toString();
380 387
	}
381 388
	
382

  
389
	
383 390
	/**
384 391
	 * Gets the t.
385 392
	 *
......
388 395
	public int getT() {
389 396
		return numberOfWords;
390 397
	}
391

  
398
	
392 399
	/**
393 400
	 * Gets the n properties.
394 401
	 *
......
397 404
	public int getNProperties() {
398 405
		return NProperties;
399 406
	}
400

  
407
	
401 408
	/**
402 409
	 * Gets the internal architecture.
403 410
	 *
......
406 413
	public List<String> getInternalArchitecture() {
407 414
		return internalArchitecture;
408 415
	}
409

  
416
	
410 417
	/**
411 418
	 * Gets the n structures.
412 419
	 *
......
415 422
	public int getNStructures() {
416 423
		return NStructures;
417 424
	}
418

  
425
	
419 426
	/**
420 427
	 * Gets the structures counts.
421 428
	 *
......
424 431
	public HashMap<String, Integer> getStructuresCounts() {
425 432
		return structuresCounts;
426 433
	}
427

  
434
	
428 435
	/**
429 436
	 * Gets the annotations types.
430 437
	 *
......
433 440
	public HashMap<String, Integer> getAnnotationsTypes() {
434 441
		return annotationsTypes;
435 442
	}
436

  
443
	
437 444
	/**
438 445
	 * Gets the annotations origins.
439 446
	 *
......
442 449
	public HashMap<String, Integer> getAnnotationsOrigins() {
443 450
		return annotationsOrigins;
444 451
	}
445

  
452
	
446 453
	@Override
447 454
	public boolean _compute(IProgressMonitor monitor) throws Exception {
448

  
455
		
449 456
		if (monitor != null) monitor.beginTask(props.getComputingStartMessage(), 3);
450 457
		this.stepGeneralInfos();
451 458
		if (monitor != null) monitor.worked(1);
452

  
459
		
453 460
		this.stepLexicalProperties();
454 461
		if (monitor != null) monitor.worked(1);
455

  
462
		
456 463
		this.stepStructuralUnits();
457 464
		if (monitor != null) monitor.worked(1);
458 465
		return true;
......
461 468
	public String getDetails() {
462 469
		if (numberOfWords >= 0) {
463 470
			return NLS.bind(PropertiesCoreMessages.numberOfWordsP0, numberOfWords);
464
		} else {
471
		}
472
		else {
465 473
			return "";
466 474
		}
467 475
	}

Also available in: Unified diff