Révision 1426

tmp/org.txm.index.core/src/org/txm/index/core/functions/Lexicon.java (revision 1426)
124 124
	@Override
125 125
	public String getName() {
126 126
		try {
127
			return IndexCoreMessages.lexicon + ": " + this.getSimpleName();
127
			return this.getParent().getSimpleName() + ": " + this.getSimpleName();
128 128
		}
129 129
		catch(Exception e) {
130 130
			return this.getEmptyName();
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/utils/VectorizeArray.java (revision 1426)
113 113
	 */
114 114
	public final static int[] vectorizeByInner(int[][] matrix) {
115 115
		if (matrix == null || matrix.length == 0) {
116
			throw new IllegalArgumentException(StatsEngineCoreMessages.nothingToDoWithAnEmptyMatrix);
116
			//throw new IllegalArgumentException(StatsEngineCoreMessages.nothingToDoWithAnEmptyMatrix);
117
			return new int[0];
117 118
		}
118 119
		int inner_length = matrix[0].length;
120
		return vectorizeByInner(matrix, inner_length);
121
	}
122
	
123
	/**
124
	 * Convert a <code>int * int</code> array in a <code>double</code> array.
125
	 * Each inner array of the argument is added one after the other into the
126
	 * result array.
127
	 * 
128
	 * <pre>
129
	 * [
130
	 * [1, 2, 3],
131
	 * [4, 5, 6]
132
	 * ]
133
	 * </pre>
134
	 * 
135
	 * result in :
136
	 * 
137
	 * <pre>
138
	 * [1, 2, 3, 4, 5, 6]
139
	 * </pre>
140
	 * 
141
	 * that is, "row first".
142
	 *
143
	 * @param matrix a <code>int * int</code> array where all inner arrays have the
144
	 * same length.
145
	 * @return an array of <code>int</code> produced by vectorization of the
146
	 * matrix.
147
	 */
148
	public final static int[] vectorizeByInner(int[][] matrix, int inner_length) {
149
		
119 150
		if (inner_length < 1) {
120 151
			throw new IllegalArgumentException(StatsEngineCoreMessages.innerArraysMustBeOfDimensionSup0);
121 152
		}
122
		int[] vector = new int[matrix.length * matrix[0].length];
153
		int[] vector = new int[matrix.length * inner_length];
123 154
		for (int i = 0; i < matrix.length; i++) {
124 155
			if (matrix[i] == null) {
125 156
				throw new IllegalArgumentException(StatsEngineCoreMessages.anInnerArrayCannotBeNull);
......
159 190
	 */
160 191
	public final static double[] vectorizeByOuter(double[][] matrix) {
161 192
		if (matrix == null || matrix.length == 0) {
162
			throw new IllegalArgumentException(StatsEngineCoreMessages.nothingToDoWithAnEmptyMatrix);
193
			//throw new IllegalArgumentException(StatsEngineCoreMessages.nothingToDoWithAnEmptyMatrix);
194
			return new double[0];
163 195
		}
164 196
		int inner_length = matrix[0].length;
165 197
		int outer_length = matrix.length;
tmp/org.txm.specificities.core/src/org/txm/specificities/core/functions/Specificities.java (revision 1426)
37 37
import java.util.Arrays;
38 38
import java.util.List;
39 39

  
40
import org.eclipse.osgi.util.NLS;
40 41
import org.rosuda.REngine.REXP;
41 42
import org.txm.core.preferences.TBXPreferences;
42 43
import org.txm.core.results.Parameter;
......
102 103
	/** The writer. */
103 104
	@Deprecated
104 105
	private BufferedWriter writer;
105
	
106 106

  
107
	// FIXME: SJ: any way to simplify that? table, lexicon, subLexicon, corpus, subcorpus... 
108
	/** The table. */
107
	/** The table. contains **all** the corpus data necessary to compute the Specificities */
109 108
	private LexicalTable lexicalTable;
110 109

  
111
	/** The lexicon. */
112
	private CQPLexicon lexicon;
113

  
114
	/** The sub lexicon. */
115
	private CQPLexicon subLexicon;
116

  
117
	/** The corpus. */
118
	private CQPCorpus corpus;
119

  
120
	/** The sub corpus. */
121
	private CQPCorpus subCorpus;
122

  
123

  
124 110
	/**
125 111
	 * Maximum score.
126 112
	 */
127 113
	@Parameter(key=SpecificitiesPreferences.MAX_SCORE)
128 114
	protected int maxScore;
129
	
130
	
131
	
115

  
116

  
132 117
	/**
133 118
	 * Creates a not computed Specificities.
134 119
	 * @param parent
......
137 122
		super(parent);
138 123
	}
139 124

  
140

  
141
	
142 125
	/**
143 126
	 * Creates a not computed Specificities.
144 127
	 * @param parametersNodePath
......
146 129
	public Specificities(String parametersNodePath)	{
147 130
		this(parametersNodePath, null);
148 131
	}
149
	
132

  
150 133
	/**
151 134
	 * Creates a not computed Specificities.
152 135
	 *
......
158 141
	public Specificities(String parametersNodePath, LexicalTable parent) {
159 142
		super(parametersNodePath, parent);
160 143
	}
161
	
162
	
163
	
144

  
164 145
	@Override
165 146
	public boolean loadParameters() {
166 147
		this.lexicalTable = (LexicalTable) this.parent;
167
		
168
		CQPCorpus corpus = CQPCorpus.getFirstParentCorpus(this);
169
		this.corpus = corpus;
170
		if(corpus instanceof Subcorpus)	{
171
			this.subCorpus = corpus;
172
		}
173
		
148

  
149
		//		CQPCorpus corpus = CQPCorpus.getFirstParentCorpus(this);
150
		//		this.corpus = corpus;
151
		//		if(corpus instanceof Subcorpus)	{
152
		//			this.subCorpus = corpus;
153
		//		}
154

  
174 155
		return true;
175 156
	}
176 157

  
......
179 160
		// nothing to do
180 161
		return true;
181 162
	}
182
	
183 163

  
184
	
185 164

  
165

  
186 166
	@Override
187 167
	protected boolean _compute() throws Exception {
188 168

  
......
193 173
		if (this.lexicalTable.hasParameterChanged(TBXPreferences.UNIT_PROPERTY))	{
194 174
			this.deleteChildren(SpecificitiesSelection.class);
195 175
		}
196
		
176

  
197 177
		//if (this.lexicalTable.hasBeenComputedOnce())	{ // LT should have been computed one because of TXMResult.compute
198
		
178

  
199 179
		ILexicalTable data = this.lexicalTable.getData();
200
		
201
			SpecificitiesR rSpecificities = new SpecificitiesR(data);
202
			double[][] specIndex = rSpecificities.getScores();
203 180

  
204
			if (this.lexicalTable.getPartition() != null) {
205
				init(symbol, specIndex); 
206
			}
207
			else {
208
				init(rSpecificities.getSymbol(), specIndex); //$NON-NLS-1$
209
			}
181
		SpecificitiesR rSpecificities = new SpecificitiesR(data);
182
		double[][] specIndex = rSpecificities.getScores();
183

  
184
		if (this.lexicalTable.getPartition() != null) {
185
			init(symbol, specIndex); 
186
		}
187
		else {
188
			init(rSpecificities.getSymbol(), specIndex); //$NON-NLS-1$
189
		}
210 190
		//}
211
		
191

  
212 192
		return true;
213 193
	}
214
	
194

  
215 195
	/**
216 196
	 * Instantiates a new specificities result.
217 197
	 *
......
229 209
	 * @throws StatException the stat exception
230 210
	 */
231 211
	protected void init(String symbol, double[][] specIndex) throws Exception {
232
		
212

  
233 213
		this.symbol = symbol;
234 214

  
235 215
		if (this.lexicalTable == null) {
......
282 262
				}
283 263
			}
284 264
		}
285
//		if (this.colnames != null && this.colnames.size() != 0) {
286
//			if (this.colnames.size() != specIndex[0].length) {
287
//				throw new IllegalArgumentException(
288
//						SpecificitiesCoreMessages.SpecificitesResult_7 + this.colnames.size()
289
//						+ ", " + specIndex[0].length + ")."); //$NON-NLS-1$//$NON-NLS-2$ 
290
//			}
291
//			colindex = ArrayIndex.getIndex(
292
//					table.getColNames().asStringsArray(), partFocus
293
//					.toArray(new String[] {}));
294
//			for (int i : colindex) {
295
//				if (i == -1) {
296
//					throw new IllegalArgumentException(
297
//							SpecificitiesCoreMessages.SpecificitesResult_10);
298
//				}
299
//			}
300
//		}
265
		//		if (this.colnames != null && this.colnames.size() != 0) {
266
		//			if (this.colnames.size() != specIndex[0].length) {
267
		//				throw new IllegalArgumentException(
268
		//						SpecificitiesCoreMessages.SpecificitesResult_7 + this.colnames.size()
269
		//						+ ", " + specIndex[0].length + ")."); //$NON-NLS-1$//$NON-NLS-2$ 
270
		//			}
271
		//			colindex = ArrayIndex.getIndex(
272
		//					table.getColNames().asStringsArray(), partFocus
273
		//					.toArray(new String[] {}));
274
		//			for (int i : colindex) {
275
		//				if (i == -1) {
276
		//					throw new IllegalArgumentException(
277
		//							SpecificitiesCoreMessages.SpecificitesResult_10);
278
		//				}
279
		//			}
280
		//		}
301 281
	}
302 282

  
303
	
283

  
304 284
	/**
305 285
	 * Utility method to compute the specificity index of a word in a subcorpus.
306 286
	 * <br>
......
324 304
		if (rez != null) return rez.asDoubles()[0];
325 305
		return 0.0d;
326 306
	}
327
	
328
	
307

  
308

  
329 309
	/**
330 310
	 * Sets the unit property.
331 311
	 * @param unitProperty
......
333 313
	public void setUnitProperty(WordProperty unitProperty)	{
334 314
		this.getLexicalTable().setUnitProperty(unitProperty);
335 315
	}
336
	
337 316

  
338
	
339
	
317

  
318

  
319

  
340 320
	/**
341 321
	 * Gets the type focus.
342 322
	 *
......
383 363
	public int getFrequenciesSum() throws StatException {
384 364
		if (lexicalTable.getData() != null) {
385 365
			return lexicalTable.getData().getTotal();
386
		}
387
		else if (lexicon != null) {
388
			return lexicon.nbrOfToken();
389
		}
390
		else {
366
		} else {
391 367
			return 0;
392 368
		}
393 369
	}
......
400 376
	 * @throws CqiClientException 
401 377
	 */
402 378
	public int[] getColumnsFrequenciesSums() throws StatException, CqiClientException {
403
		
379

  
404 380
		if(
405 381
				//this.lexicalTable != null && 
406 382
				this.lexicalTable.hasBeenComputedOnce())	{
......
416 392
		else	{
417 393
			return new int[] {0, 0};
418 394
		}
419
//		if (lexicalTable != null && this.subCorpus == null
420
//				|| 
421
//				) {
422
//			try {
423
//				Vector partSizes = lexicalTable.getColMarginsVector();
424
//				if (colindex != null) {
425
//					partSizes = partSizes.get(colindex);
426
//				}
427
//				return partSizes.asIntArray();
428
//			}
429
//			catch (Exception e) {
430
//				return ((Partition)this.lexicalTable.getParent()).getPartSizes();
431
//			}
432
//		}
433
//		else {
434
//			try {
435
//				return new int[] { subLexicon.nbrOfToken(), lexicon.nbrOfToken() - subLexicon.nbrOfToken() };
436
//			}
437
//			// case of Subcorpus specificities (the lexicons has not yet been computed)
438
//			catch (Exception e) {
439
//				return new int[] {0, 0};
440
//			}
441
//		}
395
		//		if (lexicalTable != null && this.subCorpus == null
396
		//				|| 
397
		//				) {
398
		//			try {
399
		//				Vector partSizes = lexicalTable.getColMarginsVector();
400
		//				if (colindex != null) {
401
		//					partSizes = partSizes.get(colindex);
402
		//				}
403
		//				return partSizes.asIntArray();
404
		//			}
405
		//			catch (Exception e) {
406
		//				return ((Partition)this.lexicalTable.getParent()).getPartSizes();
407
		//			}
408
		//		}
409
		//		else {
410
		//			try {
411
		//				return new int[] { subLexicon.nbrOfToken(), lexicon.nbrOfToken() - subLexicon.nbrOfToken() };
412
		//			}
413
		//			// case of Subcorpus specificities (the lexicons has not yet been computed)
414
		//			catch (Exception e) {
415
		//				return new int[] {0, 0};
416
		//			}
417
		//		}
442 418
	}
443
	
419

  
444 420
	/**
445 421
	 * Gets the specificities index.
446 422
	 * 
......
457 433
	 * @throws StatException the stat exception
458 434
	 */
459 435
	public String[] getTypeNames() throws Exception {
460
		if (lexicalTable != null) {
461
			return (rownames != null && rownames.size() != 0) ? rownames.toArray(new String[] {}) : lexicalTable.getRowNames().asStringsArray();
462
		} else {
463
			return lexicon.getForms();
464
		}
436
		return lexicalTable.getRowNames().asStringsArray();
465 437
	}
466 438

  
467 439
	/**
......
471 443
	 * @throws StatException the stat exception
472 444
	 */
473 445
	public String[] getColumnsNames() throws StatException {
474
		//		System.out.println("get col names: "+table);
475
		//		System.out.println("colnames: "+colnames);
476
		if (colnames != null && colnames.size() > 0) {
477
			return colnames.toArray(new String[]{});
478
		}
479
		else if (this.subCorpus != null) {
480
			return new String[] { this.subCorpus.getName(), this.corpus.getName() + " \\ " + this.subCorpus.getName() }; //$NON-NLS-1$
481
		}
482
		else if (lexicalTable != null) {
483
			// return (colnames != null && colnames.size() != 0) ?
484
			// colnames.toArray(new String[]{}) :
485
			// table.getColNames().asStringsArray();
486
			/*
487
			 * List<Part> parts = table.getPartition().getOrderedParts(); String[]
488
			 * partShortNames = new String[parts.size()]; for (int i = 0; i <
489
			 * partShortNames.length; i++) { partShortNames[i] =
490
			 * parts.get(i).getShortName(); }
491
			 */
492
			try {
493
				return lexicalTable.getColNames().asStringsArray();
494
			}
495
			catch (Exception e) {
496
				return ((Partition)this.lexicalTable.getParent()).getPartNames().toArray(new String[0]);
497
			}
498
		}
499
		return new String[0];
446
		return lexicalTable.getColNames().asStringsArray();
500 447
	}
501 448

  
502 449
	/**
......
509 456
		//System.out.println("GET FREQUENCIES");
510 457
		if (frequencies == null) {
511 458
			//System.out.println("no frequencies");
512
			if (lexicalTable != null) {
459
//			if (lexicalTable != null) {
513 460
				//System.out.println("FROM TABLE");
514 461
				frequencies = RWorkspace.getRWorkspaceInstance().evalToInt2D(lexicalTable.getData().getSymbol());
515
				
516
			}
517
			else {// if table == null : subcorpus specif 
518
				//System.out.println("FROM LEXICON");
519
				frequencies = new int[lexicon.getFreq().length][2]; // build a frequency table from lexicons
520
				String[] corpusforms = lexicon.getForms(); // all the forms
521
				String[] subcorpusforms = subLexicon.getForms(); // all the forms
522
				int[] corpusfreq = lexicon.getFreq(); // all the freqs
523
				int[] subcorpusfreq = subLexicon.getFreq(); // all the freqs in the subcorpus
524 462

  
525
				//				System.out.println("len subforms: "+subcorpusforms.length);
526
				//				System.out.println("len subfreqs: "+subcorpusfreq.length);
527
				 //get all forms
528
				for (int i = 0 ; i < corpusforms.length ; i++) {
529
					int j = 0; // find the index of the form in the subcorpus arrays
530
					for (j = 0; j < subcorpusforms.length; j++) {
531
						if (subcorpusforms[j].equals(corpusforms[i]))
532
							break;// found the good form
533
					}
534
					if(j < subcorpusforms.length)
535
						frequencies[i][0] = subcorpusfreq[j];
536
					frequencies[i][1] = corpusfreq[i] - frequencies[i][0];
537
				}
538
			}
463
//			}
464
//			else {// if table == null : subcorpus specif 
465
//				//System.out.println("FROM LEXICON");
466
//				frequencies = new int[lexicon.getFreq().length][2]; // build a frequency table from lexicons
467
//				String[] corpusforms = lexicon.getForms(); // all the forms
468
//				String[] subcorpusforms = subLexicon.getForms(); // all the forms
469
//				int[] corpusfreq = lexicon.getFreq(); // all the freqs
470
//				int[] subcorpusfreq = subLexicon.getFreq(); // all the freqs in the subcorpus
471
//
472
//				//				System.out.println("len subforms: "+subcorpusforms.length);
473
//				//				System.out.println("len subfreqs: "+subcorpusfreq.length);
474
//				//get all forms
475
//				for (int i = 0 ; i < corpusforms.length ; i++) {
476
//					int j = 0; // find the index of the form in the subcorpus arrays
477
//					for (j = 0; j < subcorpusforms.length; j++) {
478
//						if (subcorpusforms[j].equals(corpusforms[i]))
479
//							break;// found the good form
480
//					}
481
//					if(j < subcorpusforms.length)
482
//						frequencies[i][0] = subcorpusfreq[j];
483
//					frequencies[i][1] = corpusfreq[i] - frequencies[i][0];
484
//				}
485
//			}
539 486
		}
540 487
		return frequencies;
541 488
	}
......
550 497
	}
551 498

  
552 499
	/**
553
	 * Gets the lexicon.
554
	 *
555
	 * @return the lexicon
556
	 */
557
	public CQPLexicon getLexicon() {
558
		return lexicon;
559
	}
560

  
561

  
562

  
563
	/**
564 500
	 * The frequency in the whole corpus.
565 501
	 *
566 502
	 * @return the form frequencies
567 503
	 * @throws StatException the stat exception
568 504
	 */
569 505
	public int[] getFormFrequencies() throws Exception {
570
		if (lexicalTable != null) {
571
			//System.out.println("get freq by table");
572
			Vector formFrequencies = lexicalTable.getRowMarginsVector();
573
			if (rowindex != null) {
574
				formFrequencies = formFrequencies.get(rowindex);
575
			}
576
			return formFrequencies.asIntArray();
577
		} else {
578
			//System.out.println("freqs by lexicon of "+lexicon.getCorpus());
579
			return lexicon.getFreq();
506
		//System.out.println("get freq by table");
507
		Vector formFrequencies = lexicalTable.getRowMarginsVector();
508
		if (rowindex != null) {
509
			formFrequencies = formFrequencies.get(rowindex);
580 510
		}
511
		return formFrequencies.asIntArray();
581 512
	}
582 513

  
583 514
	@Override
......
600 531
		try {
601 532
			getFrequencies();
602 533
			getFormFrequencies();
603
			getLexicon();
604 534
			String[] names = getColumnsNames();
605 535
			// if ("UTF-8".equals(encoding)) writer.write('\ufeff'); // UTF-8 BOM
606 536
			//write column header
......
634 564
		return true;
635 565
	}
636 566

  
637

  
638

  
639 567
	@Override
640 568
	public void clean() {
641 569
		try {
......
648 576
		}
649 577
	}
650 578

  
579
	//	/**
580
	//	 * Gets the symbol.
581
	//	 *
582
	//	 * @return the symbol
583
	//	 */
584
	//	public String getSymbol() {
585
	//		return symbol;
586
	//	}
651 587

  
588
	//	/**
589
	//	 * Gets the sorted part indexes.
590
	//	 *
591
	//	 * @return the sorted part indexes
592
	//	 */
593
	//	public int[] getSortedPartIndexes() {
594
	//
595
	//		try {
596
	//			int[] indexes = new int[this.getNbrPart()];
597
	//			String[] partsname = this.getPartShortNames().clone();
598
	//			for (int i = 0; i < this.getNbrPart(); i++) {
599
	//				indexes[i] = i;
600
	//			}
601
	//
602
	//			for (int i = 0; i < this.getNbrPart(); i++) {
603
	//				int imin = i;
604
	//				for (int j = i; j < this.getNbrPart(); j++) {
605
	//					if (partsname[imin].compareTo(partsname[j]) > 0) {
606
	//						imin = j;
607
	//					}
608
	//				}
609
	//				String tmp = partsname[i];
610
	//				partsname[i] = partsname[imin];
611
	//				partsname[imin] = tmp;
612
	//
613
	//				int tmp2 = indexes[i];
614
	//				indexes[i] = indexes[imin];
615
	//				indexes[imin] = tmp2;
616
	//			}
617
	//			return indexes;
618
	//		} catch (StatException e) {
619
	//			org.txm.utils.logger.Log.printStackTrace(e);
620
	//		}
621
	//		return new int[0];
622
	//	}
652 623

  
653

  
654
//	/**
655
//	 * Gets the symbol.
656
//	 *
657
//	 * @return the symbol
658
//	 */
659
//	public String getSymbol() {
660
//		return symbol;
661
//	}
662

  
663
//	/**
664
//	 * Gets the sorted part indexes.
665
//	 *
666
//	 * @return the sorted part indexes
667
//	 */
668
//	public int[] getSortedPartIndexes() {
669
//
670
//		try {
671
//			int[] indexes = new int[this.getNbrPart()];
672
//			String[] partsname = this.getPartShortNames().clone();
673
//			for (int i = 0; i < this.getNbrPart(); i++) {
674
//				indexes[i] = i;
675
//			}
676
//
677
//			for (int i = 0; i < this.getNbrPart(); i++) {
678
//				int imin = i;
679
//				for (int j = i; j < this.getNbrPart(); j++) {
680
//					if (partsname[imin].compareTo(partsname[j]) > 0) {
681
//						imin = j;
682
//					}
683
//				}
684
//				String tmp = partsname[i];
685
//				partsname[i] = partsname[imin];
686
//				partsname[imin] = tmp;
687
//
688
//				int tmp2 = indexes[i];
689
//				indexes[i] = indexes[imin];
690
//				indexes[imin] = tmp2;
691
//			}
692
//			return indexes;
693
//		} catch (StatException e) {
694
//			org.txm.utils.logger.Log.printStackTrace(e);
695
//		}
696
//		return new int[0];
697
//	}
698
	
699 624
	@Override
700 625
	public String getName() {
701 626
		// FIXME: to define
702
//		if (this.specificitiesResult.getLexicalTable()!= null && this.specificitiesResult.getLexicalTable().getPartition() != null)	{
703
//			setPartName(this.specificitiesResult.getLexicalTable().getPartition().getName()+": "+specificitiesResult.getName()); //$NON-NLS-1$
704
//		} else if (spinput.getSubcorpus() != null) {
705
//			setPartName(spinput.getSubcorpus().getName()+": "+specificitiesResult.getName()); //$NON-NLS-1$
706
//		} else {
707
//			setPartName(specificitiesResult.getName());
708
//		}
627
		//		if (this.specificitiesResult.getLexicalTable()!= null && this.specificitiesResult.getLexicalTable().getPartition() != null)	{
628
		//			setPartName(this.specificitiesResult.getLexicalTable().getPartition().getName()+": "+specificitiesResult.getName()); //$NON-NLS-1$
629
		//		} else if (spinput.getSubcorpus() != null) {
630
		//			setPartName(spinput.getSubcorpus().getName()+": "+specificitiesResult.getName()); //$NON-NLS-1$
631
		//		} else {
632
		//			setPartName(specificitiesResult.getName());
633
		//		}
709 634
		// FIXME: to define
710 635
		try {
711
//			if (this.lexicalTable.getProperty() != null) {
712
				return this.lexicalTable.getProperty().getName();
713
//			}
714
//			else {
715
//				return this.lexicalTable.getParent().toString();
716
//			}
636
			//			if (this.lexicalTable.getProperty() != null) {
637
			return this.lexicalTable.getProperty().getName();
638
			//			}
639
			//			else {
640
			//				return this.lexicalTable.getParent().toString();
641
			//			}
717 642
		}
718 643
		catch (Exception e) {
719 644
			return this.getEmptyName();
......
724 649

  
725 650
	@Override
726 651
	public String getSimpleName() {
727
		// FIXME: to define
728 652
		return this.getName();
729 653
	}
730 654

  
731 655
	@Override
732 656
	public String getDetails() {
733
		// FIXME: to define
734
		return this.getName();
657
		return NLS.bind(this.getName()+" (max score={0})", this.maxScore);
735 658
	}
736 659

  
737 660
	@Override
738 661
	public boolean canCompute() {
739
		
662

  
740 663
		if (this.lexicalTable == null) {
741 664
			Log.severe("Specificities.canCompute(): can not compute without a lexical table.");
742 665
			return false;
743 666
		}
744
				
745
//		if (this.lexicalTable.getNColumns() < 2) {
746
//			Log.severe(SpecificitiesCoreMessages.ComputeError_NEED_AT_LEAST_2_PARTS);
747
//			return false;
748
//		}
749
		
667

  
668
		//		if (this.lexicalTable.getNColumns() < 2) {
669
		//			Log.severe(SpecificitiesCoreMessages.ComputeError_NEED_AT_LEAST_2_PARTS);
670
		//			return false;
671
		//		}
672

  
750 673
		return true;
751 674
	}
752 675

  
......
767 690
		return true;
768 691
	}
769 692

  
770
	
693

  
771 694
	/**
772 695
	 * @return the maxScore
773 696
	 */
......
787 710
		return SpecificitiesCoreMessages.RESULT_TYPE;
788 711
	}
789 712

  
790
	
791 713

  
792
	
793 714

  
715

  
716

  
794 717
}
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/handlers/ComputeSpecifities.java (revision 1426)
60 60
			return null;
61 61
		}
62 62

  
63
		
64 63
		try {
65 64
			Object selection = this.getCorporaViewSelectedObject(event);
66 65
			Specificities specificities = null;
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/editors/SpecificitiesEditor.java (revision 1426)
299 299
				//final int[] sortedPartIndexes = specificitesResult.getSortedPartIndexes();
300 300
	
301 301
				// Create an array of lines to fill the tables
302
				Log.finest("len types: " + typeNames.length);
303
				Log.finest("len freq: " + typeFreq.length);
304
				Log.finest("len specfreqs: " + specFreqs.length);
305
				Log.finest("len specidx: " + specIndex.length);
302
//				Log.finest("len types: " + typeNames.length);
303
//				Log.finest("len freq: " + typeFreq.length);
304
//				Log.finest("len specfreqs: " + specFreqs.length);
305
//				Log.finest("len specidx: " + specIndex.length);
306 306
				
307 307
				Object[] tableLines = new Object[typeNames.length];
308 308
				for (int j = 0; j < tableLines.length; j++) {
......
314 314
				viewer.setInput(null);
315 315
			}
316 316

  
317
			
318 317
			// Updating the main frequency table header
319 318
			String text = TXMCoreMessages.common_frequency;
320 319
			if(this.getResult().hasBeenComputedOnce())	{
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Partition.java (revision 1426)
395 395
	 * @return the part names
396 396
	 */
397 397
	public List<String> getPartNames() {
398
		if (hasBeenComputedOnce()) {
398 399
		List<Part> parts = getParts();
399 400
		List<String> partNames = new ArrayList<String>(parts.size());
400 401
		for (Subcorpus part : getParts()) {
401 402
			partNames.add(part.getName());
402 403
		}
403 404
		return partNames;
405
		} else {
406
			return this.pPartNames;
407
		}
404 408
	}
405 409

  
406 410
	/**
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/RWorkspace.java (revision 1426)
553 553
	 * of column in every row.
554 554
	 * @throws RWorkspaceException the r workspace exception
555 555
	 */
556
	public void addMatrixToWorkspace(String variableName, double[][] matrix)
557
			throws RWorkspaceException {
556
	public void addMatrixToWorkspace(String variableName, double[][] matrix) throws RWorkspaceException {
558 557
		//System.out.println("matrix len: "+matrix.length+" test="+(matrix.length == 0));
559 558
		if (matrix.length == 0) {
560 559
			new RWorkspaceException(RCoreMessages.error_matrixIsEmpty);
561 560
		}
562 561
		int ncol = matrix[0].length;
563 562
		int nrow = matrix.length;
563
		
564
		addMatrixToWorkspace(variableName, matrix, ncol, nrow);
565
	}
566
	
567
	/**
568
	 * Add a matrix into the workspace and link it to a name. The inner arrays
569
	 * of the <code>matrix</code> parameters are the <strong>row</strong> of the
570
	 * resulting R matrix.
571
	 *
572
	 * @param variableName the name to be used in the R workspace.
573
	 * @param matrix the data to be bound to the name. In the form
574
	 * <code>matrix[row][column]</code>, with exactly the same number
575
	 * of column in every row.
576
	 * @throws RWorkspaceException the r workspace exception
577
	 */
578
	public void addMatrixToWorkspace(String variableName, double[][] matrix, int ncol, int nrow)
579
			throws RWorkspaceException {
564 580

  
565 581
		double[] vector = VectorizeArray.vectorizeByInner(matrix);
566 582

  
......
594 610
			throws RWorkspaceException {
595 611

  
596 612
		double[][] data = RColt.doubleMatrix2D2DoubleDoubleArray(matrix);
597
		addMatrixToWorkspace(variableName, data);
613
		addMatrixToWorkspace(variableName, data, matrix.columns(), matrix.rows());
598 614

  
599 615
		// // IntArrayList x = new IntArrayList();
600 616
		// // IntArrayList y = new IntArrayList();
......
715 731
	 */
716 732
	public void addMatrixToWorkspace(String variableName, int[][] matrix) throws RWorkspaceException {
717 733
		int ncol = 0;
718
		if (matrix.length == 0) {
719
			ncol = 0;
720
		}
721
		else {
734
		int nrow = 0;
735
		if (matrix.length > 0) {
736
			nrow = matrix.length;
722 737
			ncol = matrix[0].length;
723 738
		}
724
		int nrow = matrix.length;
739
		
740
		addMatrixToWorkspace(variableName, matrix, ncol, nrow);
741
	}
742
	/**
743
	 * Add a matrix into the workspace and link it to a name. The inner arrays
744
	 * of the <code>matrix</code> parameters are the <strong>row</strong> of the
745
	 * resulting R matrix.
746
	 *
747
	 * @param variableName the name to be used in the R workspace.
748
	 * @param matrix the data to be bound to the name. In the form
749
	 * <code>matrix[row][column]</code>, with exactly the same number
750
	 * of column in every row.
751
	 * @throws RWorkspaceException the r workspace exception
752
	 */
753
	public void addMatrixToWorkspace(String variableName, int[][] matrix, int ncol, int nrow) throws RWorkspaceException {
754
		
725 755
		int[] vector = VectorizeArray.vectorizeByInner(matrix);
726 756
		if (!filecommunication) {
727 757
			try {
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/data/MatrixImpl.java (revision 1426)
109 109
		//this.rows = null;
110 110
		//this.cols = null;
111 111
	}
112
	
113
	/**
114
	 * Instantiates a new matrix impl.
115
	 *
116
	 * @param matrix the matrix
117
	 * @throws RWorkspaceException the r workspace exception
118
	 */
119
	public MatrixImpl(double[][] matrix, int ncol, int nrow) throws RWorkspaceException {
120
		super();
121
		rw.addMatrixToWorkspace(symbol, matrix, ncol, nrow);
122
		//		this.nrow = matrix.length;
123
		//		this.ncol = matrix[0].length;
124
		//this.rows = null;
125
		//this.cols = null;
126
	}
112 127

  
113 128
	/**
114 129
	 * Instantiates a new matrix impl.
......
165 180
	 * @param matrix the matrix
166 181
	 * @throws RWorkspaceException the r workspace exception
167 182
	 */
183
	public MatrixImpl(int[][] matrix, int ncol, int nrow) throws RWorkspaceException {
184
		super();
185
		rw.addMatrixToWorkspace(symbol, matrix, ncol, nrow);
186
		//		this.nrow = matrix.length;
187
		//		if (matrix.length > 0)
188
		//			this.ncol = matrix[0].length;
189
		//		else
190
		//			this.ncol = 0;
191
		//this.rows = null;
192
		//this.cols = null;
193
	}
194
	
195
	/**
196
	 * Instantiates a new matrix impl.
197
	 *
198
	 * @param matrix the matrix
199
	 * @throws RWorkspaceException the r workspace exception
200
	 */
168 201
	public MatrixImpl(int[][] matrix) throws RWorkspaceException {
169 202
		super();
170 203
		rw.addMatrixToWorkspace(symbol, matrix);
......
201 234
	 * @throws RWorkspaceException the r workspace exception
202 235
	 */
203 236
	public MatrixImpl(int[][] matrix, String[] lineNames, String[] partNames) throws RWorkspaceException {
204
		this(matrix);
237
		this(matrix, partNames!=null?partNames.length:0, lineNames!=null?lineNames.length:0);
205 238

  
206 239
		if (lineNames == null) {
207 240
			throw new IllegalArgumentException(StatsEngineCoreMessages.rowNamesOfAContingencyTableCannotBeNull);
208 241
		}
242
		
243
		if (partNames == null) {
244
			throw new IllegalArgumentException(StatsEngineCoreMessages.columnNamesOfAContingencyTableCannotBeNull);
245
		}
246
		
209 247
		//		if (lineNames.length != nrow) {
210 248
		//			throw new IllegalArgumentException(Messages.MatrixImpl_5);
211 249
		//		}
212 250
		//this.rows = ;
213 251
		rw.assignRowNamesToMatrix(symbol, new VectorImpl(lineNames).getSymbol());
214 252

  
215
		if (partNames == null) {
216
			throw new IllegalArgumentException(StatsEngineCoreMessages.columnNamesOfAContingencyTableCannotBeNull);
217
		}
253
		
218 254
		//		if (partNames.length != ncol) {
219 255
		//			throw new IllegalArgumentException(Messages.MatrixImpl_7
220 256
		//					+ partNames.length + ", " + ncol + ")."); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/data/DoubleMatrix.java (revision 1426)
59 59
	public DoubleMatrix(double[][] mat) throws RWorkspaceException {
60 60
		super(mat);
61 61
	}
62
	
63
	/**
64
	 * Instantiates a new double matrix.
65
	 *
66
	 * @param mat the mat
67
	 * @throws RWorkspaceException the r workspace exception
68
	 */
69
	public DoubleMatrix(double[][] mat, int ncol, int nrow) throws RWorkspaceException {
70
		super(mat, ncol, nrow);
71
	}
62 72

  
63 73
	/**
64 74
	 * Instantiates a new double matrix.
tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/functions/LexicalTable.java (revision 1426)
8 8
import java.util.List;
9 9
import java.util.Map;
10 10

  
11
import org.eclipse.osgi.util.NLS;
11 12
import org.txm.core.preferences.TBXPreferences;
12 13
import org.txm.core.results.Parameter;
13 14
import org.txm.core.results.TXMParameters;
......
32 33
/**
33 34
 * Holds the word frequencies table of a {@link Partition} seen through a word property.
34 35
 * 
36
 * until the LT is computed the internal R table is set to an empty matrix with rownames and colnames set
37
 * 
35 38
 * @author mdecorde
36 39
 * @author sjacquot
37 40
 * 
......
68 71
	@Parameter(key=LexicalTablePreferences.USE_ALL_OCCURRENCES)
69 72
	protected boolean useAllOccurrences;
70 73

  
71
//	/**
72
//	 * Build a LexicalTable result with an already computed frequency R table
73
//	 * 
74
//	 * @param corpus
75
//	 * @param analysisProperty
76
//	 * @param itable
77
//	 */
78
//	public LexicalTable(CQPCorpus corpus, WordProperty analysisProperty, ILexicalTable itable) {
79
//		super(corpus);
80
//		this.property = analysisProperty;
81
//		this.statsData = itable;
82
//	}
83

  
84
//	/**
85
//	 * Build a LexicalTable with the {@link Subcorpus} words and {@link Subcorpus} parent remaining words.
86
//	 * 
87
//	 * @param corpus
88
//	 * @param analysisProperty the property to count
89
//	 * @throws Exception
90
//	 */
91
//	public LexicalTable(Subcorpus corpus, WordProperty analysisProperty) {
92
//		this(corpus, analysisProperty, null);
93
//	}
94

  
95 74
	/**
96 75
	 * Build a LexicalTable with the Subcorpus words and Subcorpus parent remaining words.
97 76
	 * 
......
104 83
//		if (property == null) {
105 84
//			this.setUnitProperty(corpus.getDefaultProperty());
106 85
//		}
86
		
87
		try { // create empty LT to store infos
88
			String[] rowNames = {};
89
			String[] colNames = {NLS.bind("{0}-{1}", corpus.getCorpusParent().getName(), corpus.getName()), corpus.getName()};
90
			int[][] matrix = new int[0][2];
91
			this.statsData = new LexicalTableImpl(matrix, rowNames, colNames);
92
		} catch (Exception e) {
93
			e.printStackTrace();
94
		}
107 95
	}
108 96

  
109
//	/**
110
//	 * 
111
//	 * @param partition
112
//	 * @param analysisProperty
113
//	 * @param fMin
114
//	 * @param vMax
115
//	 * @param iTable
116
//	 */
117
//	public LexicalTable(Partition partition, WordProperty analysisProperty, int fMin, int vMax, ILexicalTable iTable) {
118
//		this(partition, analysisProperty, fMin, vMax, false, iTable);
119
//	}
120

  
121 97
	/**
122 98
	 * 
123 99
	 * @param index
......
127 103
		
128 104
		this.property = index.getProperties().get(0);
129 105
		this.useAllOccurrences = true;
106
		
107
		try { // create empty LT to store infos
108
			String[] rowNames = {};
109
			List<String> names = index.getPartition().getPartNames();
110
			String[] colNames = names.toArray(new String[names.size()]);
111
			int[][] matrix = new int[0][names.size()];
112
			this.statsData = new LexicalTableImpl(matrix, rowNames, colNames);
113
		} catch (Exception e) {
114
			e.printStackTrace();
115
		}
130 116
	}
131 117

  
132 118
	/**
......
135 121
	 */
136 122
	public LexicalTable(Partition partition)	{
137 123
		super(partition);
138
//		if (property == null) {
139
//			try {
140
//				this.setUnitProperty(partition.getCorpus().getDefaultProperty());
141
//			} catch (CqiClientException e) {
142
//				e.printStackTrace();
143
//			}
144
//		}
124

  
125
		try { // create empty LT to store infos
126
			String[] rowNames = {};
127
			List<String> names = partition.getPartNames();
128
			String[] colNames = names.toArray(new String[names.size()]);
129
			int[][] matrix = new int[0][names.size()];
130
			this.statsData = new LexicalTableImpl(matrix, rowNames, colNames);
131
		} catch (Exception e) {
132
			e.printStackTrace();
133
		}
145 134
	}
146 135

  
147
//	/**
148
//	 * 
149
//	 * @param partition
150
//	 * @param analysisProperty
151
//	 * @param fMin
152
//	 * @param vMax
153
//	 */
154
//	public LexicalTable(Partition partition, WordProperty analysisProperty, int fMin, int vMax) {
155
//		this(partition, analysisProperty, fMin, vMax, null);
156
//	}
157

  
158
//	/**
159
//	 * 
160
//	 * @param parent
161
//	 * @param analysisProperty
162
//	 * @param fMin
163
//	 * @param vMax
164
//	 * @param useAllOccurrences
165
//	 * @param iTable
166
//	 */
167
//	private LexicalTable(TXMResult parent, WordProperty analysisProperty, int fMin, int vMax, boolean useAllOccurrences, ILexicalTable iTable)	{
168
//		super(parent);
169
//		this.setParameters(analysisProperty, fMin, vMax, useAllOccurrences);
170
//		this.statsData = iTable;
171
//	}
172

  
173 136
	public LexicalTable(String parametersNodePath)	{
174 137
		super(parametersNodePath);
175 138
	}
......
194 157
	}
195 158

  
196 159

  
197

  
198 160
	/**
199 161
	 * 
200 162
	 * @param partition

Formats disponibles : Unified diff