Revision 2596

tmp/org.txm.ca.core/src/org/txm/ca/core/statsengine/r/functions/CA.java (revision 2596)
435 435
		}
436 436
		return singularValues2;
437 437
	}
438
	
439
	@Override
440
	public String getEigenvaluesRSymbol() throws StatException {
441
		return symbol+"$sv";
442
	}
438 443

  
439 444
	/* (non-Javadoc)
440 445
	 * @see org.txm.stat.engine.r.function.ICA#getSymbol()
tmp/org.txm.ca.core/src/org/txm/ca/core/statsengine/r/functions/FactoMineRCA.java (revision 2596)
446 446
		return eigenvalues;
447 447
		
448 448
	}
449
	
450
	/**
451
	 * Gets the valeurs propres.
452
	 *
453
	 * @return the singular values pow 2
454
	 * @throws StatException the stat exception
455
	 */
456
	@Override
457
	public String getEigenvaluesRSymbol() throws StatException {
458
		return symbol+"$eig$eigenvalue";
459
	}
449 460

  
450 461
	/* (non-Javadoc)
451 462
	 * @see org.txm.stat.engine.r.function.ICA#loadLibrary()
tmp/org.txm.ca.core/src/org/txm/ca/core/statsengine/r/functions/ICA.java (revision 2596)
170 170
	 * @throws StatException the stat exception
171 171
	 */
172 172
	public double[] getEigenvalues() throws StatException;
173
	
174
	/**
175
	 * Gets the valeurs propres.
176
	 *
177
	 * @return the valeurs propres
178
	 * @throws StatException the stat exception
179
	 */
180
	public String getEigenvaluesRSymbol() throws StatException;
173 181

  
174 182
	/**
175 183
	 * Load library.
tmp/org.txm.ca.core/src/org/txm/ca/core/functions/CA.java (revision 2596)
47 47
import org.txm.lexicaltable.core.functions.LexicalTable;
48 48
import org.txm.searchengine.cqp.corpus.Property;
49 49
import org.txm.statsengine.core.StatException;
50
import org.txm.statsengine.r.core.RResult;
50 51
import org.txm.statsengine.r.core.RWorkspace;
51 52
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
52 53
import org.txm.utils.logger.Log;
......
59 60
 * @author sloiseau
60 61
 * 
61 62
 */
62
public class CA extends ChartResult {
63
public class CA extends ChartResult implements RResult {
63 64
	
64 65
	/** The ca. */
65 66
	private ICA r_ca;
......
864 865
		return svtabledata;
865 866
	}
866 867
	
867
	/**
868
	 * Gets the symbol.
869
	 *
870
	 * @return the R symbol of the CA result
871
	 */
872
	public String getSymbol() {
868
	@Override
869
	public String getRSymbol() {
873 870
		return r_ca.getSymbol();
874 871
	}
875 872
	
tmp/org.txm.ca.core/src/org/txm/ca/core/functions/Eigenvalues.java (revision 2596)
10 10
import org.txm.core.preferences.TXMPreferences;
11 11
import org.txm.core.results.TXMParameters;
12 12
import org.txm.core.results.TXMResult;
13
import org.txm.statsengine.core.StatException;
14
import org.txm.statsengine.r.core.RResult;
13 15

  
14 16
/**
15 17
 * Eigenvalues chart result.
......
17 19
 * @author sjacquot
18 20
 *
19 21
 */
20
public class Eigenvalues extends ChartResult {
22
public class Eigenvalues extends ChartResult implements RResult {
21 23
	
22 24
	/**
23 25
	 * @param parent
......
71 73
	}
72 74
	
73 75
	@Override
76
	public String getRSymbol() {
77
		try {
78
			return this.getCA().getCA().getEigenvaluesRSymbol();
79
		} catch (Exception e) {
80
			e.printStackTrace();
81
			return null;
82
		}
83
	}
84
	
85
	@Override
74 86
	public void clean() {
75 87
		// nothing to do
76 88
	}
tmp/org.txm.specificities.core/src/org/txm/specificities/core/functions/Specificities.java (revision 2596)
50 50
import org.txm.searchengine.cqp.corpus.Partition;
51 51
import org.txm.searchengine.cqp.corpus.Property;
52 52
import org.txm.searchengine.cqp.corpus.WordProperty;
53
import org.txm.specificities.core.chartsengine.r.RSpecificitiesBarChartCreator;
53 54
import org.txm.specificities.core.messages.SpecificitiesCoreMessages;
54 55
import org.txm.specificities.core.preferences.SpecificitiesPreferences;
55 56
import org.txm.specificities.core.statsengine.r.function.SpecificitiesR;
......
57 58
import org.txm.statsengine.core.data.Vector;
58 59
import org.txm.statsengine.core.utils.ArrayIndex;
59 60
import org.txm.statsengine.core.utils.CheckArray;
61
import org.txm.statsengine.r.core.RResult;
60 62
import org.txm.statsengine.r.core.RWorkspace;
61 63
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
62 64
import org.txm.utils.logger.Log;
......
64 66
/**
65 67
 * Compute specificities indexes using a {@link LexicalTable}
66 68
 * 
67
 * for alternative and test usages, the Specificities.computeIndex(...) method can be used.
69
 * for alternative and test usages, the Specificities.computeIndex(...) method
70
 * can be used.
68 71
 * 
69 72
 * @author mdecorde
70 73
 * @author sloiseau
71 74
 * 
72 75
 */
73
public class Specificities extends TXMResult {
74
	
76
public class Specificities extends TXMResult implements RResult {
77

  
75 78
	public static int MAXSPECIF = 1000;
76
	
79

  
77 80
	/** The indices. */
78 81
	private double[][] indices;
79
	
82

  
80 83
	/** The rowindex. */
81 84
	private int[] rowindex = null;
82
	
85

  
83 86
	/** The colindex. */
84 87
	private int[] colindex = null;
85
	
88

  
86 89
	/** The frequencies. */
87 90
	private int[][] frequencies = null;
88
	
91

  
89 92
	/** The colnames. */
90 93
	private List<String> colnames = null;
91
	
94

  
92 95
	/** The rownames. */
93 96
	private List<String> rownames = null;
94
	
97

  
95 98
	/** The symbol. */
96 99
	private String symbol;
97
	
100

  
98 101
	/** The writer. */
99 102
	@Deprecated
100 103
	private BufferedWriter writer;
101
	
102
	/** The table. contains **all** the corpus data necessary to compute the Specificities */
104

  
105
	/**
106
	 * The table. contains **all** the corpus data necessary to compute the
107
	 * Specificities
108
	 */
103 109
	private LexicalTable lexicalTable;
104
	
110

  
105 111
	/**
106 112
	 * Maximum score.
107 113
	 */
108 114
	@Parameter(key = SpecificitiesPreferences.MAX_SCORE)
109 115
	protected int maxScore;
110
	
111
	
116

  
112 117
	/**
113 118
	 * Creates a not computed Specificities.
114 119
	 * 
......
117 122
	public Specificities(LexicalTable parent) {
118 123
		super(parent);
119 124
	}
120
	
125

  
121 126
	/**
122 127
	 * Creates a not computed Specificities.
123 128
	 * 
......
126 131
	public Specificities(String parametersNodePath) {
127 132
		this(parametersNodePath, null);
128 133
	}
129
	
134

  
130 135
	/**
131 136
	 * Creates a not computed Specificities.
132 137
	 *
133 138
	 * @param parent the table
134 139
	 * @return the specificities result
135 140
	 * @throws CqiClientException the cqi client exception
136
	 * @throws StatException the stat exception
141
	 * @throws StatException      the stat exception
137 142
	 */
138 143
	public Specificities(String parametersNodePath, LexicalTable parent) {
139 144
		super(parametersNodePath, parent);
140 145
	}
141
	
146

  
142 147
	@Override
143 148
	public boolean loadParameters() {
144 149
		this.lexicalTable = (LexicalTable) this.parent;
145 150
		return true;
146 151
	}
147
	
152

  
148 153
	@Override
149 154
	public boolean saveParameters() {
150 155
		// nothing to do
151 156
		return true;
152 157
	}
153
	
154
	
155
	
158

  
156 159
	@Override
157 160
	protected boolean _compute() throws Exception {
158
		
161

  
159 162
		this.frequencies = null;
160
		
161
		// delete the specificities selection chart children since they can not be valid anymore if the unit property has changed
163

  
164
		// delete the specificities selection chart children since they can not be valid
165
		// anymore if the unit property has changed
162 166
		// FIXME: doesn't work
163 167
		if (this.lexicalTable.hasParameterChanged(TBXPreferences.UNIT_PROPERTY)) {
164 168
			this.deleteChildren(SpecificitiesSelection.class);
165 169
		}
166
		
170

  
167 171
		ILexicalTable data = this.lexicalTable.getData();
168 172
		SpecificitiesR rSpecificities = new SpecificitiesR(data);
169 173
		double[][] specIndex = rSpecificities.getScores();
170
		
174

  
171 175
		// TODO if test no more necessary ? only if lexicalTable symb
172 176
		// if (this.lexicalTable.getPartition() != null) {
173 177
		// init(symbol, specIndex);
174 178
		// }
175 179
		// else {
176 180
		init(rSpecificities.getSymbol(), specIndex);
181
		this.symbol = rSpecificities.getSymbol();
177 182
		// }
178 183
		// }
179
		
184

  
180 185
		return true;
181 186
	}
182
	
187

  
183 188
	/**
184 189
	 * Instantiates a new specificities result.
185 190
	 *
186
	 * @param symbol the symbol
191
	 * @param symbol    the symbol
187 192
	 * @param specIndex the spec index (as double[row][column])
188
	 * @param table the table
189
	 * @param typeFocus names of the rows of the lexical table with corresponding rows
190
	 *            in the specIndex array; <code>null</code> if all the rows are
191
	 *            represented in specIndex.
192
	 * @param partFocus names of the cols of the lexical table with corresponding cols
193
	 *            in the specIndex array; <code>null</code> if all the cols are
194
	 *            represented in specIndex.
195
	 * @param name the name
196
	 * @param maxScore if abs(score) > maxScore -> score = +/- maxScore
193
	 * @param table     the table
194
	 * @param typeFocus names of the rows of the lexical table with corresponding
195
	 *                  rows in the specIndex array; <code>null</code> if all the
196
	 *                  rows are represented in specIndex.
197
	 * @param partFocus names of the cols of the lexical table with corresponding
198
	 *                  cols in the specIndex array; <code>null</code> if all the
199
	 *                  cols are represented in specIndex.
200
	 * @param name      the name
201
	 * @param maxScore  if abs(score) > maxScore -> score = +/- maxScore
197 202
	 * @throws StatException the stat exception
198 203
	 */
199 204
	protected void init(String symbol, double[][] specIndex) throws Exception {
200
		
205

  
201 206
		if (this.symbol != null && this.symbol.equals(symbol)) {
202 207
			try {
203 208
				RWorkspace.getRWorkspaceInstance().removeVariableFromWorkspace(this.symbol);
204
			}
205
			catch (RWorkspaceException e) {
209
			} catch (RWorkspaceException e) {
206 210
				e.printStackTrace();
207 211
			}
208 212
		}
209 213
		this.symbol = symbol;
210
		
214

  
211 215
		if (this.lexicalTable == null) {
212 216
			throw new IllegalArgumentException(SpecificitiesCoreMessages.theLexicalTableCannotBeNull);
213 217
		}
214 218
		// this.name = name;
215
		
219

  
216 220
		if (specIndex == null || specIndex.length == 0) {
217 221
			throw new IllegalArgumentException(SpecificitiesCoreMessages.noSpecificitiesIndexArray);
218 222
		}
219 223
		boolean ok = CheckArray.checkMatrixRepresentation(specIndex);
220 224
		if (!ok) {
221
			throw new IllegalArgumentException(SpecificitiesCoreMessages.theSpecificityIndexArrayDoesNotProperlyRepresentAMatrix);
225
			throw new IllegalArgumentException(
226
					SpecificitiesCoreMessages.theSpecificityIndexArrayDoesNotProperlyRepresentAMatrix);
222 227
		}
223
		
228

  
224 229
		this.indices = specIndex;
225 230
		this.colnames = Arrays.asList(lexicalTable.getColNames().asStringsArray());
226 231
		this.rownames = Arrays.asList(lexicalTable.getRowNames().asStringsArray());
227
		
232

  
228 233
		// filter by max&min
229 234
		int MAX = MAXSPECIF;
230 235
		int MIN = -MAXSPECIF;
231
		
236

  
232 237
		if (maxScore > 0) {
233 238
			MAX = maxScore;
234 239
			MIN = -maxScore;
235 240
		}
236
		
241

  
237 242
		for (int i = 0; i < indices.length; i++) {
238 243
			for (int j = 0; j < indices[i].length; j++) {
239 244
				if (indices[i][j] > MAX) {
240 245
					indices[i][j] = MAX;
241
				}
242
				else if (indices[i][j] < MIN) {
246
				} else if (indices[i][j] < MIN) {
243 247
					indices[i][j] = MIN;
244 248
				}
245 249
			}
246 250
		}
247
		
251

  
248 252
		if (this.rownames != null && this.rownames.size() != 0) {
249 253
			if (this.rownames.size() != specIndex.length) {
250 254
				throw new IllegalArgumentException(
251
						SpecificitiesCoreMessages.bind(SpecificitiesCoreMessages.numberOfRowsWantedP0AndFoundP1Mismatch, this.rownames.size(), specIndex.length));
255
						SpecificitiesCoreMessages.bind(SpecificitiesCoreMessages.numberOfRowsWantedP0AndFoundP1Mismatch,
256
								this.rownames.size(), specIndex.length));
252 257
			}
253
			
254
			rowindex = ArrayIndex.getIndex(this.lexicalTable.getRowNames().asStringsArray(), this.rownames.toArray(new String[] {}));
258

  
259
			rowindex = ArrayIndex.getIndex(this.lexicalTable.getRowNames().asStringsArray(),
260
					this.rownames.toArray(new String[] {}));
255 261
			for (int i : rowindex) {
256 262
				if (i == -1) {
257 263
					throw new IllegalArgumentException(SpecificitiesCoreMessages.referenceToNonExistingRow);
......
275 281
		// }
276 282
		// }
277 283
	}
278
	
279
	
284

  
280 285
	/**
281 286
	 * Utility method to compute the specificity index of a word in a subcorpus.
282 287
	 * <br>
......
297 302
	public static double computeIndex(int f, int F, int t, int T) throws Exception {
298 303
		RWorkspace rw = RWorkspace.getRWorkspaceInstance();
299 304
		rw.voidEval("library(textometry)");
300
		REXP rez = rw.eval("specificities(matrix(c(" + f + ", " + (t - f) + ", " + (F - f) + ", " + (T - t - F + f) + "), ncol=2))");
305
		REXP rez = rw.eval("specificities(matrix(c(" + f + ", " + (t - f) + ", " + (F - f) + ", " + (T - t - F + f)
306
				+ "), ncol=2))");
301 307
		if (rez != null) {
302 308
			return rez.asDoubles()[0];
303 309
		}
304 310
		return 0.0d;
305 311
	}
306
	
307
	
312

  
308 313
	/**
309 314
	 * Sets the unit property.
310 315
	 * 
......
313 318
	public void setUnitProperty(WordProperty unitProperty) {
314 319
		this.getLexicalTable().setUnitProperty(unitProperty);
315 320
	}
316
	
321

  
317 322
	/**
318 323
	 * Gets the type focus.
319 324
	 *
......
322 327
	public List<String> getTypeFocus() {
323 328
		return rownames;
324 329
	}
325
	
330

  
326 331
	/**
327 332
	 * Gets the part focus.
328 333
	 *
......
331 336
	public List<String> getPartFocus() {
332 337
		return colnames;
333 338
	}
334
	
339

  
335 340
	/**
336 341
	 * Gets the number of columns of the lexical table.
337 342
	 *
......
342 347
		if (lexicalTable != null) {
343 348
			try {
344 349
				return lexicalTable.getNColumns();
345
			}
346
			catch (Exception e) {
350
			} catch (Exception e) {
347 351
				// TODO Auto-generated catch block
348 352
				e.printStackTrace();
349 353
				return 0;
350 354
			}
351
		}
352
		else {
355
		} else {
353 356
			return getColumnsNames().length;
354 357
		}
355 358
	}
356
	
359

  
357 360
	/**
358 361
	 * Gets the sum of all the columns frequencies.
359 362
	 *
......
363 366
	public int getFrequenciesSum() throws StatException {
364 367
		if (lexicalTable.getData() != null) {
365 368
			return lexicalTable.getData().getTotal();
366
		}
367
		else {
369
		} else {
368 370
			return 0;
369 371
		}
370 372
	}
371
	
373

  
372 374
	/**
373 375
	 * Gets the sums of each columns frequencies.
374 376
	 *
375 377
	 * @return the sums of each columns frequencies
376
	 * @throws StatException the stat exception
378
	 * @throws StatException      the stat exception
377 379
	 * @throws CqiClientException
378 380
	 */
379 381
	public int[] getColumnsFrequenciesSums() throws StatException, CqiClientException {
380
		
382

  
381 383
		if (
382 384
		// this.lexicalTable != null &&
383 385
		this.lexicalTable.hasBeenComputedOnce()) {
......
386 388
				colsSizes = colsSizes.get(colindex);
387 389
			}
388 390
			return colsSizes.asIntArray();
389
		}
390
		else if (this.lexicalTable.getPartition() != null) {
391
		} else if (this.lexicalTable.getPartition() != null) {
391 392
			return this.lexicalTable.getPartition().getPartSizes();
392
		}
393
		else {
393
		} else {
394 394
			return new int[] { 0, 0 };
395 395
		}
396 396
		// if (lexicalTable != null && this.subCorpus == null
......
409 409
		// }
410 410
		// else {
411 411
		// try {
412
		// return new int[] { subLexicon.nbrOfToken(), lexicon.nbrOfToken() - subLexicon.nbrOfToken() };
412
		// return new int[] { subLexicon.nbrOfToken(), lexicon.nbrOfToken() -
413
		// subLexicon.nbrOfToken() };
413 414
		// }
414 415
		// // case of Subcorpus specificities (the lexicons has not yet been computed)
415 416
		// catch (Exception e) {
......
417 418
		// }
418 419
		// }
419 420
	}
420
	
421

  
421 422
	@Override
422 423
	public LexicalTable getParent() {
423 424
		return (LexicalTable) this.parent;
424 425
	}
425
	
426

  
426 427
	/**
427 428
	 * Gets the specificities index.
428 429
	 * 
......
431 432
	public double[][] getSpecificitesIndex() {
432 433
		return indices;
433 434
	}
434
	
435

  
435 436
	/**
436 437
	 * Name of the type for which specificities are computed.
437 438
	 *
......
441 442
	public String[] getTypeNames() throws Exception {
442 443
		return lexicalTable.getRowNames().asStringsArray();
443 444
	}
444
	
445

  
445 446
	/**
446 447
	 * Gets the names of the lexical table columns.
447 448
	 *
......
451 452
	public String[] getColumnsNames() throws StatException {
452 453
		return lexicalTable.getColNames().asStringsArray();
453 454
	}
454
	
455

  
455 456
	/**
456 457
	 * Gets the frequencies of all columns.
457 458
	 *
......
465 466
			// if (lexicalTable != null) {
466 467
			// System.out.println("FROM TABLE");
467 468
			frequencies = RWorkspace.getRWorkspaceInstance().evalToInt2D(lexicalTable.getData().getSymbol());
468
			
469

  
469 470
			// }
470 471
			// else {// if table == null : subcorpus specif
471 472
			// //System.out.println("FROM LEXICON");
472
			// frequencies = new int[lexicon.getFreq().length][2]; // build a frequency table from lexicons
473
			// frequencies = new int[lexicon.getFreq().length][2]; // build a frequency
474
			// table from lexicons
473 475
			// String[] corpusforms = lexicon.getForms(); // all the forms
474 476
			// String[] subcorpusforms = subLexicon.getForms(); // all the forms
475 477
			// int[] corpusfreq = lexicon.getFreq(); // all the freqs
......
492 494
		}
493 495
		return frequencies;
494 496
	}
495
	
497

  
496 498
	/**
497 499
	 * Gets the lexical table.
498 500
	 *
......
501 503
	public LexicalTable getLexicalTable() {
502 504
		return lexicalTable;
503 505
	}
504
	
506

  
505 507
	/**
506 508
	 * The frequency in the whole corpus.
507 509
	 *
......
516 518
		// }
517 519
		return formFrequencies.asIntArray();
518 520
	}
519
	
521

  
520 522
	@Override
521 523
	public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception {
522
		
523
		// NK: Declared as class attribute to perform a clean if the operation is interrupted
524

  
525
		// NK: Declared as class attribute to perform a clean if the operation is
526
		// interrupted
524 527
		// OutputStreamWriter writer;
525 528
		try {
526 529
			this.writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfile), encoding));
527
		}
528
		catch (UnsupportedEncodingException e1) {
530
		} catch (UnsupportedEncodingException e1) {
529 531
			org.txm.utils.logger.Log.printStackTrace(e1);
530 532
			return false;
531
		}
532
		catch (FileNotFoundException e1) {
533
		} catch (FileNotFoundException e1) {
533 534
			org.txm.utils.logger.Log.printStackTrace(e1);
534 535
			return false;
535 536
		}
536
		
537

  
537 538
		// int[] T = getPartSize();
538 539
		acquireSemaphore();
539 540
		try {
......
547 548
				txt += colseparator + "f_" + colname + colseparator + "score_" + colname; //$NON-NLS-1$ //$NON-NLS-2$
548 549
			}
549 550
			writer.write(txt + "\n"); //$NON-NLS-1$
550
			
551

  
551 552
			// write data
552 553
			for (int ii = 0; ii < frequencies.length; ii++) {
553
				txt = txtseparator + getTypeNames()[ii].replace(txtseparator, txtseparator + txtseparator) + txtseparator;
554
				txt = txtseparator + getTypeNames()[ii].replace(txtseparator, txtseparator + txtseparator)
555
						+ txtseparator;
554 556
				int somme = 0;
555 557
				String txtcols = ""; //$NON-NLS-1$
556 558
				for (int j = 0; j < frequencies[ii].length; j++) {
......
562 564
				writer.flush();
563 565
			}
564 566
			writer.close();
565
		}
566
		catch (IOException e) {
567
		} catch (IOException e) {
567 568
			org.txm.utils.logger.Log.printStackTrace(e);
568 569
			return false;
569
		}
570
		finally {
570
		} finally {
571 571
			releaseSemaphore();
572 572
		}
573
		
573

  
574 574
		return true;
575 575
	}
576
	
576

  
577 577
	@Override
578 578
	public void clean() {
579 579
		try {
580 580
			if (symbol != null) {
581 581
				RWorkspace.getRWorkspaceInstance().removeVariableFromWorkspace(symbol);
582 582
			}
583
		}
584
		catch (RWorkspaceException e) {
583
		} catch (RWorkspaceException e) {
585 584
			// TODO Auto-generated catch block
586 585
			e.printStackTrace();
587 586
		}
588
		
587

  
589 588
		try {
590 589
			if (this.writer != null) {
591 590
				this.writer.flush();
592 591
				this.writer.close();
593 592
			}
594
		}
595
		catch (IOException e) {
593
		} catch (IOException e) {
596 594
			org.txm.utils.logger.Log.printStackTrace(e);
597 595
		}
598 596
	}
599
	
597

  
598
	@Override
599
	public String getRSymbol() {
600
		return this.symbol;
601
	}
602

  
600 603
	// /**
601
	// * Gets the symbol.
602
	// *
603
	// * @return the symbol
604
	// */
605
	// public String getSymbol() {
606
	// return symbol;
607
	// }
608
	
609
	// /**
610 604
	// * Gets the sorted part indexes.
611 605
	// *
612 606
	// * @return the sorted part indexes
......
641 635
	// }
642 636
	// return new int[0];
643 637
	// }
644
	
638

  
645 639
	@Override
646 640
	public String getName() {
647 641
		// FIXME: to define
648
		// if (this.specificitiesResult.getLexicalTable()!= null && this.specificitiesResult.getLexicalTable().getPartition() != null) {
649
		// setPartName(this.specificitiesResult.getLexicalTable().getPartition().getName()+": "+specificitiesResult.getName()); //$NON-NLS-1$
642
		// if (this.specificitiesResult.getLexicalTable()!= null &&
643
		// this.specificitiesResult.getLexicalTable().getPartition() != null) {
644
		// setPartName(this.specificitiesResult.getLexicalTable().getPartition().getName()+":
645
		// "+specificitiesResult.getName()); //$NON-NLS-1$
650 646
		// } else if (spinput.getSubcorpus() != null) {
651
		// setPartName(spinput.getSubcorpus().getName()+": "+specificitiesResult.getName()); //$NON-NLS-1$
647
		// setPartName(spinput.getSubcorpus().getName()+":
648
		// "+specificitiesResult.getName()); //$NON-NLS-1$
652 649
		// } else {
653 650
		// setPartName(specificitiesResult.getName());
654 651
		// }
......
660 657
			// else {
661 658
			// return this.lexicalTable.getParent().toString();
662 659
			// }
663
		}
664
		catch (Exception e) {
660
		} catch (Exception e) {
665 661
			return this.getEmptyName();
666 662
		}
667 663
	}
668
	
669
	
670
	
664

  
671 665
	@Override
672 666
	public String getSimpleName() {
673 667
		return this.getName();
674 668
	}
675
	
669

  
676 670
	@Override
677 671
	public String getDetails() {
678 672
		return NLS.bind(this.getName() + " (max score={0})", this.maxScore);
679 673
	}
680
	
681
	
674

  
682 675
	@Override
683 676
	public String getComputingStartMessage() {
684 677
		// from lexical table
685 678
		if (this.parent.isVisible()) {
686
			return TXMCoreMessages.bind(SpecificitiesCoreMessages.info_specificitiesOfTheP0LexcialTable, this.getParent().getSimpleName());
687
		}
688
		else {
689
			
679
			return TXMCoreMessages.bind(SpecificitiesCoreMessages.info_specificitiesOfTheP0LexcialTable,
680
					this.getParent().getSimpleName());
681
		} else {
682

  
690 683
			// from partition
691 684
			if (this.getParent().getPartition() != null) {
692
				return TXMCoreMessages.bind(SpecificitiesCoreMessages.info_specificitiesOfTheP0PartitionCommaP1Property, this.getParent().getPartition().getSimpleName(), this.getParent()
693
						.getProperty());
685
				return TXMCoreMessages.bind(SpecificitiesCoreMessages.info_specificitiesOfTheP0PartitionCommaP1Property,
686
						this.getParent().getPartition().getSimpleName(), this.getParent().getProperty());
694 687
			}
695 688
			// from sub-corpus lexical table
696
			// FIXME: SJ: this special case is possible when creating Specificities then calling the command on the invisible Lexical Table
689
			// FIXME: SJ: this special case is possible when creating Specificities then
690
			// calling the command on the invisible Lexical Table
697 691
			// need to if we need a special log message here
698 692
			else {
699
				return TXMCoreMessages.bind(SpecificitiesCoreMessages.info_specificitiesOfTheP0Corpus, this.getParent().getParent().getSimpleName());
693
				return TXMCoreMessages.bind(SpecificitiesCoreMessages.info_specificitiesOfTheP0Corpus,
694
						this.getParent().getParent().getSimpleName());
700 695
			}
701 696
		}
702 697
	}
703
	
704
	
698

  
705 699
	@Override
706 700
	public boolean canCompute() {
707
		
701

  
708 702
		if (this.lexicalTable == null) {
709 703
			Log.severe("Specificities.canCompute(): can not compute without a lexical table.");
710 704
			return false;
711 705
		}
712
		
706

  
713 707
		// if (this.lexicalTable.getNColumns() < 2) {
714 708
		// Log.severe(SpecificitiesCoreMessages.ComputeError_NEED_AT_LEAST_2_PARTS);
715 709
		// return false;
716 710
		// }
717
		
711

  
718 712
		return this.lexicalTable.getProperty() != null;
719 713
	}
720
	
721
	
722
	
723
	
714

  
724 715
	/**
725 716
	 * @param maxScore the pMaxScore to set
726 717
	 */
727 718
	public void setMaxScore(int maxScore) {
728 719
		this.maxScore = maxScore;
729 720
	}
730
	
721

  
731 722
	@Override
732 723
	public boolean setParameters(TXMParameters parameters) {
733 724
		// TODO Auto-generated method stub
734 725
		System.err.println("Specificities.setParameters(): not yet implemented.");
735 726
		return true;
736 727
	}
737
	
738
	
728

  
739 729
	/**
740 730
	 * @return the maxScore
741 731
	 */
742 732
	public int getMaxScore() {
743 733
		return maxScore;
744 734
	}
745
	
735

  
746 736
	/**
747 737
	 * @return the unitProperty
748 738
	 */
749 739
	public Property getUnitProperty() {
750 740
		return this.getLexicalTable().getProperty();
751 741
	}
752
	
742

  
753 743
	@Override
754 744
	public String getResultType() {
755 745
		return SpecificitiesCoreMessages.RESULT_TYPE;
tmp/org.txm.ahc.core/src/org/txm/ahc/core/functions/AHC.java (revision 2596)
42 42
import org.txm.core.results.TXMParameters;
43 43
import org.txm.lexicaltable.core.functions.LexicalTable;
44 44
import org.txm.searchengine.cqp.corpus.Property;
45
import org.txm.statsengine.r.core.RResult;
45 46
import org.txm.statsengine.r.core.RWorkspace;
46 47
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
47 48
import org.txm.utils.logger.Log;
......
53 54
 * @author sjacquot
54 55
 *
55 56
 */
56
public class AHC extends ChartResult {
57
public class AHC extends ChartResult implements RResult {
57 58
	
58 59
	/**
59 60
	 * The R name prefix.
......
193 194
		try {
194 195
			CA ca = getParent();
195 196
			LexicalTable table = ca.getLexicalTable();
196
			this.target = ca.getSymbol();
197
			this.target = ca.getRSymbol();
197 198
			
198 199
			// reset the number of clusters to default if columns or rows computing has changed
199 200
			// if(this.hasParameterChanged(AHCPreferences.COLUMNS_COMPUTING)) {
......
304 305
		this.clusterMerges = null;
305 306
	}
306 307
	
307
	/**
308
	 * Gets the symbol.
309
	 *
310
	 * @return the symbol
311
	 */
312
	public String getSymbol() {
308
	@Override
309
	public String getRSymbol() {
313 310
		return symbol;
314 311
	}
315 312
	
tmp/org.txm.ahc.core/src/org/txm/ahc/core/chartsengine/r/RAHCChartCreator.java (revision 2596)
24 24
		String cmd = null;
25 25
		// 2D
26 26
		if (ahc.isRendering2D()) {
27
			cmd = "plot.HCPC(" + ahc.getSymbol() + ", new.plot=FALSE, choice=\"tree\")";
27
			cmd = "plot.HCPC(" + ahc.getRSymbol() + ", new.plot=FALSE, choice=\"tree\")";
28 28
			
29 29
			// FIXME: SJ: for tests without drawing the inertia barplot. Without it, the max available clusters can exceed 16
30 30
			// cmd = "plot.HCPC(" + cah.getSymbol() + ", new.plot=FALSE, choice=\"tree\", tree.barplot=FALSE)"; //$NON-NLS-1$ //$NON-NLS-2$
......
35 35
		}
36 36
		// 3D
37 37
		else {
38
			cmd = "plot.HCPC(" + ahc.getSymbol() + ", new.plot=FALSE)";
38
			cmd = "plot.HCPC(" + ahc.getRSymbol() + ", new.plot=FALSE)";
39 39
		}
40 40
		
41 41
		return this.getChartsEngine().plot(file, cmd);
tmp/org.txm.statsengine.r.rcp/src/org/txm/rcp/commands/R/CopySelection.java (revision 2596)
33 33
import org.eclipse.core.commands.ExecutionException;
34 34
import org.eclipse.jface.viewers.IStructuredSelection;
35 35
import org.eclipse.ui.handlers.HandlerUtil;
36
import org.txm.core.results.TXMResult;
37
import org.txm.statsengine.r.core.RResult;
36 38

  
37 39
// TODO: Auto-generated Javadoc
38 40
/**
......
60 62
	public static void copyFirst(IStructuredSelection selection)
61 63
	{
62 64
		Object selectedItem = selection.getFirstElement();
63
		String text = ""; //$NON-NLS-1$
64
		try {
65
			Method getname = selectedItem.getClass().getMethod("getSymbol"); //$NON-NLS-1$
66
			text = (String)getname.invoke(selectedItem);
67
		} catch (Exception e2) {}
68
		org.txm.rcp.utils.IOClipboard.write(text);
65
		if (selectedItem instanceof RResult) {
66
			org.txm.rcp.utils.IOClipboard.write(((RResult)selectedItem).getRSymbol());
67
		} else if (selectedItem instanceof TXMResult) {
68
			org.txm.rcp.utils.IOClipboard.write(((TXMResult)selectedItem).getName());
69
		} else {
70
			org.txm.rcp.utils.IOClipboard.write(selectedItem.toString());
71
		}
69 72
	}
70 73
}
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/views/RVariablesView.java (revision 2596)
61 61
import org.txm.Toolbox;
62 62
import org.txm.core.results.TXMResult;
63 63
import org.txm.objects.Project;
64
import org.txm.objects.Workspace;
64 65
import org.txm.rcp.IImageKeys;
65 66
import org.txm.rcp.commands.R.CopySelection;
66 67
import org.txm.rcp.handlers.files.EditFile;
......
69 70
import org.txm.searchengine.cqp.corpus.CorpusManager;
70 71
import org.txm.searchengine.cqp.corpus.MainCorpus;
71 72
import org.txm.searchengine.cqp.corpus.Partition;
73
import org.txm.statsengine.r.core.RResult;
72 74
import org.txm.statsengine.r.core.RWorkspace;
73 75
import org.txm.statsengine.r.rcp.messages.RUIMessages;
74 76
/**
......
109 111
		if (activepage == null)
110 112
			return;
111 113
		RVariablesView rview = (RVariablesView) activepage.findView(RVariablesView.ID);
112
		if (rview != null)
114
		if (rview != null) {
113 115
			rview._reload();
116
		}
114 117
	}
115 118

  
116 119
	/**
......
119 122
	public void _reload() {
120 123
		tv.setContentProvider(new RVariablesTreeProvider());
121 124
		tv.setLabelProvider(new RVariablesLabelProvider());
122
		Collection<MainCorpus> corpora;
123 125
		try {
124
			corpora = CorpusManager.getCorpusManager().getCorpora().values();
125
			if (corpora != null)
126
			{
127
				buildTreeContent(corpora);
126
				buildTreeContent();
128 127
				tv.refresh();
129
			}
130
		} catch (Exception e) { }
128
		} catch (Exception e) { e.printStackTrace();}
131 129
	}
132 130
	
133 131
	/**
......
135 133
	 *
136 134
	 * @param corpora the corpora
137 135
	 */
138
	protected void buildTreeContent(Collection<MainCorpus> corpora)
136
	protected void buildTreeContent()
139 137
	{
140
		ArrayList<TXMResult> notempty = new ArrayList<TXMResult>(corpora);
141
		for(TXMResult container : corpora)
142
		{
143
			String symbol = null;
144
			try {
145
				Method getname = container.getClass().getMethod("getSymbol"); //$NON-NLS-1$
146
				symbol = (String)getname.invoke(container);
147
			} catch (Exception e2) {}
148

  
149
			if (symbol != null)
150
				continue;
151
			
152
			//System.out.println("check "+container.getName());
153
			if (container.getChildren().size() > 0
154
					//FIXME: commented by SJ for TXMResult implementation
155
					//|| container.getSubHasResults().size() > 0
156
					)
157
			{
158
				if (!deepSearch(container))
159
					notempty.remove(container);
160
			}
161
			else
162
			{
163
				notempty.remove(container);
164
			}
138
		List<CQPCorpus> i = new ArrayList<CQPCorpus>();
139
		for (Project p : Workspace.getInstance().getProjects()) {
140
			i.addAll(p.getChildren(CQPCorpus.class));
165 141
		}
166
		tv.setInput(notempty);
142
		tv.setInput(i);
167 143
	}
168 144
		
169 145
	/**
......
199 175
	 * @return true, if successful
200 176
	 */
201 177
	private boolean hasSymbol(List<TXMResult> results) {
202
		String symbol = null;
203 178
		for(Object rez : results)
204 179
		{
205
			try {
206
				Method getname = rez.getClass().getMethod("getSymbol"); //$NON-NLS-1$
207
				symbol = (String)getname.invoke(rez);
208
			} catch (Exception e2) {}
209
			if (symbol != null)
180
			if (rez  instanceof RResult)
210 181
				return true;
211 182
		}
212 183
		return false;
......
218 189
	@Override
219 190
	public void createPartControl(Composite parent) {
220 191
		parent.setLayout(new GridLayout(2, true));
221
		Button export = new Button(parent, SWT.PUSH);
222
		export.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true,
192
		Button refreshButton = new Button(parent, SWT.PUSH);
193
		refreshButton.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true,
223 194
				false));
224
		export.setText(RUIMessages.refreshVariables);
225
		export.addSelectionListener(new SelectionListener() {
195
		refreshButton.setText(RUIMessages.refreshVariables);
196
		refreshButton.addSelectionListener(new SelectionListener() {
226 197
			@Override
227 198
			public void widgetSelected(SelectionEvent arg0) {
228 199
				//System.out.println("reload");
......
320 291
		 */
321 292
		@Override
322 293
		public String getText(Object element) {
323
			String name =""; //$NON-NLS-1$
324
			String symbol = null;
325

  
326
			try {
327
				Method getname = element.getClass().getMethod("getName"); //$NON-NLS-1$
328
				name = (String)getname.invoke(element);
329
			} catch (Exception e) {}
330

  
331
			try {
332
				Method getname = element.getClass().getMethod("getSymbol"); //$NON-NLS-1$
333
				symbol = (String)getname.invoke(element);
334
			} catch (Exception e) {}
335

  
336
			if (symbol == null)
337
				return name;
338
			else
339
				return NLS.bind(RUIMessages.tXMNameP0SupSupRNameP1, name, symbol);
294
			if (element instanceof RResult) {
295
				if (element instanceof TXMResult) {
296
					return NLS.bind(RUIMessages.tXMNameP0SupSupRNameP1, ((TXMResult)element).getName(), ((RResult)element).getRSymbol());
297
				} else {
298
					return ((RResult)element).getRSymbol();
299
				}
300
			} else if (element instanceof TXMResult) {
301
				return ((TXMResult)element).getName();
302
			} else {
303
				return element.toString();
304
			}
340 305
		}
341 306

  
342 307
		/* (non-Javadoc)
......
365 330
		public Object[] getChildren(Object element) {
366 331
			//System.out.println("get children of "+element);
367 332
			if (element instanceof TXMResult) {
368
//				List<Object> results = ((HasResults) element).getResults();
369
//				ArrayList<TXMResult> sub = ((HasResults) element).getSubHasResults();
370
				//ArrayList<Object> children = new ArrayList<Object>();
371
//				children.addAll(sub);
372
//				children.addAll(results);
333

  
373 334
				
374
				List<TXMResult> children = ((TXMResult)element).getDeepChildren();
335
				ArrayList<Object> rresults = new ArrayList<>();
336
				List<TXMResult> children = ((TXMResult)element).getChildren();
375 337
				
376
				for(int i = 0 ; i < children.size() ; i++)
338
				for(TXMResult r : children)
377 339
				{
378
					
379
					Object obj = children.get(i);
380
					//System.out.println("test > "+obj);
381
					if (obj instanceof TXMResult)
382
					{
383
						//System.out.println("deap "+obj);
384
						if (!deepSearch((TXMResult) obj))
385
						{
386
							children.remove(i);
387
							i--;
388
						}
340
					if (r instanceof RResult && ((RResult)r).getRSymbol() != null) {
341
						rresults.add(r);
342
					} else if (deepSearch(r)) {
343
						rresults.add(r);
389 344
					}
390
					else
391
					{
392
						String symbol = null;
393
						try {
394
							Method getname = obj.getClass().getMethod("getSymbol"); //$NON-NLS-1$
395
							symbol = (String)getname.invoke(obj);
396
						} catch (Exception e) {}
397
						//System.out.println("symbol "+symbol);
398
						if (symbol == null)
399
						{
400
							children.remove(i);
401
							i--;
402
						}
403
					}
404 345
				}
405 346
				//System.out.println(""+element+" > "+children);
406
				return children.toArray();
347
				return rresults.toArray();
407 348
			}
408 349
			return new Object[0];
409 350
		}
......
413 354
		 */
414 355
		@Override
415 356
		public Object getParent(Object element) {
416
			Partition partition = null;
417
			try {
418
				Method getname = element.getClass().getMethod("getPartition"); //$NON-NLS-1$
419
				partition = (Partition)getname.invoke(element);
420
			} catch (Exception e) {}
421
			
422
			if (partition == null)
423
			{
424
				return partition;
357
			if (element instanceof TXMResult) {
358
				TXMResult r = (TXMResult)element;
359
				Partition p = r.getFirstParent(Partition.class);
360
				if (p != null) {
361
					return p;
362
				}
363
				CQPCorpus c = r.getFirstParent(CQPCorpus.class);
364
				if (c != null) {
365
					return c;
366
				}
367
				
368
				return null;
369
			} else {
370
				return null;
425 371
			}
426
			
427
			CQPCorpus corpus = null;
428
			try {
429
				Method getname = element.getClass().getMethod("getCorpus"); //$NON-NLS-1$
430
				corpus = (CQPCorpus)getname.invoke(element);
431
			} catch (Exception e) {}
432
			
433
			return corpus;
434 372
		}
435 373
		
436 374
		/* (non-Javadoc)
......
449 387
		 */
450 388
		@Override
451 389
		public Object[] getElements(Object element) {
390
			System.out.println("input: "+element);
452 391
			Collection<Project> input = (Collection<Project>) element;
453 392
			Object[] objects = new Object[input.size()];
454 393
			Iterator<Project> it = input.iterator();
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/RResult.java (revision 2596)
1
package org.txm.statsengine.r.core;
2

  
3
public interface RResult {
4
	/**
5
	 * 
6
	 * @return the R result symbol if any (null if not linked to a R result)
7
	 */
8
	public String getRSymbol();
9
}
0 10

  
tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/functions/LexicalTable.java (revision 2596)
27 27
import org.txm.searchengine.cqp.corpus.Subcorpus;
28 28
import org.txm.searchengine.cqp.corpus.WordProperty;
29 29
import org.txm.statsengine.core.data.Vector;
30
import org.txm.statsengine.r.core.RResult;
30 31
import org.txm.statsengine.r.core.RWorkspace;
31 32
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
32 33
import org.txm.utils.logger.Log;
......
40 41
 * 
41 42
 */
42 43
// TODO: SJ: add a fMax filter
43
public class LexicalTable extends TXMResult {
44
public class LexicalTable extends TXMResult implements RResult {
44 45
	
45 46
	public static Integer LEXICALTABLE_COUNTER = new Integer(1);
46 47
	
......
436 437
		}
437 438
	}
438 439
	
440
	@Override
441
	public String getRSymbol() {
442
		if (statsData == null) return null;
443
		
444
		return statsData.getSymbol();
445
	}
446
	
439 447
	public Vector getColMarginsVector() {
440 448
		try {
441 449
			return statsData.getColMarginsVector();

Also available in: Unified diff