Révision 933

tmp/org.txm.properties.core/plugin.xml (revision 933)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>
4
   <extension
5
         point="org.eclipse.core.runtime.preferences">
6
      <initializer
7
            class="org.txm.properties.core.preferences.PropertiesPreferences">
8
      </initializer>
9
   </extension>
10

  
11
</plugin>
0 12

  
tmp/org.txm.properties.core/.settings/org.eclipse.core.resources.prefs (revision 933)
1
eclipse.preferences.version=1
2
encoding//src/org/txm/properties/core/messages/messages_fr.properties=UTF-8
0 3

  
tmp/org.txm.properties.core/.settings/org.eclipse.jdt.core.prefs (revision 933)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4
org.eclipse.jdt.core.compiler.compliance=1.6
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7
org.eclipse.jdt.core.compiler.source=1.6
0 8

  
tmp/org.txm.properties.core/.classpath (revision 933)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
5
		<accessrules>
6
			<accessrule kind="accessible" pattern="**"/>
7
		</accessrules>
8
	</classpathentry>
9
	<classpathentry kind="src" path="src"/>
10
	<classpathentry kind="output" path="bin"/>
11
</classpath>
0 12

  
tmp/org.txm.properties.core/META-INF/MANIFEST.MF (revision 933)
1
Manifest-Version: 1.0
2
Export-Package: org.txm.properties.core,
3
 org.txm.properties.core.functions,
4
 org.txm.properties.core.messages,
5
 org.txm.properties.core.preferences
6
Require-Bundle: org.txm.searchengine.cqp.core;bundle-version="1.1.0";visibility:=reexport
7
Bundle-Vendor: Textometrie.org
8
Bundle-Version: 1.0.0.qualifier
9
Bundle-Name: Corpus Properties Core
10
Bundle-ManifestVersion: 2
11
Bundle-SymbolicName: org.txm.properties.core;singleton:=true
12
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
13

  
0 14

  
tmp/org.txm.properties.core/.project (revision 933)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.properties.core</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  
tmp/org.txm.properties.core/src/org/txm/properties/core/messages/messages_ru.properties (revision 933)
1

  
2
RESULT_TYPE = 
0 3

  
tmp/org.txm.properties.core/src/org/txm/properties/core/messages/messages_fr.properties (revision 933)
1

  
2
Properties_0  = <h3>Propriétés des structures\n
3
Properties_1  = ** Echec d'accès au corpus
4
Properties_11 = \ structures
5
Properties_14 = Propriétés des unités lexicales (max {0} valeurs)
6
Properties_16 = Nombre d'unités de structure 
7
Properties_2  = ** Erreur
8
Properties_22 = Propriétés des structures (max {0} valeurs)
9
Properties_26 = Pas de propriété
10
Properties_3  = Détails du corpus CQP 
11
Properties_4  = \ propriétés
12
Properties_40 = * Statistiques Générales\n
13
Properties_41 = - T
14
Properties_43 = - Propriétés de mot 
15
Properties_49 = - S
16
Properties_5  = Statistiques Générales
17
Properties_6  = ** Echec d'accès au corpus
18
Properties_7  = Nombre de mots 
19
Properties_8  = \ lexique
20
Properties_9  = Nombre de propriétés de mot 
21

  
22
RESULT_TYPE = Propriétés
0 23

  
tmp/org.txm.properties.core/src/org/txm/properties/core/messages/PropertiesCoreMessages.java (revision 933)
1
package org.txm.properties.core.messages;
2

  
3
import org.eclipse.osgi.util.NLS;
4
import org.txm.utils.messages.Utf8NLS;
5

  
6

  
7
/**
8
 * Properties core messages.
9
 * 
10
 * @author mdecorde
11
 * @author sjacquot
12
 *
13
 */
14
public class PropertiesCoreMessages extends NLS {
15

  
16
	private static final String BUNDLE_NAME = "org.txm.properties.core.messages.messages"; //$NON-NLS-1$
17
	
18
	public static String RESULT_TYPE;
19

  
20
	
21
	public static String Properties_0;
22
	public static String Properties_1;
23
	public static String Properties_11;
24
	public static String Properties_14;
25
	public static String Properties_16;
26
	public static String Properties_2;
27
	public static String Properties_22;
28
	public static String Properties_26;
29
	public static String Properties_3;
30
	public static String Properties_4;
31
	public static String Properties_40;
32
	public static String Properties_41;
33
	public static String Properties_43;
34
	public static String Properties_49;
35
	public static String Properties_5;
36
	public static String Properties_6;
37
	public static String Properties_7;
38
	public static String Properties_8;
39
	public static String Properties_9;
40

  
41
	
42
	
43
	static {
44
		// initialize resource bundle
45
		Utf8NLS.initializeMessages(BUNDLE_NAME, PropertiesCoreMessages.class);
46
	}
47

  
48
	private PropertiesCoreMessages() {
49
	}
50
	
51
}
0 52

  
tmp/org.txm.properties.core/src/org/txm/properties/core/messages/messages.properties (revision 933)
1

  
2
Properties_0  = * Structural Units properties\n
3
Properties_1  = ** Failed to access corpus 
4
Properties_11 = \ structures
5
Properties_14 = Lexical Units properties (max {0} values)
6
Properties_16 = Number of structural units 
7
Properties_2  = ** Error
8
Properties_22 = Structural Units properties (max {0} values)
9
Properties_26 = No property
10
Properties_3  = Description of 
11
Properties_4  = \ properties
12
Properties_40 = * General Statistics\n
13
Properties_41 = - T 
14
Properties_43 = - Word properties 
15
Properties_49 = - S 
16
Properties_5  = General Statistics
17
Properties_6  = ** Failed to access corpus 
18
Properties_7  = Number of words 
19
Properties_8  = \ lexicon
20
Properties_9  = Number of word properties 
21

  
22
RESULT_TYPE = Properties
0 23

  
tmp/org.txm.properties.core/src/org/txm/properties/core/functions/Properties.java (revision 933)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2016-09-19 10:31:00 +0200 (Mon, 19 Sep 2016) $
25
// $LastChangedRevision: 3298 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.properties.core.functions;
29

  
30
import java.io.File;
31
import java.io.IOException;
32
import java.io.PrintWriter;
33
import java.util.ArrayList;
34
import java.util.Collections;
35
import java.util.HashMap;
36
import java.util.LinkedHashSet;
37
import java.util.List;
38
import java.util.Locale;
39

  
40
import org.eclipse.osgi.util.NLS;
41
import org.txm.core.preferences.TBXPreferences;
42
import org.txm.core.preferences.TXMPreferences;
43
import org.txm.core.results.Parameter;
44
import org.txm.core.results.TXMParameters;
45
import org.txm.core.results.TXMResult;
46
import org.txm.objects.Base;
47
import org.txm.properties.core.messages.PropertiesCoreMessages;
48
import org.txm.properties.core.preferences.PropertiesPreferences;
49
import org.txm.searchengine.cqp.AbstractCqiClient;
50
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
51
import org.txm.searchengine.cqp.corpus.Corpus;
52
import org.txm.searchengine.cqp.corpus.CorpusManager;
53
import org.txm.searchengine.cqp.corpus.MainCorpus;
54
import org.txm.searchengine.cqp.corpus.Property;
55
import org.txm.searchengine.cqp.corpus.StructuralUnit;
56
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
57
import org.txm.searchengine.cqp.corpus.WordProperty;
58
import org.txm.utils.AsciiUtils;
59
import org.txm.utils.io.IOUtils;
60
import org.txm.utils.logger.Log;
61

  
62
/**
63
 * Computes a diagnostic of Corpus or Subcorpus.
64
 * 
65
 * @author mdecorde
66
 */
67
public class Properties extends TXMResult {
68
	// Base base;
69
	/** The corpus. */
70
	protected Corpus corpus;
71
	
72
	// Numbers
73
	/** The T. */
74
	int T = 0; // number of word
75

  
76
	/** The N properties. */
77
	int NProperties = 0; // number of word properties
78
	//HashMap<String, Integer> propertiesCounts = new HashMap<String, Integer>(); // properties counts
79
	/** The properties values. */
80
	HashMap<String, List<String>> propertiesValues = new HashMap<String, List<String>>(); // properties values
81

  
82
	/** The N structures. */
83
	int NStructures = 0; // number of structures
84
	
85
	/** The structures counts. */
86
	HashMap<String, Integer> structuresCounts = new HashMap<String, Integer>(); // structures counts
87

  
88
	/** The internal architecture. */
89
	List<String> internalArchitecture = new ArrayList<String>(); // cqp structures = propertiesCounts keys but ordered
90
	
91
	/** The hierarchie counts. */
92
	HashMap<String, Integer> hierarchieCounts = new HashMap<String, Integer>(); // hierarchic structures counts
93
	
94
	/** The internal architecture properties. */
95
	HashMap<String, HashMap<String, List<String>>> internalArchitectureProperties = new HashMap<String, HashMap<String, List<String>>>(); // hierarchic structures counts
96
	
97
	/** The internal architecture properties counts. */
98
	HashMap<String, HashMap<String, Integer>> internalArchitecturePropertiesCounts = new HashMap<String, HashMap<String, Integer>>(); // hierarchic structures counts
99

  
100
	// Annotations description
101
	/** The annotations types. */
102
	HashMap<String, Integer> annotationsTypes = new HashMap<String, Integer>(); // for each annotation its description
103
	
104
	/** The annotations origins. */
105
	HashMap<String, Integer> annotationsOrigins = new HashMap<String, Integer>(); // for each annoation its origin description
106

  
107
	/** The properties. */
108
	List<WordProperty> properties;
109
	
110
	/** The structures. */
111
	List<StructuralUnit> structures;
112

  
113
	/**
114
	 * The HTML file.
115
	 */
116
	protected File file;
117
	
118
	/**
119
	 * The maximum number of word property values to display.
120
	 */
121
	@Parameter(key=PropertiesPreferences.MAX_PROPERTIES_TO_DISPLAY)
122
	protected int pMaxPropertiesToDisplay;
123
	
124
	/**
125
	 * Instantiates a new Information.
126
	 *
127
	 * @param corpus a MainCorpus or a SubCorpus
128
	 */
129
	public Properties(Corpus corpus) {
130
		super(corpus);
131
	}
132

  
133
	public Properties(String uuid) {
134
		super(uuid);
135
	}
136

  
137
	
138
	
139
	@Override
140
	public boolean loadParameters() {
141
		this.corpus = (Corpus) this.parent;
142
		return true;
143
	}
144

  
145
	
146
	/**
147
	 * Sets the maximum properties to display.
148
	 * @param maxPropertiesToDisplay
149
	 */
150
	public void setParameters(int maxPropertiesToDisplay) {
151
		this.pMaxPropertiesToDisplay = maxPropertiesToDisplay;
152
		if (this.pMaxPropertiesToDisplay <= 0) {
153
			this.pMaxPropertiesToDisplay = 10;
154
		}
155
		this.dirty = true;
156
	}
157
	
158
	
159
	/**
160
	 * Step general infos.
161
	 */
162
	public void stepGeneralInfos()
163
	{
164
		try {
165
			properties = corpus.getProperties();
166
			NProperties = properties.size();
167
		} catch (CqiClientException e) {
168
			Log.severe(PropertiesCoreMessages.Properties_1 + corpus.getName() + PropertiesCoreMessages.Properties_4);
169
			Log.printStackTrace(e);
170
			return;
171
		}
172
		
173
		try {
174
			T = corpus.getSize();// corpus.getLexicon(corpus.getProperty("id")).nbrOfToken();
175
		} catch (CqiClientException e) {
176
			Log.severe(PropertiesCoreMessages.Properties_6 + corpus.getName() + PropertiesCoreMessages.Properties_8);
177
			Log.printStackTrace(e);
178
			return;
179
		} 
180
	}
181
	
182
	/**
183
	 * step2.
184
	 * randomly position are choose
185
	 */
186
	public void stepLexicalProperties() {
187
		propertiesValues.clear();
188
		
189
		AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient();
190
		for (Property p : properties) {
191
			//int size;
192
			try {
193
				//size = CorpusManager.getCorpusManager().getCqiClient().lexiconSize(p.getQualifiedName());
194
				//propertiesCounts.put(p.getName(), size);
195
				//List<String> list = Arrays.asList(corpus.getLexicon(p).getForms(this.maxvalue));
196

  
197
				int[] positions = new int[Math.min(pMaxPropertiesToDisplay, T)];
198
				for(int i = 0 ; i < Math.min(pMaxPropertiesToDisplay, T) ; i++) {
199
					positions[i] = i;
200
				}
201
				
202
				//ArrayList<String> values = new ArrayList<String>();
203
				LinkedHashSet<String> values = new LinkedHashSet<String>(cqiClient.getSingleData(p, positions));
204
				propertiesValues.put(p.getName(), new ArrayList<String>(values));
205
			} catch (Exception e) {
206
				Log.printStackTrace(e);
207
			}
208
		}
209
	}
210
	
211
	/**
212
	 * Step structural units.
213
	 */
214
	public void stepStructuralUnits()
215
	{
216
		try {
217
			structures = corpus.getOrderedStructuralUnits();
218
		} catch (CqiClientException e) {
219
			Log.severe(PropertiesCoreMessages.Properties_1 + corpus.getName() + PropertiesCoreMessages.Properties_11);
220
			Log.printStackTrace(e);
221
			return;
222
		}
223
		NStructures = structures.size();
224
		internalArchitecture.clear();
225
		for (StructuralUnit su : structures) { // for each structural unit
226
			internalArchitecture.add(su.getName());
227
			hierarchieCounts.put(su.getName(), -1);
228
			internalArchitectureProperties.put(su.getName(), new HashMap<String, List<String>>());
229
			internalArchitecturePropertiesCounts.put(su.getName(), new HashMap<String, Integer>());
230
			
231
			if (su.getProperties().size() > 0) {
232
				for (StructuralUnitProperty sup : su.getProperties())  {// for each of its property
233
					try {
234
						List<String> allvalues = sup.getValues(corpus);
235
						internalArchitectureProperties.get(su.getName()).put(sup.getName(), allvalues.subList(0, Math.min(allvalues.size(), pMaxPropertiesToDisplay)));
236
						internalArchitecturePropertiesCounts.get(su.getName()).put(sup.getName(), allvalues.size());
237
					} catch (Exception e) {
238
						ArrayList<String> list = new ArrayList<String>(1);
239
						list.add(PropertiesCoreMessages.Properties_2);
240
						internalArchitectureProperties.get(su.getName()).put(sup.getName(), list);
241
						internalArchitecturePropertiesCounts.get(su.getName()).put(sup.getName(), -1);
242
					}
243
				}
244
			}
245
		}
246
	}
247

  
248
	// FIXME: useless?
249
//	/**
250
//	 * Instantiates a new diagnostic.
251
//	 *
252
//	 * @param partition the partition
253
//	 * @throws CqiClientException the cqi client exception
254
//	 */
255
//	public Information(Partition partition) throws CqiClientException {
256
//		corpus = partition.getCorpus();
257
//		this.partition = partition;
258
//		int T = corpus.getSize();
259
//		System.out.println(InformationCoreMessages.Properties_12);
260
//		int nbParts = partition.getNPart();
261
//		List<String> partNames = partition.getPartNames();
262
//		List<Integer> partSizes = new ArrayList<Integer>();
263
//		List<List<Property>> partProperties = new ArrayList<List<Property>>();
264
//		List<String> partQueries = new ArrayList<String>();
265
//		for (Part part : partition.getParts()) {
266
//			partSizes.add(part.getSize());
267
//			partProperties.add(part.getProperties());
268
//			partQueries.add(part.getQuery().getQueryString());
269
//		}
270
//	}
271

  
272
	/**
273
	 * dump the results of the diagnostic in a String containing HTML code.
274
	 *
275
	 * @return the string
276
	 */
277
	public String htmlDump() {
278
		StringBuffer buff = new StringBuffer();
279

  
280
		buff.append("<? version=\"1.0\" encoding=\"UTF-8\"?>\n" + //$NON-NLS-1$
281
				"<html>" + //$NON-NLS-1$
282
				"<head>" + //$NON-NLS-1$
283
				"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>" + //$NON-NLS-1$
284
				"</head>" + //$NON-NLS-1$
285
				"<body>\n"); //$NON-NLS-1$
286
		buff.append("<h2 style'font-family:\"Arial\";'>"+PropertiesCoreMessages.Properties_3 + this.corpus.getName() + "</h2>\n"); //$NON-NLS-2$ //$NON-NLS-1$
287
		
288
		if (corpus.getDescription() != null && corpus.getDescription().length() > 0) {
289
			buff.append("<p>"+corpus.getDescription()+"</p>"); //$NON-NLS-1$ //$NON-NLS-2$
290
		}
291
		
292
		buff.append("<h3 style'font-family:\"Arial\";'>"+PropertiesCoreMessages.Properties_5+ "</h3>\n"); //$NON-NLS-1$ //$NON-NLS-2$ 
293

  
294
		
295
		
296
		// counts
297
		buff.append("<ul>\n"); //$NON-NLS-1$
298
		buff.append("<li>" + PropertiesCoreMessages.Properties_7 + T + "</li>\n"); //$NON-NLS-1$ //$NON-NLS-2$ 
299
		buff
300
		.append("<li>" + PropertiesCoreMessages.Properties_9 + (NProperties - 1) + "</li>\n"); //$NON-NLS-2$ //$NON-NLS-1$
301
		buff.append("<li>" + PropertiesCoreMessages.Properties_16 + NStructures + "</li>\n"); //$NON-NLS-2$ //$NON-NLS-1$
302
		buff.append("</ul>\n"); //$NON-NLS-1$
303

  
304
		// Propriétés d'occurrences
305
		buff.append("<h3 style'font-family:\"Arial\";'>"+NLS.bind(PropertiesCoreMessages.Properties_14, pMaxPropertiesToDisplay) + "</h3>\n"); //$NON-NLS-1$ //$NON-NLS-2$ 
306
		ArrayList<String> properties = new ArrayList<String>(propertiesValues.keySet());
307
		Collections.sort(properties);
308
		buff.append("<ul>\n"); //$NON-NLS-1$
309
		for (String s : properties) {
310
			if (!s.equals("id")) //$NON-NLS-1$
311
			{
312
				//buff.append("<li> " + s + " (" + propertiesCounts.get(s) + ") : "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
313
				buff.append("<li> " + s + " : "); //$NON-NLS-1$ //$NON-NLS-2$ 
314
				for (String v : propertiesValues.get(s))
315
					buff.append(v + ", "); //$NON-NLS-1$
316
				buff.append("..."); //$NON-NLS-1$
317
				buff.append("</li>\n"); //$NON-NLS-1$ 
318
			}
319
		}
320
		buff.append("</ul>\n"); //$NON-NLS-1$
321

  
322
		// Propriété de structures
323
		buff.append("<h3 style'font-family:\"Arial\";'>"+NLS.bind(PropertiesCoreMessages.Properties_22, pMaxPropertiesToDisplay)+"</h3>\n"); //$NON-NLS-1$ //$NON-NLS-2$
324
		buff.append("<ul>\n"); //$NON-NLS-1$
325
		for (String s : internalArchitecture) {
326
			StringBuffer subbuffer = new StringBuffer();
327
			if (s.equals("txmcorpus")) //$NON-NLS-1$
328
				continue;//ignore the txmcorpus structure
329
			
330
			properties = new ArrayList<String>(internalArchitectureProperties.get(s).keySet());
331
			
332
			subbuffer.append("<li> " + s + "\n<ul>\n"); //$NON-NLS-1$ //$NON-NLS-2$
333
			if (internalArchitectureProperties.get(s).keySet().size() == 0)
334
				subbuffer.append("<li>"+PropertiesCoreMessages.Properties_26+"</li>\n"); //$NON-NLS-1$ //$NON-NLS-2$ 
335

  
336
			
337
			//System.out.println("struct: "+s+" >> "+properties);
338
			Collections.sort(properties);
339
			//System.out.println("struct: "+s+" >sort> "+properties);
340
			int nbOfValues = 0;
341
			for (String ps : properties) {
342
				if (!ps.equals("project") && !ps.equals("base") ) //$NON-NLS-1$ //$NON-NLS-2$ 
343
				{
344
					//System.out.println("struct: "+s+" >> "+ps);
345
					int valuecount = internalArchitecturePropertiesCounts.get(s).get(ps);
346
					ArrayList<String> values = new ArrayList<String>(internalArchitectureProperties.get(s).get(ps));
347
					subbuffer.append("<li> " + ps + " (" + valuecount + ") = "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
348
					//System.out.println("VALUES: "+values);
349
					Collections.sort(values);
350
					for (int i = 0 ; i < values.size() ; i++) {
351
						nbOfValues++;
352
						String psv = values.get(i);
353
						if (psv != null && psv.length() > 0)
354
							subbuffer.append(psv.replace("<", "&lt;")); //$NON-NLS-1$ //$NON-NLS-2$
355
						else
356
							subbuffer.append("\"\""); //$NON-NLS-1$
357
						
358
						if (i == values.size() -1)
359
							subbuffer.append("."); //$NON-NLS-1$
360
						else
361
							subbuffer.append(", "); //$NON-NLS-1$
362
						
363
						if (i >= pMaxPropertiesToDisplay) {
364
							subbuffer.append("..."); //$NON-NLS-1$
365
							break;
366
						}
367
					}
368
					subbuffer.append("</li>\n"); //$NON-NLS-1$
369
				}
370
			}
371
			subbuffer.append("</ul>\n</li>\n"); //$NON-NLS-1$
372
			if (nbOfValues > 0) {
373
				buff.append(subbuffer);
374
			}
375
		}
376
		buff.append("</ul>\n"); //$NON-NLS-1$
377
		buff.append("</body>\n"); //$NON-NLS-1$
378
		buff.append("</html>\n"); //$NON-NLS-1$
379
		
380
		return buff.toString();
381
	}
382

  
383
	
384
	
385
	/**
386
	 * dump the result in the console.
387
	 *
388
	 * @param maxvalue the maxvalue
389
	 * @return the string
390
	 */
391
	public String dump(int maxvalue) {
392
		StringBuffer buff = new StringBuffer();
393

  
394
		buff.append(PropertiesCoreMessages.Properties_40);
395
		buff.append(PropertiesCoreMessages.Properties_41 + String.format(Locale.FRANCE,"%,d", T) + "\n"); //$NON-NLS-1$ 
396
		buff.append(PropertiesCoreMessages.Properties_43 + String.format("%,d", NProperties) + "\n"); //$NON-NLS-1$ 
397
		/*for (String s : propertiesCounts.keySet())
398
			if (!s.equals("id")) //$NON-NLS-1$
399
				buff.append(" - " + s + " " + propertiesCounts.get(s) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
400
				*/
401
		buff.append(PropertiesCoreMessages.Properties_49 + String.format("%,d", NStructures) + "\n"); //$NON-NLS-1$ 
402
		for (String s : structuresCounts.keySet())
403
			buff.append(" - " + s + "\n");//+structuresCounts.get(s)+"\n"); //$NON-NLS-1$ //$NON-NLS-2$
404

  
405
		/*
406
		 * buff.append("* Structural Units counts\n"); for(String s :
407
		 * internalArchitecture)
408
		 * buff.append(" - "+s+" "+hierarchieCounts.get(s)+"\n");
409
		 */
410
		buff.append(PropertiesCoreMessages.Properties_0);
411
		for (String s : internalArchitecture) {
412
			buff.append(" - " + s + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
413
			for (String ps : internalArchitectureProperties.get(s).keySet()) {
414
				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$
415
				{
416
					buff
417
					.append("   - " + ps + "(" + internalArchitectureProperties.get(s).get(ps).size() + ") = "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
418

  
419
					int valuecount = 0;
420
					for (String psv : internalArchitectureProperties.get(s)
421
							.get(ps)) {
422
						buff.append(psv);
423
						if (valuecount++ >= maxvalue) {
424
							buff.append("..."); //$NON-NLS-1$
425
							break;
426
						}
427
						if (valuecount < internalArchitectureProperties.get(s)
428
								.get(ps).size())
429
							buff.append(", "); //$NON-NLS-1$
430
					}
431

  
432
					buff.append("\n"); //$NON-NLS-1$
433
				}
434
			}
435
		}
436

  
437
		return buff.toString();
438
	}
439

  
440
	/**
441
	 * dump the result in the console with maxvalue=30.
442
	 *
443
	 * @return the string
444
	 */
445
	public String dump() {
446
		return dump(30);
447
	}
448

  
449
	/**
450
	 * Gets the name.
451
	 *
452
	 * @return the name
453
	 */
454
	public String getName() {
455
		return corpus.getName();
456
	}
457

  
458
	/**
459
	 * Gets the base.
460
	 *
461
	 * @return the base
462
	 */
463
	public Base getBase() {
464
		return corpus.getBase();
465
	}
466

  
467
	/**
468
	 * Gets the t.
469
	 *
470
	 * @return the t
471
	 */
472
	public int getT() {
473
		return T;
474
	}
475

  
476
	/**
477
	 * Gets the n properties.
478
	 *
479
	 * @return the n properties
480
	 */
481
	public int getNProperties() {
482
		return NProperties;
483
	}
484

  
485
	/**
486
	 * Gets the internal architecture.
487
	 *
488
	 * @return the internal architecture
489
	 */
490
	public List<String> getInternalArchitecture() {
491
		return internalArchitecture;
492
	}
493

  
494
	/**
495
	 * Gets the n structures.
496
	 *
497
	 * @return the n structures
498
	 */
499
	public int getNStructures() {
500
		return NStructures;
501
	}
502

  
503
	/**
504
	 * Gets the structures counts.
505
	 *
506
	 * @return the structures counts
507
	 */
508
	public HashMap<String, Integer> getStructuresCounts() {
509
		return structuresCounts;
510
	}
511

  
512
	/**
513
	 * Gets the annotations types.
514
	 *
515
	 * @return the annotations types
516
	 */
517
	public HashMap<String, Integer> getAnnotationsTypes() {
518
		return annotationsTypes;
519
	}
520

  
521
	/**
522
	 * Gets the annotations origins.
523
	 *
524
	 * @return the annotations origins
525
	 */
526
	public HashMap<String, Integer> getAnnotationsOrigins() {
527
		return annotationsOrigins;
528
	}
529

  
530
	/**
531
	 * dump the diagnostic in a text file.
532
	 *
533
	 * @param outfile the outfile
534
	 * @param maxvalue the maxvalue
535
	 * @return true, if successful
536
	 */
537
	public boolean toTxt(File outfile, String encoding, int maxvalue) {
538
		PrintWriter writer = null;
539
		try {
540
			writer = IOUtils.getWriter(outfile, encoding);
541
			writer.write(this.dump(maxvalue));
542
			writer.close();
543
		} catch (Exception e) {
544
			org.txm.utils.logger.Log.printStackTrace(e);
545
			return false;
546
		}
547

  
548
		return true;
549
	}
550

  
551
	/**
552
	 * dump the diagnostic in a HTML file.
553
	 *
554
	 * @param outfile the outfile
555
	 * @return true, if successful
556
	 */
557
	public boolean toHTML(File outfile) {
558
		outfile.getParentFile().mkdirs();
559
		PrintWriter writer;
560
		try {
561
			writer = IOUtils.getWriter(outfile); //$NON-NLS-1$
562
			writer.write(this.htmlDump());
563
			writer.close();
564
		} catch (IOException e) {
565
			org.txm.utils.logger.Log.printStackTrace(e);
566
			return false;
567
		}
568

  
569
		return true;
570
	}
571

  
572
	/**
573
	 * dump the diagnostic in a text file, maxvalue = 100.
574
	 *
575
	 * @param outfile the outfile
576
	 * @return true, if successful
577
	 */
578
	public boolean toTxt(File outfile) {
579
		return toTxt(outfile, "UTF-8", 100); //$NON-NLS-1$
580
	}
581

  
582
	@Override
583
	public void clean() {
584
		// TODO Auto-generated method stub
585
	}
586

  
587
	@Override
588
	public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception {
589
		return toTxt(outfile, encoding, 100);
590
	}
591

  
592
	@Override
593
	public String getSimpleName() {
594
		return this.getResultype();
595
	}
596

  
597
	@Override
598
	public String getDetails() {
599
		return "" + T;
600
	}
601

  
602
	@Override
603
	protected boolean _compute() throws Exception {
604
		
605
		this.beginTask("Computing properties...", 3);
606
		this.stepGeneralInfos();
607
		this.worked(1);
608
		
609
		this.stepLexicalProperties();
610
		this.worked(1);
611
		
612
		this.stepStructuralUnits();
613
		this.worked(1);
614
		
615
		String txmhome = TXMPreferences.getString(TBXPreferences.USER_TXM_HOME, TBXPreferences.PREFERENCES_NODE);
616
		String filename = corpus.getMainCorpus() + "-" + corpus.getName(); //$NON-NLS-1$
617
		if (corpus instanceof MainCorpus) {
618
			filename = corpus.getName(); //$NON-NLS-1$
619
		}
620
		
621
		filename = AsciiUtils.buildId(filename);
622
		file = new File(txmhome, "results/" + filename + "-infos.html"); //$NON-NLS-1$ //$NON-NLS-2$
623
		
624
		this.toHTML(file);
625
		return true;
626
	}
627
	
628
	/**
629
	 * Gets the HTML file.
630
	 * @return the HTML file
631
	 */
632
	public File getHTMLFile() {
633
		return file;
634
	}
635

  
636
	@Override
637
	public boolean canCompute() {
638
		return this.parent != null;
639
	}
640

  
641
	@Override
642
	public boolean setParameters(TXMParameters parameters) {
643
		this.pMaxPropertiesToDisplay = parameters.getInteger(PropertiesPreferences.MAX_PROPERTIES_TO_DISPLAY);
644
		return true;
645
	}
646

  
647
	
648
	@Override
649
	public boolean saveParameters() {
650
		// nothing to do -> all parameters are already managed by autoSaveParameters
651
		return true;
652
	}
653

  
654
	public Corpus getCorpus() {
655
		return (Corpus) this.parent;
656
	}
657

  
658
	@Override
659
	public String getResultype() {
660
		return PropertiesCoreMessages.RESULT_TYPE;
661
	}
662
}
0 663

  
tmp/org.txm.properties.core/src/org/txm/properties/core/package.html (revision 933)
1
<html>
2
<body>
3
<p>Diagnostic function</p>
4
</body>
5
</html>
0 6

  
tmp/org.txm.properties.core/src/org/txm/properties/core/preferences/PropertiesPreferences.java (revision 933)
1
package org.txm.properties.core.preferences;
2

  
3

  
4
import org.eclipse.core.runtime.preferences.DefaultScope;
5
import org.osgi.framework.FrameworkUtil;
6
import org.osgi.service.prefs.Preferences;
7
import org.txm.core.preferences.TXMPreferences;
8

  
9
/**
10
 * Information preferences initializer.
11
 * @author sjacquot
12
 *
13
 */
14
public class PropertiesPreferences extends TXMPreferences {
15

  
16
	// auto populate the preference node qualifier from the current bundle id
17
	public static final String PREFERENCES_NODE = FrameworkUtil.getBundle(PropertiesPreferences.class).getSymbolicName();
18
	
19
	public static final String PREFERENCES_PREFIX = "properties_"; //$NON-NLS-1$
20
	
21
	
22
	/**
23
	 * The maximum number of word property values to display.
24
	 */
25
	public static final String MAX_PROPERTIES_TO_DISPLAY = PREFERENCES_PREFIX + "max_properties_to_display"; //$NON-NLS-1$
26

  
27
	
28
	@Override
29
	public void initializeDefaultPreferences() {
30
		Preferences preferences = DefaultScope.INSTANCE.getNode(PREFERENCES_NODE);
31
		
32
		preferences.putInt(MAX_PROPERTIES_TO_DISPLAY, 100);
33
		
34
	}
35
	
36
}
0 37

  
tmp/org.txm.properties.core/build.properties (revision 933)
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .,\
5
               plugin.xml
0 6

  

Formats disponibles : Unified diff