Révision 2768

tmp/org.txm.index.core/src/org/txm/index/core/functions/PartitionIndex.java (revision 2768)
32 32
import java.io.FileOutputStream;
33 33
import java.io.IOException;
34 34
import java.io.OutputStreamWriter;
35
import java.util.ArrayList;
35 36
import java.util.HashMap;
36 37
import java.util.List;
37 38

  
......
417 418
	public String getResultType() {
418 419
		return PartitionIndex.class.getSimpleName();
419 420
	}
421
	
422
	/** The novoc. */
423
	protected static int novoc = 1;
424

  
425
	/** The prefix r. */
426
	protected static String prefixR = "PartitionIndex"; //$NON-NLS-1$
427

  
428
	/**
429
	 * As r matrix.
430
	 *
431
	 * TODO MD: restore the asRMatrix method used by the execR&co macros as demonstration
432
	 * TODO MD: finalize a export to R mechanism (maybe linked to the export engines to be implemented 
433
	 *
434
	 * @return the string
435
	 * @throws RWorkspaceException the r workspace exception
436
	 */
437
	public String asRMatrix() throws RWorkspaceException {
438
		String symbol = prefixR+novoc;
439

  
440
		ArrayList<String> colnames = new ArrayList<String>();
441
		List<String> partnames = getPartNames();
442
		partnames.add(this.getCorpus().getName());
443
		
444
		colnames.add("F"); //$NON-NLS-1$
445
		if (partnames.size() > 1)
446
			for (int j = 0; j < partnames.size(); j++)
447
				colnames.add(partnames.get(j)); 
448

  
449
		//System.out.println("cols: "+colnames);
450

  
451
		String[] keywords = new String[this.lines.size()];
452

  
453
		int[] freq = new int[this.lines.size()];
454
		ArrayList<int[]> partfreqs = new ArrayList<int[]>(partnames.size());
455
		if (partnames.size() > 1)
456
			for (int j = 0; j < partnames.size(); j++)
457
				partfreqs.add(new int[this.lines.size()]);
458

  
459
		for (int i = 0 ; i < lines.size() ; i++) 
460
		{
461
			Line ligne = lines.get(i);
462
			freq[i] = ligne.getFrequency(); 
463
			keywords[i] = ligne.toString();
464
			if (partnames.size() > 1)
465
				for (int j = 0; j < partnames.size(); j++)
466
				{
467
					partfreqs.get(j)[i] = ligne.getFrequency(j);
468
				}
469

  
470
		}
471

  
472
		RWorkspace rw = RWorkspace.getRWorkspaceInstance();
473
		if (partnames.size() > 1)
474
			for (int j = 0; j < partnames.size(); j++)
475
				rw.addVectorToWorkspace("vocpartfreqs"+j, partfreqs.get(j)); //$NON-NLS-1$
476
		rw.addVectorToWorkspace("vocfreq", freq); //$NON-NLS-1$
477
		rw.addVectorToWorkspace("vockeywords", keywords); //$NON-NLS-1$
478
		rw.addVectorToWorkspace("voccolnames", colnames.toArray(new String[colnames.size()])); //$NON-NLS-1$
479

  
480
		int ncol = 1;
481
		if (partnames.size() > 1)
482
			ncol += partnames.size();
483

  
484
		int nrow = lines.size();
485
		String partscmd = ""; //$NON-NLS-1$
486
		if (partnames.size() > 1)
487
			for (int j = 0; j < partnames.size(); j++)
488
				partscmd +=", vocpartfreqs"+j; //$NON-NLS-1$
489

  
490
		rw.eval(symbol+ "<- matrix(data = c(vocfreq"+partscmd+"), nrow = "+nrow+", ncol = "+ncol+")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
491
		rw.eval("colnames("+symbol+" ) <- voccolnames"); //$NON-NLS-1$ //$NON-NLS-2$
492
		rw.eval("rownames("+symbol+" ) <- vockeywords"); //$NON-NLS-1$ //$NON-NLS-2$
493
		rw.eval(symbol+ "<- list(data="+symbol+")"); //$NON-NLS-1$ //$NON-NLS-2$
494

  
495
		novoc++;
496
		return symbol;
497
	}
420 498
}
tmp/org.txm.index.core/src/org/txm/index/core/functions/Index.java (revision 2768)
1150 1150
	public String getResultType() {
1151 1151
		return IndexCoreMessages.RESULT_TYPE;
1152 1152
	}
1153
	
1154
	/** The novoc. */
1155
	protected static int novoc = 1;
1156

  
1157
	/** The prefix r. */
1158
	protected static String prefixR = "Index"; //$NON-NLS-1$
1159

  
1160
	/**
1161
	 * As r matrix.
1162
	 *
1163
	 * TODO MD: restore the asRMatrix method used by the execR&co macros as demonstration
1164
	 * TODO MD: finalize a export to R mechanism (maybe linked to the export engines to be implemented 
1165
	 *
1166
	 * @return the string
1167
	 * @throws RWorkspaceException the r workspace exception
1168
	 */
1169
	public String asRMatrix() throws RWorkspaceException {
1170
		String symbol = prefixR+novoc;
1171

  
1172
		ArrayList<String> colnames = new ArrayList<String>();
1173
		ArrayList<String> partnames = new ArrayList<String>();
1174
		partnames.add(this.getCorpus().getName());
1175
		
1176
		colnames.add("F"); //$NON-NLS-1$
1177
		if (partnames.size() > 1)
1178
			for (int j = 0; j < partnames.size(); j++)
1179
				colnames.add(partnames.get(j)); 
1180

  
1181
		//System.out.println("cols: "+colnames);
1182

  
1183
		String[] keywords = new String[this.lines.size()];
1184

  
1185
		int[] freq = new int[this.lines.size()];
1186
		ArrayList<int[]> partfreqs = new ArrayList<int[]>(partnames.size());
1187
		if (partnames.size() > 1)
1188
			for (int j = 0; j < partnames.size(); j++)
1189
				partfreqs.add(new int[this.lines.size()]);
1190

  
1191
		for (int i = 0 ; i < lines.size() ; i++) 
1192
		{
1193
			Line ligne = lines.get(i);
1194
			freq[i] = ligne.getFrequency(); 
1195
			keywords[i] = ligne.toString();
1196
			if (partnames.size() > 1)
1197
				for (int j = 0; j < partnames.size(); j++)
1198
				{
1199
					partfreqs.get(j)[i] = ligne.getFrequency(j);
1200
				}
1201

  
1202
		}
1203

  
1204
		RWorkspace rw = RWorkspace.getRWorkspaceInstance();
1205
		if (partnames.size() > 1)
1206
			for (int j = 0; j < partnames.size(); j++)
1207
				rw.addVectorToWorkspace("vocpartfreqs"+j, partfreqs.get(j)); //$NON-NLS-1$
1208
		rw.addVectorToWorkspace("vocfreq", freq); //$NON-NLS-1$
1209
		rw.addVectorToWorkspace("vockeywords", keywords); //$NON-NLS-1$
1210
		rw.addVectorToWorkspace("voccolnames", colnames.toArray(new String[colnames.size()])); //$NON-NLS-1$
1211

  
1212
		int ncol = 1;
1213
		if (partnames.size() > 1)
1214
			ncol += partnames.size();
1215

  
1216
		int nrow = lines.size();
1217
		String partscmd = ""; //$NON-NLS-1$
1218
		if (partnames.size() > 1)
1219
			for (int j = 0; j < partnames.size(); j++)
1220
				partscmd +=", vocpartfreqs"+j; //$NON-NLS-1$
1221

  
1222
		rw.eval(symbol+ "<- matrix(data = c(vocfreq"+partscmd+"), nrow = "+nrow+", ncol = "+ncol+")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
1223
		rw.eval("colnames("+symbol+" ) <- voccolnames"); //$NON-NLS-1$ //$NON-NLS-2$
1224
		rw.eval("rownames("+symbol+" ) <- vockeywords"); //$NON-NLS-1$ //$NON-NLS-2$
1225
		rw.eval(symbol+ "<- list(data="+symbol+")"); //$NON-NLS-1$ //$NON-NLS-2$
1226

  
1227
		novoc++;
1228
		return symbol;
1229
	}
1153 1230
}

Formats disponibles : Unified diff