Révision 118
tmp/org.txm.partition.core/src/org/txm/partition/core/corpusengine/cqp/__Partition2.java (revision 118) | ||
---|---|---|
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: 2014-09-15 10:51:15 +0200 (Mon, 15 Sep 2014) $ |
|
25 |
// $LastChangedRevision: 2836 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.partition.core.corpusengine.cqp; |
|
29 |
|
|
30 |
import java.text.Collator; |
|
31 |
import java.text.DateFormat; |
|
32 |
import java.text.ParseException; |
|
33 |
import java.text.SimpleDateFormat; |
|
34 |
import java.util.ArrayList; |
|
35 |
import java.util.Arrays; |
|
36 |
import java.util.Collections; |
|
37 |
import java.util.Comparator; |
|
38 |
import java.util.Date; |
|
39 |
import java.util.HashMap; |
|
40 |
import java.util.List; |
|
41 |
import java.util.Locale; |
|
42 |
import java.util.Map; |
|
43 |
|
|
44 |
import org.eclipse.osgi.util.NLS; |
|
45 |
import org.txm.HasResults; |
|
46 |
import org.txm.Messages; |
|
47 |
import org.txm.Toolbox; |
|
48 |
import org.txm.objects.TxmObject; |
|
49 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
50 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
51 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
|
52 |
import org.txm.searchengine.cqp.corpus.CqpObject; |
|
53 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
54 |
import org.txm.searchengine.cqp.corpus.Part; |
|
55 |
import org.txm.searchengine.cqp.corpus.Property; |
|
56 |
import org.txm.searchengine.cqp.corpus.QueryResult; |
|
57 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
|
58 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
59 |
import org.txm.searchengine.cqp.corpus.Subcorpus; |
|
60 |
import org.txm.searchengine.cqp.corpus.query.Query; |
|
61 |
import org.txm.searchengine.cqp.corpus.query.QueryPart; |
|
62 |
import org.txm.stat.StatException; |
|
63 |
import org.txm.stat.data.LexicalTable; |
|
64 |
import org.txm.stat.engine.r.data.LexicalTableImpl; |
|
65 |
import org.txm.utils.logger.Log; |
|
66 |
import org.w3c.dom.Document; |
|
67 |
import org.w3c.dom.Element; |
|
68 |
import org.w3c.dom.NodeList; |
|
69 |
|
|
70 |
// TODO: Auto-generated Javadoc |
|
71 |
/** |
|
72 |
* A partition on a corpus. |
|
73 |
* |
|
74 |
* @author Jean-Philippe Magué |
|
75 |
*/ |
|
76 |
public class __Partition2 extends TxmObject implements HasResults{ |
|
77 |
|
|
78 |
/** The Constant serialVersionUID. */ |
|
79 |
private static final long serialVersionUID = 4420732757687971253L; |
|
80 |
|
|
81 |
/** The corpus. */ |
|
82 |
private Corpus corpus; |
|
83 |
|
|
84 |
/** The parts. */ |
|
85 |
private List<Part> parts; |
|
86 |
|
|
87 |
/** The structure. */ |
|
88 |
private StructuralUnit structure; |
|
89 |
|
|
90 |
/** The property. */ |
|
91 |
private Property property; |
|
92 |
|
|
93 |
/** An association between name of analysis property and lexical table. */ |
|
94 |
private Map<String, LexicalTable> lexicalTables = new HashMap<String, LexicalTable>(); |
|
95 |
|
|
96 |
/** The results. */ |
|
97 |
private List<Object> results = new ArrayList<Object>(); |
|
98 |
|
|
99 |
/** |
|
100 |
* Creates a new partition on a corpus given a structure, a property of this |
|
101 |
* structure and a liste of values this property can take |
|
102 |
* |
|
103 |
* The partition has as many parts as the size of the list of value. The ith |
|
104 |
* part is composed by all the structure <code>structure</code> such as |
|
105 |
* <code>strucutre.getValue(property) == values.get(i)<code> |
|
106 |
* |
|
107 |
* @param corpus |
|
108 |
* the corpus |
|
109 |
* @param structure |
|
110 |
* the structure |
|
111 |
* @param property |
|
112 |
* the property |
|
113 |
* @param values |
|
114 |
* the values |
|
115 |
* |
|
116 |
* @throws CqiClientException |
|
117 |
* the cqi client exception |
|
118 |
*/ |
|
119 |
protected __Partition2(Corpus corpus, StructuralUnit structure, |
|
120 |
StructuralUnitProperty property, List<String> values) |
|
121 |
throws CqiClientException { |
|
122 |
this.name = corpus.getName()+ "_" + structure.getName() + "_" + property.getName(); //$NON-NLS-1$ //$NON-NLS-2$ |
|
123 |
Log.finest(NLS.bind(Messages.NEW_PARTION, this.corpus, this.name)); |
|
124 |
long start = System.currentTimeMillis(); |
|
125 |
this.corpus = corpus; |
|
126 |
this.structure = structure; |
|
127 |
this.property = property; |
|
128 |
this.parts = new ArrayList<Part>(); |
|
129 |
HashMap<String, String> infos = this.getCorpus().getSAttributesInfos().get(property.getFullName()); |
|
130 |
String type = "String"; //$NON-NLS-1$ |
|
131 |
if (infos != null) { |
|
132 |
type = infos.get("type"); //$NON-NLS-1$ |
|
133 |
} |
|
134 |
if (type == null || type.trim().length() == 0 || type.equals("String")) { //$NON-NLS-1$ |
|
135 |
Collections.sort(values, Collator.getInstance(Locale.getDefault())); // alpha sort |
|
136 |
} else if (type.equals("Integer")) { //$NON-NLS-1$ |
|
137 |
Collections.sort(values, new Comparator<String>() { |
|
138 |
@Override |
|
139 |
public int compare(String arg0, String arg1) { |
|
140 |
int i0 = Integer.parseInt(arg0); |
|
141 |
int i1 = Integer.parseInt(arg1); |
|
142 |
return i0-i1; |
|
143 |
} |
|
144 |
}); |
|
145 |
} else if (type.equals("Date")) { //$NON-NLS-1$ |
|
146 |
String format = infos.get("inputFormat"); //$NON-NLS-1$ |
|
147 |
final DateFormat formater = new SimpleDateFormat(format); |
|
148 |
Collections.sort(values, new Comparator<String>() { |
|
149 |
@Override |
|
150 |
public int compare(String arg0, String arg1) { |
|
151 |
try { |
|
152 |
Date i0 = formater.parse(arg0); |
|
153 |
Date i1 = formater.parse(arg1); |
|
154 |
return i0.compareTo(i1); |
|
155 |
} catch (ParseException e) { |
|
156 |
return arg0.compareTo(arg1); |
|
157 |
} |
|
158 |
} |
|
159 |
}); |
|
160 |
} else if(type.contains("|")){ //$NON-NLS-1$ |
|
161 |
final List<String> sortedValues = Arrays.asList(type.split("\\|")); //$NON-NLS-1$ |
|
162 |
Collections.sort(values, new Comparator<String>() { |
|
163 |
@Override |
|
164 |
public int compare(String arg0, String arg1) { |
|
165 |
int i0 = sortedValues.indexOf(arg0); |
|
166 |
int i1 = sortedValues.indexOf(arg1); |
|
167 |
return i0-i1; |
|
168 |
} |
|
169 |
}); |
|
170 |
} |
|
171 |
//System.out.println("Parts sorted with type: "+type); |
|
172 |
//System.out.println("values: "+values); |
|
173 |
for (String value : values) { |
|
174 |
String partitionName = this.getName(); |
|
175 |
String partName = value.replace("\\",""); //$NON-NLS-1$ //$NON-NLS-2$ |
|
176 |
//System.out.println("VALUE: "+value); |
|
177 |
Query query = new QueryPart(structure, property, Query.addBackSlash(value)); |
|
178 |
Part part = createPart(partitionName, partName, query); |
|
179 |
// System.out.println("part id: "+part.getQualifiedCqpId()); |
|
180 |
parts.add(part); |
|
181 |
} |
|
182 |
long end = System.currentTimeMillis(); |
|
183 |
Log.finest(NLS.bind(Messages.PARTITION_CREATED, this.name, (end - start))); |
|
184 |
} |
|
185 |
|
|
186 |
/** |
|
187 |
* Instantiates a new partition. |
|
188 |
* |
|
189 |
* @param corpus the corpus |
|
190 |
* @param structure the structure |
|
191 |
* @param property the property |
|
192 |
* @throws CqiClientException the cqi client exception |
|
193 |
*/ |
|
194 |
protected __Partition2(Corpus corpus, StructuralUnit structure, |
|
195 |
StructuralUnitProperty property) throws CqiClientException { |
|
196 |
|
|
197 |
this(corpus, structure, property, property.getValues(corpus)); |
|
198 |
} |
|
199 |
|
|
200 |
/** |
|
201 |
* Get the safe values (spacial char regexp safe). |
|
202 |
* |
|
203 |
* @param property the property |
|
204 |
* @param corpus the corpus |
|
205 |
* @return the safe values |
|
206 |
* @throws CqiClientException the cqi client exception |
|
207 |
*/ |
|
208 |
private static List<String> getSafeValues(StructuralUnitProperty property, Corpus corpus) throws CqiClientException |
|
209 |
{ |
|
210 |
List<String> values = property.getValues(corpus); |
|
211 |
//System.out.println("CORPUS: "+corpus); |
|
212 |
//System.out.println("VALUES: "+values); |
|
213 |
for(int i = 0 ; i < values.size() ; i++) |
|
214 |
values.set(i, Query.addBackSlash(values.get(i))); |
|
215 |
return values; |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* Create a partition with a set of raw queries. |
|
220 |
* |
|
221 |
* @param corpus the corpus |
|
222 |
* @param name the name |
|
223 |
* @param queries the queries |
|
224 |
* @throws CqiClientException the cqi client exception |
|
225 |
* @author Sylvain Loiseau |
|
226 |
*/ |
|
227 |
protected __Partition2(Corpus corpus, String name, List<String> queries) |
|
228 |
throws CqiClientException { |
|
229 |
this.structure = null; |
|
230 |
this.property = null; |
|
231 |
if (name == null || name.trim().length() == 0) |
|
232 |
name = "noname"; //$NON-NLS-1$ |
|
233 |
this.name = name; |
|
234 |
Log.info(NLS.bind(Messages.NEW_PARTION, this.corpus, this.name)); |
|
235 |
long start = System.currentTimeMillis(); |
|
236 |
this.corpus = corpus; |
|
237 |
this.parts = new ArrayList<Part>(); |
|
238 |
for (int i = 0; i < queries.size(); i++) { |
|
239 |
String queryS = queries.get(i); |
|
240 |
String partitionName = this.getName(); |
|
241 |
String partName = String.valueOf(i); |
|
242 |
if (partName.length() == 0) partName = "-"; //$NON-NLS-1$ |
|
243 |
Part part = createPart(partitionName, partName, queryS); |
|
244 |
parts.add(part); |
|
245 |
} |
|
246 |
long end = System.currentTimeMillis(); |
|
247 |
Log.info(NLS.bind(Messages.PARTITION_CREATED, this.name, (end - start))); |
|
248 |
} |
|
249 |
|
|
250 |
/** |
|
251 |
* Instantiates a new partition. |
|
252 |
* |
|
253 |
* @param corpus the corpus |
|
254 |
* @param name the name |
|
255 |
* @param queries the queries |
|
256 |
* @param partnames the partnames |
|
257 |
* @throws CqiClientException the cqi client exception |
|
258 |
*/ |
|
259 |
public __Partition2(Corpus corpus, String name, List<String> queries, |
|
260 |
List<String> partnames) throws CqiClientException { |
|
261 |
this.corpus = corpus; |
|
262 |
this.structure = null; |
|
263 |
this.property = null; |
|
264 |
if (name == null || name.trim().length() == 0) |
|
265 |
name = "noname"; //$NON-NLS-1$ |
|
266 |
this.name = name; |
|
267 |
Log.info(NLS.bind(Messages.NEW_PARTION, this.corpus, this.name)); |
|
268 |
long start = System.currentTimeMillis(); |
|
269 |
this.parts = new ArrayList<Part>(); |
|
270 |
for (int i = 0; i < queries.size(); i++) { |
|
271 |
String queryS = queries.get(i); |
|
272 |
String partitionName = this.getName(); |
|
273 |
String partName = partnames.get(i); |
|
274 |
if (partName.trim().length() == 0) partName = "-"; //$NON-NLS-1$ |
|
275 |
Part part = createPart(partitionName, partName, queryS); |
|
276 |
parts.add(part); |
|
277 |
} |
|
278 |
long end = System.currentTimeMillis(); |
|
279 |
Log.info(NLS.bind(Messages.PARTITION_CREATED, this.name, (end - start))); |
|
280 |
} |
|
281 |
|
|
282 |
public static Integer SUBCORPUS_COUNTER = new Integer(0); |
|
283 |
/** |
|
284 |
* Create a part with a raw query. |
|
285 |
* |
|
286 |
* @param partitionName the partition name |
|
287 |
* @param partName the part name |
|
288 |
* @param query the query |
|
289 |
* @return the part |
|
290 |
* @throws CqiClientException the cqi client exception |
|
291 |
* |
|
292 |
* @author Sylvain Loiseau, mdecorde |
|
293 |
*/ |
|
294 |
private Part createPart(String partitionName, String partName, String query) |
|
295 |
throws CqiClientException { |
|
296 |
Part part; |
|
297 |
String partCqpId = CqpObject.partNamePrefix |
|
298 |
+ Corpus.getNextSubcorpusCounter(); |
|
299 |
Log.finest(NLS.bind(Messages.CREATING_PART,partName, query)); |
|
300 |
long start = System.currentTimeMillis(); |
|
301 |
try { |
|
302 |
CorpusManager.getCorpusManager().getCqiClient().cqpQuery( |
|
303 |
this.corpus.getQualifiedCqpId(), partCqpId, query); |
|
304 |
part = new Part(partCqpId, partitionName, partName, this, |
|
305 |
new Query(query)); |
|
306 |
} catch (Exception e) { |
|
307 |
try { |
|
308 |
throw new CqiClientException(Messages.Partition_9 + partitionName |
|
309 |
+ "_" + partName+ e +" last error: "+Toolbox.getCqiClient().getLastCQPError()); //$NON-NLS-1$ //$NON-NLS-2$ |
|
310 |
} catch (Exception e1) { |
|
311 |
System.out.println(Messages.Partition_18+e1); |
|
312 |
org.txm.utils.logger.Log.printStackTrace(e1); |
|
313 |
return null; |
|
314 |
} |
|
315 |
} |
|
316 |
long end = System.currentTimeMillis(); |
|
317 |
Log.finest(NLS.bind(Messages.PART_CREATED, partitionName |
|
318 |
+ "_" + partName, (end - start))); //$NON-NLS-1$//$NON-NLS-2$ |
|
319 |
return part; |
|
320 |
} |
|
321 |
|
|
322 |
/** |
|
323 |
* Creates the part. |
|
324 |
* |
|
325 |
* @param partitionName the partition name |
|
326 |
* @param partName the part name |
|
327 |
* @param query the query |
|
328 |
* @return the part |
|
329 |
* @throws CqiClientException the cqi client exception |
|
330 |
*/ |
|
331 |
private Part createPart(String partitionName, String partName, Query query) |
|
332 |
throws CqiClientException { |
|
333 |
if (partName.length() == 0) partName = "-"; //$NON-NLS-1$ |
|
334 |
return createPart(partitionName, partName, query.getQueryString()); |
|
335 |
} |
|
336 |
|
|
337 |
/** |
|
338 |
* Gets the name. |
|
339 |
* |
|
340 |
* @return the name |
|
341 |
*/ |
|
342 |
@Override |
|
343 |
public String getName() { |
|
344 |
return name; |
|
345 |
} |
|
346 |
|
|
347 |
/** |
|
348 |
* Gets the corpus. |
|
349 |
* |
|
350 |
* @return the corpus |
|
351 |
*/ |
|
352 |
public Corpus getCorpus() { |
|
353 |
return corpus; |
|
354 |
} |
|
355 |
|
|
356 |
// /** |
|
357 |
// * Gets the parts. |
|
358 |
// * |
|
359 |
// * @return the parts |
|
360 |
// */ |
|
361 |
// public List<Part> getOrderedParts() { |
|
362 |
// List<Part> sparts = parts; |
|
363 |
// Collections.sort(sparts); |
|
364 |
// return sparts; |
|
365 |
// } |
|
366 |
|
|
367 |
/** |
|
368 |
* Gets the parts. |
|
369 |
* |
|
370 |
* @return the parts |
|
371 |
*/ |
|
372 |
public List<Part> getParts() { |
|
373 |
return parts; |
|
374 |
} |
|
375 |
|
|
376 |
/** |
|
377 |
* Gets the name of the parts. |
|
378 |
* |
|
379 |
* @return the part names |
|
380 |
*/ |
|
381 |
public List<String> getPartNames() { |
|
382 |
List<String> partNames = new ArrayList<String>(parts.size()); |
|
383 |
for (Subcorpus part : parts) |
|
384 |
partNames.add(part.getName()); |
|
385 |
return partNames; |
|
386 |
} |
|
387 |
|
|
388 |
// /** |
|
389 |
// * Gets the ordered name of the parts. |
|
390 |
// * |
|
391 |
// * @return the part names |
|
392 |
// */ |
|
393 |
// public List<String> getOrderedPartNames() { |
|
394 |
// List<String> partNames = getPartNames(); |
|
395 |
// Collections.sort(partNames); |
|
396 |
// return partNames; |
|
397 |
// } |
|
398 |
|
|
399 |
/** |
|
400 |
* Gets the short name of the parts. |
|
401 |
* |
|
402 |
* @return the part names |
|
403 |
*/ |
|
404 |
public List<String> getPartShortNames() { |
|
405 |
List<String> partNames = new ArrayList<String>(parts.size()); |
|
406 |
for (Part part : parts) |
|
407 |
partNames.add(part.getShortName()); |
|
408 |
return partNames; |
|
409 |
} |
|
410 |
|
|
411 |
/** |
|
412 |
* Run a query on all the parts of this partition. |
|
413 |
* |
|
414 |
* @param query |
|
415 |
* the query |
|
416 |
* @param name |
|
417 |
* the name |
|
418 |
* |
|
419 |
* @return the list< subcorpus> |
|
420 |
* |
|
421 |
* @throws CqiClientException |
|
422 |
* the cqi client exception |
|
423 |
*/ |
|
424 |
public List<QueryResult> query(Query query, String name) |
|
425 |
throws CqiClientException { |
|
426 |
Log.finest(Messages.QUERYING_PARTITION + this.name); |
|
427 |
List<QueryResult> results = new ArrayList<QueryResult>(parts.size()); |
|
428 |
for (Subcorpus part : parts) |
|
429 |
results.add(part.query(query, part.getName() + "_" + name, false)); //$NON-NLS-1$ |
|
430 |
return results; |
|
431 |
} |
|
432 |
|
|
433 |
/** |
|
434 |
* Gets the number of parts. |
|
435 |
* |
|
436 |
* @return the the number of parts. |
|
437 |
*/ |
|
438 |
public int getNPart() { |
|
439 |
return parts.size(); |
|
440 |
} |
|
441 |
|
|
442 |
/** |
|
443 |
* Gets the structure. |
|
444 |
* |
|
445 |
* @return the structure |
|
446 |
*/ |
|
447 |
public StructuralUnit getStructure() { |
|
448 |
return structure; |
|
449 |
} |
|
450 |
|
|
451 |
/** |
|
452 |
* Gets the property. |
|
453 |
* |
|
454 |
* @return the property |
|
455 |
*/ |
|
456 |
public Property getProperty() { |
|
457 |
return property; |
|
458 |
} |
|
459 |
|
|
460 |
/** |
|
461 |
* Create a lexical table for this partition given an analysis property. |
|
462 |
* Lexical table are cached and recycled. In order to drop from memory a |
|
463 |
* lexical table, use {@link #dropLexicalTable(Property)}. |
|
464 |
* |
|
465 |
* @param analysisProperty the analysis property |
|
466 |
* @param Fmin the fmin |
|
467 |
* @return the lexical table |
|
468 |
* @throws StatException the stat exception |
|
469 |
* @throws CqiClientException the cqi client exception |
|
470 |
* @author sloiseau |
|
471 |
*/ |
|
472 |
public LexicalTable getLexicalTable(Property analysisProperty, int Fmin) |
|
473 |
throws StatException, CqiClientException { |
|
474 |
// System.out.println("CL : test si déja existant ds cache"); |
|
475 |
/*if (lexicalTables.containsKey(analysisProperty.getName())) { |
|
476 |
if (lexicalTables.get(analysisProperty.getName()).getConstructorFmin() == Fmin) |
|
477 |
return lexicalTables.get(analysisProperty.getName()); |
|
478 |
}*/ |
|
479 |
// System.out.println("CL : fait un new lexique"); |
|
480 |
LexicalTable t = LexicalTableImpl.getLexicalTable(this, |
|
481 |
analysisProperty, Fmin); |
|
482 |
|
|
483 |
// System.out.println("CL : put results ds le cache"); |
|
484 |
lexicalTables.put(analysisProperty.getName(), t); |
|
485 |
return t; |
|
486 |
} |
|
487 |
|
|
488 |
/** |
|
489 |
* Drop a lexical table from the cache. Return the dropped lexical table, or |
|
490 |
* <code>null</code> if no lexical table was existing for this analysis |
|
491 |
* property. |
|
492 |
* |
|
493 |
* @param analysisProperty the analysis property |
|
494 |
* @return the lexical table |
|
495 |
* @author sloiseau |
|
496 |
*/ |
|
497 |
public LexicalTable dropLexicalTable(Property analysisProperty) { |
|
498 |
return lexicalTables.remove(analysisProperty.getName()); |
|
499 |
} |
|
500 |
|
|
501 |
/** |
|
502 |
* Stores the result of textometric computation in this corpus. |
|
503 |
* |
|
504 |
* @param result the result |
|
505 |
*/ |
|
506 |
public void storeResult(Object result) { |
|
507 |
results.add(result); |
|
508 |
} |
|
509 |
|
|
510 |
/** |
|
511 |
* Removes a result stored in thsi corpus. |
|
512 |
* |
|
513 |
* @param result the result |
|
514 |
* @return true, if successful |
|
515 |
*/ |
|
516 |
@Override |
|
517 |
public boolean removeResult(Object result) { |
|
518 |
boolean ret = results.remove(result); |
|
519 |
if (result instanceof LexicalTable) |
|
520 |
{ |
|
521 |
lexicalTables.remove(((LexicalTable)result).getProperty().getName()); |
|
522 |
} |
|
523 |
return ret; |
|
524 |
} |
|
525 |
|
|
526 |
/** |
|
527 |
* Gets the results of textometric computation stored in the corpus. |
|
528 |
* |
|
529 |
* @return the results |
|
530 |
*/ |
|
531 |
@Override |
|
532 |
public List<Object> getResults() { |
|
533 |
return results; |
|
534 |
} |
|
535 |
|
|
536 |
/** |
|
537 |
* Sets the name. |
|
538 |
* |
|
539 |
* @param name2 the new name |
|
540 |
*/ |
|
541 |
public void setName(String name2) { |
|
542 |
this.name = name2; |
|
543 |
if(this.selfElement != null) |
|
544 |
this.selfElement.setAttribute("name", name); //$NON-NLS-1$ |
|
545 |
} |
|
546 |
|
|
547 |
/* (non-Javadoc) |
|
548 |
* @see org.txm.objects.TxmObject#getChildren() |
|
549 |
*/ |
|
550 |
@Override |
|
551 |
public List<? extends TxmObject> getChildren() { |
|
552 |
return parts; |
|
553 |
} |
|
554 |
|
|
555 |
/* (non-Javadoc) |
|
556 |
* @see org.txm.objects.TxmObject#getParent() |
|
557 |
*/ |
|
558 |
@Override |
|
559 |
public TxmObject getParent() { |
|
560 |
return this.corpus; |
|
561 |
} |
|
562 |
|
|
563 |
/** |
|
564 |
* Register to parent. |
|
565 |
* |
|
566 |
* @param partitionName the partition name |
|
567 |
*/ |
|
568 |
private void registerToParent(String partitionName) { |
|
569 |
if (this.selfElement == null && this.getParent() != null) |
|
570 |
try { |
|
571 |
Element parentElem = (Element) this.getParent().getSelfElement(); |
|
572 |
if (parentElem == null) return; |
|
573 |
Document doc = parentElem.getOwnerDocument(); |
|
574 |
Element corporaElem; |
|
575 |
if (this.getParent() instanceof MainCorpus) { |
|
576 |
NodeList corporaList = parentElem.getElementsByTagName("preBuild"); //$NON-NLS-1$ |
|
577 |
corporaElem = (Element) corporaList.item(0); |
|
578 |
} else { |
|
579 |
corporaElem = parentElem; |
|
580 |
} |
|
581 |
Element partitionElem = doc.createElement("partition"); //$NON-NLS-1$ |
|
582 |
partitionElem.setAttribute("name", partitionName); //$NON-NLS-1$ |
|
583 |
corporaElem.appendChild(partitionElem); |
|
584 |
this.selfElement = partitionElem; |
|
585 |
for (Part p : parts) { |
|
586 |
Element partElem = doc.createElement("part"); //$NON-NLS-1$ |
|
587 |
partElem.setAttribute("name", p.getName()); //$NON-NLS-1$ |
|
588 |
partElem.setAttribute("shortname", p.getShortName()); //$NON-NLS-1$ |
|
589 |
partElem.setAttribute("query", p.getQuery().getQueryString()); //$NON-NLS-1$ |
|
590 |
partitionElem.appendChild(partElem); |
|
591 |
} |
|
592 |
} catch (Exception e) { |
|
593 |
System.out.println(Messages.Partition_21+e); |
|
594 |
} |
|
595 |
this.load(); |
|
596 |
} |
|
597 |
|
|
598 |
/** |
|
599 |
* Register to parent. |
|
600 |
*/ |
|
601 |
public void registerToParent() { |
|
602 |
registerToParent(this.name); |
|
603 |
} |
|
604 |
|
|
605 |
/* (non-Javadoc) |
|
606 |
* @see org.txm.objects.TxmObject#hasChildren(org.txm.objects.TxmObject) |
|
607 |
*/ |
|
608 |
@Override |
|
609 |
public boolean hasChildren(TxmObject children) { |
|
610 |
return parts.size() > 0; |
|
611 |
} |
|
612 |
|
|
613 |
/** |
|
614 |
* Load. |
|
615 |
* |
|
616 |
* @param e the e |
|
617 |
* @return true, if successful |
|
618 |
*/ |
|
619 |
public boolean load(Element e) { |
|
620 |
this.selfElement = e; |
|
621 |
return this.load(); |
|
622 |
} |
|
623 |
|
|
624 |
/* (non-Javadoc) |
|
625 |
* @see org.txm.objects.TxmObject#load() |
|
626 |
*/ |
|
627 |
@Override |
|
628 |
public boolean load() { |
|
629 |
if (this.selfElement != null && this.getParent() != null) { |
|
630 |
NodeList partList = selfElement.getChildNodes(); |
|
631 |
for (int i = 0; i < partList.getLength(); i++) { |
|
632 |
if (partList.item(i).getNodeType() == 1) { |
|
633 |
Element c = (Element) partList.item(i); |
|
634 |
if (c.getNodeName().equals("part")) //$NON-NLS-1$ |
|
635 |
{ |
|
636 |
String pname = c.getAttribute("name"); //$NON-NLS-1$ |
|
637 |
String pshortname = c.getAttribute("shortname"); //$NON-NLS-1$ |
|
638 |
String pquery = c.getAttribute("query"); //$NON-NLS-1$ |
|
639 |
for (Part part : parts) |
|
640 |
if (part.getName().equals(pname)) { |
|
641 |
part.setName(pname); |
|
642 |
part.setShortName(pshortname); |
|
643 |
part.setQuery(pquery); |
|
644 |
} |
|
645 |
} |
|
646 |
} |
|
647 |
} |
|
648 |
this.loadMetadata(); |
|
649 |
return true; |
|
650 |
} |
|
651 |
|
|
652 |
return false; |
|
653 |
} |
|
654 |
|
|
655 |
/* (non-Javadoc) |
|
656 |
* @see org.txm.objects.TxmObject#removeChildren(org.txm.objects.TxmObject) |
|
657 |
*/ |
|
658 |
@Override |
|
659 |
public TxmObject removeChildren(TxmObject children) { |
|
660 |
if (children instanceof Part) { |
|
661 |
if (children.getSelfElement() != null && children.getSelfElement().getParentNode() == selfElement) |
|
662 |
selfElement.removeChild(children.getSelfElement()); |
|
663 |
parts.remove(children); |
|
664 |
return children; |
|
665 |
} |
|
666 |
return null; |
|
667 |
} |
|
668 |
|
|
669 |
/* (non-Javadoc) |
|
670 |
* @see org.txm.objects.TxmObject#save() |
|
671 |
*/ |
|
672 |
@Override |
|
673 |
public boolean save() { |
|
674 |
return false; |
|
675 |
} |
|
676 |
|
|
677 |
/* (non-Javadoc) |
|
678 |
* @see org.txm.objects.TxmObject#delete() |
|
679 |
*/ |
|
680 |
@Override |
|
681 |
public boolean delete() { |
|
682 |
try { |
|
683 |
this.getCorpus().dropPartition(this); |
|
684 |
this.selfElement.getParentNode().removeChild(selfElement); |
|
685 |
return true; |
|
686 |
} catch (CqiClientException e) { |
|
687 |
// TODO Auto-generated catch block |
|
688 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
689 |
} |
|
690 |
return false; |
|
691 |
} |
|
692 |
|
|
693 |
/* (non-Javadoc) |
|
694 |
* @see org.txm.HasResults#getSubHasResults() |
|
695 |
*/ |
|
696 |
@Override |
|
697 |
public List<HasResults> getSubHasResults() { |
|
698 |
return new ArrayList<HasResults>(0); |
|
699 |
} |
|
700 |
|
|
701 |
int totalsize = -1; |
|
702 |
public int getTotalSize() throws CqiClientException { |
|
703 |
if (totalsize == -1) { |
|
704 |
totalsize = 0; |
|
705 |
for (Part p : parts) { |
|
706 |
totalsize += p.getSize(); |
|
707 |
} |
|
708 |
} |
|
709 |
return totalsize; |
|
710 |
} |
|
711 |
|
|
712 |
int[] partSizes; |
|
713 |
public int[] getPartSizes() throws CqiClientException { |
|
714 |
if (partSizes != null) |
|
715 |
return partSizes; |
|
716 |
partSizes = new int[getParts().size()]; |
|
717 |
for (int i = 0 ; i < getParts().size() ; i++) { |
|
718 |
Part p = getParts().get(i); |
|
719 |
partSizes[i] = p.getSize(); |
|
720 |
} |
|
721 |
return partSizes; |
|
722 |
} |
|
723 |
|
|
724 |
/** |
|
725 |
* Gets a copy of the parts sorted by descendant size order. |
|
726 |
* @return |
|
727 |
*/ |
|
728 |
public List<Part> getPartsSortedBySize() { |
|
729 |
|
|
730 |
List<Part> sortedParts = new ArrayList<Part>(this.parts); |
|
731 |
|
|
732 |
Collections.sort(sortedParts, new Comparator<Part>() { |
|
733 |
@Override |
|
734 |
public int compare(Part arg0, Part arg1) { |
|
735 |
try { |
|
736 |
return arg1.getSize() - arg0.getSize(); |
|
737 |
} catch (CqiClientException e) { |
|
738 |
return 0; |
|
739 |
} |
|
740 |
} |
|
741 |
}); |
|
742 |
|
|
743 |
return sortedParts; |
|
744 |
} |
|
745 |
|
|
746 |
} |
|
0 | 747 |
tmp/org.txm.partition.core/src/org/txm/partition/core/preferences/PartitionDimensionsPreferences.java (revision 118) | ||
---|---|---|
1 |
package org.txm.partition.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 |
* Default preferences initializer. |
|
11 |
* @author sjacquot |
|
12 |
* |
|
13 |
*/ |
|
14 |
public class PartitionDimensionsPreferences extends TXMPreferences { |
|
15 |
|
|
16 |
|
|
17 |
// auto populate the preference node qualifier from the current bundle id |
|
18 |
public static final String PREFERENCES_NODE = FrameworkUtil.getBundle(PartitionDimensionsPreferences.class).getSymbolicName(); |
|
19 |
|
|
20 |
public static final String PREFERENCES_PREFIX = "partition_"; //$NON-NLS-1$ |
|
21 |
|
|
22 |
public static final String CHART_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE = PREFERENCES_PREFIX + "chart_dimensions_display_parts_count_in_title"; //$NON-NLS-1$ |
|
23 |
public static final String CHART_DIMENSIONS_SORTED_BY_SIZE = PREFERENCES_PREFIX + "chart_dimensions_sort_by_parts_size"; //$NON-NLS-1$ |
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
public PartitionDimensionsPreferences() { |
|
28 |
// TODO Auto-generated constructor stub |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public void initializeDefaultPreferences() { |
|
33 |
Preferences preferences = DefaultScope.INSTANCE.getNode(PREFERENCES_NODE); |
|
34 |
preferences.putBoolean(CHART_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE, true); |
|
35 |
preferences.putBoolean(CHART_DIMENSIONS_SORTED_BY_SIZE, false); |
|
36 |
|
|
37 |
// shared charts rendering preferences |
|
38 |
super.initializeChartsEngineSharedPreferences(preferences); |
|
39 |
} |
|
40 |
|
|
41 |
} |
|
0 | 42 |
tmp/org.txm.partition.core/src/org/txm/partition/core/messages/TBXPartitionMessages.java (revision 118) | ||
---|---|---|
1 |
package org.txm.partition.core.messages; |
|
2 |
|
|
3 |
import org.eclipse.osgi.util.NLS; |
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
public class TBXPartitionMessages extends NLS { |
|
8 |
|
|
9 |
private static final String BUNDLE_NAME = "org.txm.partition.core.messages.messages"; //$NON-NLS-1$ |
|
10 |
|
|
11 |
public static String CHARTSENGINE_CANT_CREATE_PARTITION_DIMENSIONS_FILE_CHART; |
|
12 |
public static String CHARTSENGINE_PARTITION_DIMENSIONS_SORTED_BY_SIZE; |
|
13 |
public static String CHARTSENGINE_PARTITION_DIMENSIONS_DIMENSIONS_OF_PARTITION; |
|
14 |
public static String CHARTSENGINE_PARTITION_DIMENSIONS_PARTS; |
|
15 |
public static String CHARTSENGINE_PARTITION_DIMENSIONS_CATEGORY; |
|
16 |
public static String CHARTSENGINE_PARTITION_DIMENSIONS_X_AXIS_LABEL; |
|
17 |
public static String CHARTSENGINE_PARTITION_DIMENSIONS_Y_AXIS_LABEL; |
|
18 |
|
|
19 |
static { |
|
20 |
// initialize resource bundle |
|
21 |
NLS.initializeMessages(BUNDLE_NAME, TBXPartitionMessages.class); |
|
22 |
} |
|
23 |
|
|
24 |
private TBXPartitionMessages() { |
|
25 |
} |
|
26 |
} |
|
0 | 27 |
tmp/org.txm.partition.core/src/org/txm/partition/core/messages/messages.properties (revision 118) | ||
---|---|---|
1 |
CHARTSENGINE_CANT_CREATE_PARTITION_DIMENSIONS_FILE_CHART=Can''t create dimensions partition chart file (charts engine: {0}) |
|
2 |
CHARTSENGINE_PARTITION_DIMENSIONS_CATEGORY=t |
|
3 |
CHARTSENGINE_PARTITION_DIMENSIONS_DIMENSIONS_OF_PARTITION=Dimensions of the {0} partition in the {1} corpus |
|
4 |
CHARTSENGINE_PARTITION_DIMENSIONS_SORTED_BY_SIZE=\n Sorted by size |
|
5 |
CHARTSENGINE_PARTITION_DIMENSIONS_X_AXIS_LABEL=Part |
|
6 |
CHARTSENGINE_PARTITION_DIMENSIONS_Y_AXIS_LABEL=Number of words |
|
7 |
CHARTSENGINE_PARTITION_DIMENSIONS_PARTS=Part(s) |
|
0 | 8 |
tmp/org.txm.partition.core/src/org/txm/partition/core/messages/messages_fr.properties (revision 118) | ||
---|---|---|
1 |
CHARTSENGINE_CANT_CREATE_PARTITION_DIMENSIONS_FILE_CHART=Impossible de cr?er le fichier du graphique des dimensions de la partition (moteur de production de graphiques: {0}) |
|
2 |
CHARTSENGINE_PARTITION_DIMENSIONS_CATEGORY=t |
|
3 |
CHARTSENGINE_PARTITION_DIMENSIONS_DIMENSIONS_OF_PARTITION=Dimensions de la partition {0} du corpus {1} |
|
4 |
CHARTSENGINE_PARTITION_DIMENSIONS_SORTED_BY_SIZE=\n Tri?es par taille |
|
5 |
CHARTSENGINE_PARTITION_DIMENSIONS_X_AXIS_LABEL=Partie |
|
6 |
CHARTSENGINE_PARTITION_DIMENSIONS_Y_AXIS_LABEL=Nombre de mots |
|
7 |
CHARTSENGINE_PARTITION_DIMENSIONS_PARTS=Partie(s) |
|
0 | 8 |
tmp/org.txm.partition.core/src/org/txm/partition/core/chartsengine/r/RPartitionDimensionsPieChartCreator.java (revision 118) | ||
---|---|---|
1 |
package org.txm.partition.core.chartsengine.r; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.txm.chartsengine.r.core.RChartCreator; |
|
7 |
import org.txm.chartsengine.r.core.RChartsEngine; |
|
8 |
import org.txm.core.preferences.TXMPreferences; |
|
9 |
import org.txm.partition.core.chartsengine.base.Utils; |
|
10 |
import org.txm.partition.core.messages.TBXPartitionMessages; |
|
11 |
import org.txm.partition.core.preferences.PartitionDimensionsPreferences; |
|
12 |
import org.txm.searchengine.cqp.corpus.Part; |
|
13 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
14 |
import org.txm.stat.engine.r.RWorkspace; |
|
15 |
import org.txm.utils.logger.Log; |
|
16 |
|
|
17 |
/** |
|
18 |
* Creates a partition dimensions pie chart from the specified <code>Partition</code> result. |
|
19 |
* @author sjacquot |
|
20 |
* |
|
21 |
*/ |
|
22 |
public class RPartitionDimensionsPieChartCreator extends RChartCreator { |
|
23 |
|
|
24 |
public RPartitionDimensionsPieChartCreator() { |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public Object createChart(Object resultData, String preferencesNode) { |
|
29 |
return null; |
|
30 |
} |
|
31 |
|
|
32 |
|
|
33 |
@Override |
|
34 |
public File createChartFile(Object resultData, File file, String preferencesNode) { |
|
35 |
|
|
36 |
try { |
|
37 |
|
|
38 |
Partition partition = (Partition) resultData; |
|
39 |
|
|
40 |
// parameters |
|
41 |
boolean sortPartsBySize = TXMPreferences.getBoolean(preferencesNode, resultData, PartitionDimensionsPreferences.CHART_DIMENSIONS_SORTED_BY_SIZE); |
|
42 |
boolean displayPartsCountInTitle = TXMPreferences.getBoolean(preferencesNode, resultData, PartitionDimensionsPreferences.CHART_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE); |
|
43 |
|
|
44 |
RWorkspace r = RWorkspace.getRWorkspaceInstance(); |
|
45 |
|
|
46 |
List<Part> parts; |
|
47 |
|
|
48 |
// Sort parts by descendant size order |
|
49 |
if(sortPartsBySize) { |
|
50 |
parts = partition.getPartsSortedBySize(); |
|
51 |
} |
|
52 |
// Default parts order |
|
53 |
else { |
|
54 |
parts = partition.getParts(); |
|
55 |
} |
|
56 |
|
|
57 |
// Create parts names command string |
|
58 |
String snames = "c("; //$NON-NLS-1$ |
|
59 |
for(int i = 0; i < parts.size(); i++) { |
|
60 |
String name = parts.get(i).getName(); |
|
61 |
if(name.trim().length() == 0) |
|
62 |
name = "N/A"; //$NON-NLS-1$ |
|
63 |
snames += "\"" + name + "\""; //$NON-NLS-1$ //$NON-NLS-2$ |
|
64 |
if(i != parts.size() - 1) |
|
65 |
snames += ","; //$NON-NLS-1$ |
|
66 |
} |
|
67 |
snames += ")"; //$NON-NLS-1$ |
|
68 |
|
|
69 |
// Create parts sizes command string |
|
70 |
String ssizes = "c("; //$NON-NLS-1$ |
|
71 |
|
|
72 |
for(int i = 0; i < parts.size(); i++) { |
|
73 |
ssizes += "" + parts.get(i).getSize(); //$NON-NLS-1$ |
|
74 |
if(i != parts.size() - 1) |
|
75 |
ssizes += ","; //$NON-NLS-1$ |
|
76 |
} |
|
77 |
ssizes += ")"; //$NON-NLS-1$ |
|
78 |
|
|
79 |
// Create chart title |
|
80 |
String title = Utils.createPartitionDimensionsChartTitle(partition, sortPartsBySize, displayPartsCountInTitle); |
|
81 |
|
|
82 |
String ylab = TBXPartitionMessages.CHARTSENGINE_PARTITION_DIMENSIONS_Y_AXIS_LABEL; |
|
83 |
|
|
84 |
String cmd = "pie(" + ssizes + ", labels=" + snames + //$NON-NLS-1$ //$NON-NLS-2$ |
|
85 |
", main=\"" + title + "\", horiz=F, las=2, ylab=\"" + ylab + "\")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
86 |
|
|
87 |
|
|
88 |
((RChartsEngine) this.chartsEngine).plot(file, cmd); |
|
89 |
} |
|
90 |
catch(Exception e) { |
|
91 |
Log.severe(TBXPartitionMessages.bind(TBXPartitionMessages.CHARTSENGINE_CANT_CREATE_PARTITION_DIMENSIONS_FILE_CHART, RChartsEngine.DESCRIPTION) + e); |
|
92 |
} |
|
93 |
|
|
94 |
return file; |
|
95 |
} |
|
96 |
|
|
97 |
|
|
98 |
@Override |
|
99 |
public Class getResultDataClass() { |
|
100 |
return Partition.class; |
|
101 |
} |
|
102 |
|
|
103 |
} |
|
0 | 104 |
tmp/org.txm.partition.core/src/org/txm/partition/core/chartsengine/r/RPartitionDimensionsBarChartCreator.java (revision 118) | ||
---|---|---|
1 |
package org.txm.partition.core.chartsengine.r; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.txm.chartsengine.r.core.RChartCreator; |
|
7 |
import org.txm.chartsengine.r.core.RChartsEngine; |
|
8 |
import org.txm.core.preferences.TXMPreferences; |
|
9 |
import org.txm.partition.core.chartsengine.base.Utils; |
|
10 |
import org.txm.partition.core.messages.TBXPartitionMessages; |
|
11 |
import org.txm.partition.core.preferences.PartitionDimensionsPreferences; |
|
12 |
import org.txm.searchengine.cqp.corpus.Part; |
|
13 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
14 |
import org.txm.stat.engine.r.RWorkspace; |
|
15 |
import org.txm.utils.logger.Log; |
|
16 |
|
|
17 |
/** |
|
18 |
* Creates a partition dimensions bar chart from the specified <code>Partition</code> result. |
|
19 |
* @author sjacquot |
|
20 |
* |
|
21 |
*/ |
|
22 |
public class RPartitionDimensionsBarChartCreator extends RChartCreator { |
|
23 |
|
|
24 |
public RPartitionDimensionsBarChartCreator() { |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public Object createChart(Object resultData, String preferencesNode) { |
|
29 |
return null; |
|
30 |
} |
|
31 |
|
|
32 |
|
|
33 |
@Override |
|
34 |
public File createChartFile(Object resultData, File file, String preferencesNode) { |
|
35 |
|
|
36 |
try { |
|
37 |
|
|
38 |
Partition partition = (Partition) resultData; |
|
39 |
|
|
40 |
// parameters |
|
41 |
boolean sortPartsBySize = TXMPreferences.getBoolean(preferencesNode, resultData, PartitionDimensionsPreferences.CHART_DIMENSIONS_SORTED_BY_SIZE); |
|
42 |
boolean displayPartsCountInTitle = TXMPreferences.getBoolean(preferencesNode, resultData, PartitionDimensionsPreferences.CHART_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE); |
|
43 |
|
|
44 |
|
|
45 |
RWorkspace r = RWorkspace.getRWorkspaceInstance(); |
|
46 |
|
|
47 |
List<Part> parts; |
|
48 |
|
|
49 |
// Sort parts by descendant size order |
|
50 |
if(sortPartsBySize) { |
|
51 |
parts = partition.getPartsSortedBySize(); |
|
52 |
} |
|
53 |
// Default parts order |
|
54 |
else { |
|
55 |
parts = partition.getParts(); |
|
56 |
} |
|
57 |
|
|
58 |
// Create parts names command string |
|
59 |
String snames = "c("; //$NON-NLS-1$ |
|
60 |
for(int i = 0; i < parts.size(); i++) { |
|
61 |
String name = parts.get(i).getName(); |
|
62 |
if(name.trim().length() == 0) |
|
63 |
name = "N/A"; //$NON-NLS-1$ |
|
64 |
snames += "\"" + name + "\""; //$NON-NLS-1$ //$NON-NLS-2$ |
|
65 |
if(i != parts.size() - 1) |
|
66 |
snames += ","; //$NON-NLS-1$ |
|
67 |
} |
|
68 |
snames += ")"; //$NON-NLS-1$ |
|
69 |
|
|
70 |
// Create parts sizes command string |
|
71 |
String ssizes = "c("; //$NON-NLS-1$ |
|
72 |
|
|
73 |
for(int i = 0; i < parts.size(); i++) { |
|
74 |
ssizes += "" + parts.get(i).getSize(); //$NON-NLS-1$ |
|
75 |
if(i != parts.size() - 1) |
|
76 |
ssizes += ","; //$NON-NLS-1$ |
|
77 |
} |
|
78 |
ssizes += ")"; //$NON-NLS-1$ |
|
79 |
|
|
80 |
// Create chart title |
|
81 |
String title = Utils.createPartitionDimensionsChartTitle(partition, sortPartsBySize, displayPartsCountInTitle); |
|
82 |
|
|
83 |
String ylab = TBXPartitionMessages.CHARTSENGINE_PARTITION_DIMENSIONS_Y_AXIS_LABEL; |
|
84 |
|
|
85 |
String cmd = "barplot(" + ssizes + ", names.arg=" + snames + //$NON-NLS-1$ //$NON-NLS-2$ |
|
86 |
", main=\"" + title + "\", horiz=F, las=2, ylab=\"" + ylab + "\")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
87 |
|
|
88 |
((RChartsEngine) this.chartsEngine).plot(file, cmd); |
|
89 |
} |
|
90 |
catch(Exception e) { |
|
91 |
Log.severe(TBXPartitionMessages.bind(TBXPartitionMessages.CHARTSENGINE_CANT_CREATE_PARTITION_DIMENSIONS_FILE_CHART, RChartsEngine.DESCRIPTION) + e); |
|
92 |
Log.printStackTrace(e); |
|
93 |
} |
|
94 |
|
|
95 |
return file; |
|
96 |
} |
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
@Override |
|
102 |
public Class getResultDataClass() { |
|
103 |
return Partition.class; |
|
104 |
} |
|
105 |
|
|
106 |
} |
|
0 | 107 |
tmp/org.txm.partition.core/src/org/txm/partition/core/chartsengine/base/Utils.java (revision 118) | ||
---|---|---|
1 |
package org.txm.partition.core.chartsengine.base; |
|
2 |
|
|
3 |
import org.txm.partition.core.messages.TBXPartitionMessages; |
|
4 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
5 |
|
|
6 |
/** |
|
7 |
* Creates a partition dimensions bar chart from the specified <code>Partition</code> result. |
|
8 |
* @author sjacquot |
|
9 |
* |
|
10 |
*/ |
|
11 |
public abstract class Utils { |
|
12 |
|
|
13 |
public Utils() { |
|
14 |
// TODO Auto-generated constructor stub |
|
15 |
} |
|
16 |
|
|
17 |
|
|
18 |
/** |
|
19 |
* Creates a string title, shared by charts engine implementations, for the dimensions partition chart from the specified result. |
|
20 |
* @param the partition result |
|
21 |
* @param sortPartsBySize the sort parts by size state |
|
22 |
* @param displayPartsCountInTitle display or not the parts count in chart title |
|
23 |
* @return the title string |
|
24 |
*/ |
|
25 |
public static String createPartitionDimensionsChartTitle(Partition partition, boolean sortPartsBySize, boolean displayPartsCountInTitle) { |
|
26 |
|
|
27 |
String title = TBXPartitionMessages.bind(TBXPartitionMessages.CHARTSENGINE_PARTITION_DIMENSIONS_DIMENSIONS_OF_PARTITION, partition.getName(), partition.getCorpus().getName()); |
|
28 |
|
|
29 |
if(displayPartsCountInTitle) { |
|
30 |
title += "\n(" + partition.getParts().size() + " " + TBXPartitionMessages.CHARTSENGINE_PARTITION_DIMENSIONS_PARTS + ")"; //$NON-NLS-1$ //$NON-NLS-3$ |
|
31 |
} |
|
32 |
|
|
33 |
if(sortPartsBySize) { |
|
34 |
title += TBXPartitionMessages.CHARTSENGINE_PARTITION_DIMENSIONS_SORTED_BY_SIZE; |
|
35 |
} |
|
36 |
|
|
37 |
return title; |
|
38 |
} |
|
39 |
|
|
40 |
} |
|
0 | 41 |
tmp/org.txm.partition.core/src/org/txm/partition/core/chartsengine/jfreechart/JFCPartitionDimensionsBarChartCreator.java (revision 118) | ||
---|---|---|
1 |
package org.txm.partition.core.chartsengine.jfreechart; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import org.jfree.chart.JFreeChart; |
|
6 |
import org.jfree.chart.axis.NumberAxis; |
|
7 |
import org.jfree.data.general.DatasetUtilities; |
|
8 |
import org.jfree.data.xy.XYSeries; |
|
9 |
import org.jfree.data.xy.XYSeriesCollection; |
|
10 |
import org.txm.chartsengine.core.ChartsEngine; |
|
11 |
import org.txm.chartsengine.jfreechart.core.JFCChartCreator; |
|
12 |
import org.txm.chartsengine.jfreechart.core.JFCChartsEngine; |
|
13 |
import org.txm.chartsengine.jfreechart.core.renderers.interfaces.IItemSelectionRenderer; |
|
14 |
import org.txm.chartsengine.jfreechart.core.themes.base.ExtendedNumberAxis; |
|
15 |
import org.txm.core.preferences.TXMPreferences; |
|
16 |
import org.txm.partition.core.chartsengine.base.Utils; |
|
17 |
import org.txm.partition.core.messages.TBXPartitionMessages; |
|
18 |
import org.txm.partition.core.preferences.PartitionDimensionsPreferences; |
|
19 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
20 |
import org.txm.searchengine.cqp.corpus.Part; |
|
21 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
22 |
|
|
23 |
/** |
|
24 |
* Creates a partition dimensions bar chart from the specified <code>Partition</code> result. |
|
25 |
* @author sjacquot |
|
26 |
* |
|
27 |
*/ |
|
28 |
public class JFCPartitionDimensionsBarChartCreator extends JFCChartCreator { |
|
29 |
|
|
30 |
public JFCPartitionDimensionsBarChartCreator() { |
|
31 |
} |
|
32 |
|
|
33 |
@Override |
|
34 |
public JFreeChart createChart(Object resultData, String preferencesNode) { |
|
35 |
|
|
36 |
Partition partition = (Partition) resultData; |
|
37 |
|
|
38 |
|
|
39 |
// parameters |
|
40 |
boolean sortPartsBySize = TXMPreferences.getBoolean(preferencesNode, resultData, PartitionDimensionsPreferences.CHART_DIMENSIONS_SORTED_BY_SIZE); |
|
41 |
boolean displayPartsCountInTitle = TXMPreferences.getBoolean(preferencesNode, resultData, PartitionDimensionsPreferences.CHART_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE); |
|
42 |
|
|
43 |
JFreeChart chart = null; |
|
44 |
|
|
45 |
|
|
46 |
try { |
|
47 |
// Creating the data set from the partition result |
|
48 |
XYSeriesCollection dataset = new XYSeriesCollection(); |
|
49 |
|
|
50 |
XYSeries series = new XYSeries(TBXPartitionMessages.CHARTSENGINE_PARTITION_DIMENSIONS_CATEGORY); |
|
51 |
dataset.addSeries(series); |
|
52 |
|
|
53 |
List<Part> parts; |
|
54 |
|
|
55 |
// Sort parts by descendant size order |
|
56 |
if (sortPartsBySize) { |
|
57 |
parts = partition.getPartsSortedBySize(); |
|
58 |
} |
|
59 |
// Default parts order |
|
60 |
else { |
|
61 |
parts = partition.getParts(); |
|
62 |
} |
|
63 |
|
|
64 |
|
|
65 |
String[] xAxisSymbols = new String[parts.size()]; |
|
66 |
|
|
67 |
|
|
68 |
for (int i = 0 ; i < parts.size() ; i++) { |
|
69 |
series.add(i, parts.get(i).getSize()); |
|
70 |
|
|
71 |
// Add X axis symbol |
|
72 |
xAxisSymbols[i] = parts.get(i).getName(); |
|
73 |
} |
|
74 |
|
|
75 |
// Create chart title |
|
76 |
String title = Utils.createPartitionDimensionsChartTitle(partition, sortPartsBySize, displayPartsCountInTitle); |
|
77 |
|
|
78 |
// Create the chart |
|
79 |
chart = this.getChartsEngine().createXYBarChart(dataset, title, TBXPartitionMessages.CHARTSENGINE_PARTITION_DIMENSIONS_X_AXIS_LABEL, TBXPartitionMessages.CHARTSENGINE_PARTITION_DIMENSIONS_Y_AXIS_LABEL, false, true, false, xAxisSymbols); |
|
80 |
((IItemSelectionRenderer) chart.getXYPlot().getRenderer()).setChartType(ChartsEngine.CHART_TYPE_PARTITION_DIMENSIONS); |
|
81 |
|
|
82 |
|
|
83 |
// Custom range axis for ticks drawing options |
|
84 |
chart.getXYPlot().setRangeAxis(new ExtendedNumberAxis((NumberAxis) chart.getXYPlot().getRangeAxis(), false, true, 0, DatasetUtilities.findMaximumRangeValue(chart.getXYPlot().getDataset()).doubleValue())); |
|
85 |
|
|
86 |
this.getChartsEngine().getTheme().apply(chart); |
|
87 |
|
|
88 |
} |
|
89 |
catch(CqiClientException e) { |
|
90 |
e.printStackTrace(); |
|
91 |
} |
|
92 |
|
|
93 |
return chart; |
|
94 |
|
|
95 |
} |
|
96 |
|
|
97 |
|
|
98 |
@Override |
|
99 |
public Class getResultDataClass() { |
|
100 |
return Partition.class; |
|
101 |
} |
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
} |
|
0 | 108 |
tmp/org.txm.partition.core/src/org/txm/partition/core/chartsengine/jfreechart/JFCPartitionDimensionsPieChartCreator.java (revision 118) | ||
---|---|---|
1 |
package org.txm.partition.core.chartsengine.jfreechart; |
|
2 |
import java.util.List; |
|
3 |
|
|
4 |
import org.jfree.chart.JFreeChart; |
|
5 |
import org.jfree.data.general.DefaultPieDataset; |
|
6 |
import org.jfree.data.xy.XYSeries; |
|
7 |
import org.txm.chartsengine.jfreechart.core.JFCChartCreator; |
|
8 |
import org.txm.core.preferences.TXMPreferences; |
|
9 |
import org.txm.partition.core.chartsengine.base.Utils; |
|
10 |
import org.txm.partition.core.messages.TBXPartitionMessages; |
|
11 |
import org.txm.partition.core.preferences.PartitionDimensionsPreferences; |
|
12 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
13 |
import org.txm.searchengine.cqp.corpus.Part; |
|
14 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
15 |
|
|
16 |
/** |
|
17 |
* Creates a partition dimensions pie chart from the specified <code>Partition</code> result. |
|
18 |
* @author sjacquot |
|
19 |
* |
|
20 |
*/ |
|
21 |
|
|
22 |
public class JFCPartitionDimensionsPieChartCreator extends JFCChartCreator { |
|
23 |
|
|
24 |
public JFCPartitionDimensionsPieChartCreator() { |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public Object createChart(Object resultData, String preferencesNode) { |
|
29 |
|
|
30 |
Partition partition = (Partition) resultData; |
|
31 |
|
|
32 |
// parameters |
|
33 |
boolean sortPartsBySize = TXMPreferences.getBoolean(preferencesNode, resultData, PartitionDimensionsPreferences.CHART_DIMENSIONS_SORTED_BY_SIZE); |
|
34 |
boolean displayPartsCountInTitle = TXMPreferences.getBoolean(preferencesNode, resultData, PartitionDimensionsPreferences.CHART_DIMENSIONS_DISPLAY_PARTS_COUNT_IN_TITLE); |
|
35 |
|
|
36 |
|
|
37 |
JFreeChart chart = null; |
|
38 |
|
|
39 |
try { |
|
40 |
// Creating the data set from the partition result |
|
41 |
DefaultPieDataset dataset = new DefaultPieDataset(); |
|
42 |
|
|
43 |
XYSeries series = new XYSeries(TBXPartitionMessages.CHARTSENGINE_PARTITION_DIMENSIONS_CATEGORY); |
|
44 |
|
|
45 |
List<Part> parts; |
|
46 |
|
|
47 |
// Sort parts by descendant size order |
|
48 |
if (sortPartsBySize) { |
|
49 |
parts = partition.getPartsSortedBySize(); |
|
50 |
} |
|
51 |
// Default parts order |
|
52 |
else { |
|
53 |
parts = partition.getParts(); |
|
54 |
} |
|
55 |
|
|
56 |
|
|
57 |
for (int i = 0 ; i < parts.size() ; i++) { |
|
58 |
dataset.setValue(parts.get(i).getName(), parts.get(i).getSize()); |
|
59 |
} |
|
60 |
|
|
61 |
// Create chart title |
|
62 |
String title = Utils.createPartitionDimensionsChartTitle(partition, sortPartsBySize, displayPartsCountInTitle); |
|
63 |
|
|
64 |
// Create the chart |
|
65 |
chart = this.getChartsEngine().createPieChart(dataset, title, true); |
|
66 |
//((IItemSelectionRenderer) chart.getXYPlot().getRenderer()).setChartType(___ChartsEngine.CHART_TYPE_PARTITION_DIMENSIONS); |
|
67 |
|
|
68 |
|
|
69 |
this.getChartsEngine().getTheme().apply(chart); |
|
70 |
|
|
71 |
} |
|
72 |
catch(CqiClientException e) { |
|
73 |
e.printStackTrace(); |
|
74 |
} |
|
75 |
|
|
76 |
|
|
77 |
return chart; |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public Class getResultDataClass() { |
|
82 |
return Partition.class; |
|
83 |
} |
|
84 |
} |
|
0 | 85 |
tmp/org.txm.partition.core/build.properties (revision 118) | ||
---|---|---|
1 |
source.. = src/ |
|
2 |
output.. = bin/ |
|
3 |
bin.includes = META-INF/,\ |
|
4 |
.,\ |
|
5 |
plugin.xml |
|
0 | 6 |
tmp/org.txm.partition.core/plugin.xml (revision 118) | ||
---|---|---|
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.partition.core.preferences.PartitionDimensionsPreferences"> |
|
8 |
</initializer> |
|
9 |
</extension> |
|
10 |
<extension |
|
11 |
point="org.txm.chartsengine.chartcreator"> |
|
12 |
<ChartCreator |
|
13 |
chartType="Partition Dimensions Bar Chart" |
|
14 |
chartsEngineName="jfreechart_charts_engine" |
|
15 |
class="org.txm.partition.core.chartsengine.jfreechart.JFCPartitionDimensionsBarChartCreator" |
|
16 |
fileNamePrefix="info"> |
|
17 |
</ChartCreator> |
|
18 |
<ChartCreator |
|
19 |
chartType="Partition Dimensions Pie Chart" |
|
20 |
chartsEngineName="jfreechart_charts_engine" |
|
21 |
class="org.txm.partition.core.chartsengine.jfreechart.JFCPartitionDimensionsPieChartCreator" |
|
22 |
fileNamePrefix="partition_dimensions"> |
|
23 |
</ChartCreator> |
|
24 |
<ChartCreator |
|
25 |
chartType="Partition Dimensions Bar Chart" |
|
26 |
chartsEngineName="r_charts_engine" |
|
27 |
class="org.txm.partition.core.chartsengine.r.RPartitionDimensionsBarChartCreator" |
|
28 |
fileNamePrefix="info"> |
|
29 |
</ChartCreator> |
|
30 |
<ChartCreator |
|
31 |
chartType="Partition Dimensions Pie Chart" |
|
32 |
chartsEngineName="r_charts_engine" |
|
33 |
class="org.txm.partition.core.chartsengine.r.RPartitionDimensionsPieChartCreator" |
|
34 |
fileNamePrefix="partition_dimensions"> |
|
35 |
</ChartCreator> |
|
36 |
</extension> |
|
37 |
|
|
38 |
</plugin> |
|
0 | 39 |
tmp/org.txm.partition.core/.settings/org.eclipse.jdt.core.prefs (revision 118) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 |
|
4 |
org.eclipse.jdt.core.compiler.compliance=1.7 |
|
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.7 |
|
0 | 8 |
tmp/org.txm.partition.core/.classpath (revision 118) | ||
---|---|---|
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.7"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
|
5 |
<classpathentry kind="src" path="src"/> |
|
6 |
<classpathentry kind="output" path="bin"/> |
|
7 |
</classpath> |
|
0 | 8 |
tmp/org.txm.partition.core/META-INF/MANIFEST.MF (revision 118) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: Partition TBX |
|
4 |
Bundle-SymbolicName: org.txm.partition.core;singleton:=true |
|
5 |
Bundle-Version: 1.0.0.qualifier |
|
6 |
Require-Bundle: org.eclipse.core.runtime, |
|
7 |
org.txm.chartsengine.core, |
|
8 |
org.txm.core;bundle-version="0.7.0", |
|
9 |
org.txm.chartsengine.rcp;bundle-version="1.0.0", |
|
10 |
org.txm.chartsengine.jfreechart.core;bundle-version="1.0.0", |
|
11 |
org.txm.chartsengine.r.core;bundle-version="1.0.0" |
|
12 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 |
|
13 |
Export-Package: org.txm.partition.core.chartsengine.base, |
|
14 |
org.txm.partition.core.chartsengine.jfreechart, |
|
15 |
org.txm.partition.core.chartsengine.r, |
|
16 |
org.txm.partition.core.corpusengine.cqp, |
|
17 |
org.txm.partition.core.messages, |
Formats disponibles : Unified diff