Revision 534

tmp/org.txm.searchengine.cqp.rcp/src/org/txm/searchengine/cqp/rcp/messages_fr.properties (revision 534)
1045 1045
SpecificitiesTableEditor_11 = T
1046 1046
SpecificitiesTableEditor_16 = Graphique : 
1047 1047
SpecificitiesTableEditor_17 = Chargement de la table des spécificités
1048
SpecificitiesTableEditor_5  = Erreur inattendue dans le moteur statistique R
1048
SpecificitiesTableEditor_5  = Erreur inattendue dans le moteur statistique R : {0}
1049 1049
SpecificitiesTableEditor_8  = Calculer le diagramme en bâtons des lignes sélectionnées
1050 1050

  
1051 1051
Structure_field_not_empty = Le champ structure ne doit pas être vide.
tmp/org.txm.searchengine.cqp.rcp/.settings/org.eclipse.core.resources.prefs (revision 534)
1
eclipse.preferences.version=1
2
encoding//src/org/txm/searchengine/cqp/rcp/messages_fr.properties=UTF-8
0 3

  
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/handlers/ComputeLexicalTable.java (revision 534)
467 467
				try {
468 468
					monitor.beginTask("Computing Lexical table with Index: "+firstIndex+" property: "+property, 100);
469 469
					this.acquireSemaphore();
470
					table = new LexicalTable(vocabularies, QuantitativeDataStructureImpl.createSymbole(LexicalTableImpl.class), useAllOccurrences);
470
					table = new LexicalTable(firstIndex);
471
					table.setParameters(null, null, null, useAllOccurrences);
472
					table.compute(true, monitor);
471 473
					monitor.worked(45);
472 474
					this.releaseSemaphore();
473 475
					if (monitor.isCanceled() || table == null)
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/handlers/ComputeSpecifities.java (revision 534)
42 42
import org.eclipse.ui.handlers.HandlerUtil;
43 43
import org.txm.core.preferences.TXMPreferences;
44 44
import org.txm.lexicaltable.core.functions.LexicalTable;
45
import org.txm.lexicaltable.core.functions.LexicalTableFactory;
45 46
import org.txm.lexicaltable.core.preferences.LexicalTablePreferences;
46 47
import org.txm.rcp.editors.TXMEditorPart;
47 48
import org.txm.rcp.editors.TXMResultEditorInput;
......
57 58
import org.txm.searchengine.cqp.corpus.Partition;
58 59
import org.txm.searchengine.cqp.corpus.Property;
59 60
import org.txm.searchengine.cqp.corpus.Subcorpus;
60
import org.txm.specificities.core.functions.SpecificitesResult;
61
import org.txm.specificities.core.functions.Specificities;
61 62
import org.txm.specificities.core.preferences.SpecificitiesPreferences;
62 63
import org.txm.specificities.rcp.dialogs.ComputeSpecificitiesDialog;
63 64
import org.txm.specificities.rcp.dialogs.ComputeSpecificitiesForSubcorpusDialog;
......
76 77
 * @author mdecorde
77 78
 */
78 79
public class ComputeSpecifities extends BaseAbstractHandler {
79
	
80
	
80

  
81

  
81 82
	// adds a double click listener to the Corpus View
82 83
	static	{
83
		CorporaView.addDoubleClickListener(SpecificitesResult.class, ComputeSpecifities.class);
84
		CorporaView.addDoubleClickListener(Specificities.class, ComputeSpecifities.class);
84 85
	}
85
	
86
	/** The window. */
87
	private IWorkbenchWindow window;
88 86

  
89
	/** The selection. */
90
	private IStructuredSelection selection;
91

  
92
	/** The specificities result. */
93
	private SpecificitesResult specificitiesResult;
94

  
95 87
	/*
96 88
	 * (non-Javadoc)
97 89
	 * 
......
102 94
	@Override
103 95
	public Object execute(ExecutionEvent event) throws ExecutionException {
104 96

  
105
		if(!this.checkStatsEngine()) {
97
		if (!this.checkStatsEngine()) {
106 98
			return null;
107 99
		}
108 100

  
109

  
110
		window = HandlerUtil.getActiveWorkbenchWindow(event);
111
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
112
		if(selection == null) {
101
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
102
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
103
		if (selection == null) {
113 104
			Log.info(RCPMessages.ComputeSpecifities_1);
114 105
			return null;
115 106
		}
116
		Object s = selection.getFirstElement();
117
		final int maxScore = TXMPreferences.getInt(SpecificitiesPreferences.MAX_SCORE, SpecificitiesPreferences.PREFERENCES_NODE);
118
		if(s instanceof Partition) {
119
			final Partition partition = (Partition) selection.getFirstElement();
120
			final int Fmin = TXMPreferences.getInt(LexicalTablePreferences.F_MIN, LexicalTablePreferences.PREFERENCES_NODE);
107
		final Object s = selection.getFirstElement();
108
		final Integer maxScore = TXMPreferences.getInt(SpecificitiesPreferences.MAX_SCORE, SpecificitiesPreferences.PREFERENCES_NODE);
109
		final Integer Fmin = TXMPreferences.getInt(LexicalTablePreferences.F_MIN, LexicalTablePreferences.PREFERENCES_NODE);
110
		Property propertyChoice = null;
121 111

  
122
			final ComputeSpecificitiesDialog d = new ComputeSpecificitiesDialog(window.getShell(), partition, false);
112
		// depending on the selection, ask different parameters
113
		if (s instanceof Partition) {
114

  
115
			Partition partition = (Partition) s;
116
			ComputeSpecificitiesDialog d = new ComputeSpecificitiesDialog(window.getShell(), partition, false);
123 117
			int code = d.open();
124
			if(code == Window.OK) {
125
				final Property property = d.getAnalysisProperty();
118
			if (code == Window.OK) {
119
				propertyChoice = d.getAnalysisProperty();
120
			} else {
121
				return null;
122
			}
123
		} else if (s instanceof Subcorpus) {
126 124

  
127
				// final CorporaView corporaView = (CorporaView)
128
				// PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(CorporaView.ID);
129
				JobHandler jobhandler = new JobHandler(RCPMessages.ComputeSpecificities_0) {
130
					@Override
131
					protected IStatus run(IProgressMonitor monitor) {
132
						this.runInit(monitor);
133
						try {
134
							JobsTimer.start();
135
							String str = NLS.bind(RCPMessages.ComputeSpecificities_2, new Object[] { partition.getName(), property });
136
							monitor.beginTask(str, 100);
137
							try {
138
								System.out.println(str);
139
								this.acquireSemaphore();
140
								specificitiesResult = new SpecificitesResult(partition, property, Fmin, maxScore);
141
								this.releaseSemaphore();
125
			Subcorpus subcorpus = (Subcorpus) s;
126
			ComputeSpecificitiesForSubcorpusDialog d = new ComputeSpecificitiesForSubcorpusDialog(window.getShell(), subcorpus);
127
			int code = d.open();
128
			if (code == Window.OK) {
129
				propertyChoice = d.getProperty();
130
			} else {
131
				return null;
132
			}
133
		}
142 134

  
143
								System.out.println(NLS.bind(RCPMessages.DONE, specificitiesResult.getName()));
144
							} catch(Exception e) {
145
								System.out.println(RCPMessages.ComputeSpecifities_4 + e);
146
								org.txm.rcp.utils.Logger.printStackTrace(e);
147
								return Status.CANCEL_STATUS;
148
							}
149
							monitor.worked(45);
135
		final Property property = propertyChoice;
150 136

  
151
							specificitiesResult.getLexicalTable().addResult(specificitiesResult);
152
							// partition.storeResult(specificitiesResult);
153
							monitor.worked(5);
137
		JobHandler jobhandler = new JobHandler(RCPMessages.ComputeSpecificities_0) {
138
			@Override
139
			protected IStatus run(IProgressMonitor monitor) {
140
				this.runInit(monitor);
141
				try {
142
					Specificities specifRes = null;
154 143

  
155
							monitor.subTask(RCPMessages.ComputeSpecifities_10);
156
							syncExec(new Runnable() {
157
								@Override
158
								public void run() {
159
									IWorkbenchPage page = window.getActivePage();
160
									SpecificitiesResultEditorInput editorInput = new SpecificitiesResultEditorInput(specificitiesResult, partition);
161
									try {
162
										StatusLine.setMessage(RCPMessages.ComputeSpecifities_10);
163
										page.openEditor(editorInput, SpecificitiesTableEditor.ID); //$NON-NLS-1$
164
									}
165
									catch(PartInitException e) {
166
										System.err.println(NLS.bind(RCPMessages.Error_computing_specificities, e));
167
										org.txm.rcp.utils.Logger.printStackTrace(e);
168
									}
169
								}
170
							});
144
					if (s instanceof Partition) {
145
						Partition partition = (Partition) s;
171 146

  
172
							monitor.worked(50);
173
							if(monitor.isCanceled())
174
								return Status.CANCEL_STATUS;
147
						JobsTimer.start();
148
						String str = NLS.bind(RCPMessages.ComputeSpecificities_2, new Object[] { partition.getName(), property });
149
						monitor.beginTask(str, 100);
150
						System.out.println(str);
175 151

  
176
							monitor.subTask(RCPMessages.ComputeSpecifities_2);
177
							syncExec(new Runnable() {
178
								@Override
179
								public void run() {
180
									CorporaView.refresh();
181
									CorporaView.expand(specificitiesResult.getParent());
182
									QueriesView.refresh();
183
									RVariablesView.refresh();
184
								}
185
							});
152
						this.acquireSemaphore();
153
						LexicalTable table = LexicalTableFactory.getLexicalTable(partition, property, Fmin);
154
						this.releaseSemaphore();
186 155

  
187
							monitor.worked(100);
188
						} catch(ThreadDeath td) {
189
							return Status.CANCEL_STATUS;
190
						} catch(Exception e) {
191
							org.txm.rcp.utils.Logger.printStackTrace(e);
192
						} finally {
193
							monitor.done();
194
							JobsTimer.stopAndPrint();
195
						}
196
						return Status.OK_STATUS;
197
					}
198
				};
199
				jobhandler.startJob();
200
			}
201
		}
202
		else if(s instanceof Subcorpus) {
203
			final Subcorpus subcorpus = (Subcorpus) s;
204
			ComputeSpecificitiesForSubcorpusDialog d = new ComputeSpecificitiesForSubcorpusDialog(window.getShell(), subcorpus);
205
			int code = d.open();
206
			if(code == Window.OK) {
207
				final Property property = d.getProperty();
208
				try {
209
					JobHandler jobhandler = new JobHandler(RCPMessages.ComputeSpecificities_0) {
210
						@Override
211
						protected IStatus run(IProgressMonitor monitor) {
212
							this.runInit(monitor);
156
						if (monitor.isCanceled()) return Status.CANCEL_STATUS;
213 157

  
214
							try {
215
								Corpus parentCorpus = subcorpus.getMotherSubcorpus();
216
								if(parentCorpus == null)
217
									parentCorpus = subcorpus.getMainCorpus();
158
						this.acquireSemaphore();
159
						specifRes = new Specificities(table, maxScore);
160
						this.releaseSemaphore();
218 161

  
219
								System.out.println(NLS.bind(RCPMessages.ComputeSpecifities_3, new Object[] { subcorpus.getName(), parentCorpus.getName(), property }));
220
								specificitiesResult = new SpecificitesResult(parentCorpus, subcorpus, property, maxScore);
221
								System.out.println(NLS.bind(RCPMessages.DONE, specificitiesResult.getName()));
222
								subcorpus.addResult(specificitiesResult);
223
							}
224
							catch(Exception e) {
225
								System.err.println(NLS.bind(RCPMessages.Error_computing_specificities, e));
226
								System.err.println(e);
227
								org.txm.rcp.utils.Logger.printStackTrace(e);
228
							}
162
						System.out.println(NLS.bind(RCPMessages.DONE, specifRes.getName()));
163
					}
164
					else if (s instanceof Subcorpus) {
165
						Subcorpus subcorpus = (Subcorpus) s;
166
						
167
						this.acquireSemaphore();
168
						LexicalTable table = LexicalTableFactory.getLexicalTable(subcorpus, property);
169
						this.releaseSemaphore();
229 170

  
230
							monitor.subTask(RCPMessages.ComputeSpecifities_2);
231
							syncExec(new Runnable() {
232
								@Override
233
								public void run() {
234
									IWorkbenchPage page = window.getActivePage();
235
									SpecificitiesResultEditorInput editorInput = new SpecificitiesResultEditorInput(specificitiesResult, subcorpus);
171
						if (monitor.isCanceled()) return Status.CANCEL_STATUS;
236 172

  
237
									try {
238
										page.openEditor(editorInput, SpecificitiesTableEditor.ID);
239
									}
240
									catch(PartInitException e) {
241
										e.printStackTrace();
242
									}
173
						System.out.println(NLS.bind(RCPMessages.ComputeSpecifities_3, new Object[] { subcorpus.getName(), subcorpus.getMotherCorpus().getName(), property }));
174
						specifRes = new Specificities(table, maxScore);
175
					}
176
					else if (s instanceof LexicalTable) {
177
						LexicalTable table = (LexicalTable) s;
243 178

  
244
									CorporaView.refresh();
245
									CorporaView.expand(specificitiesResult.getParent());
246
									QueriesView.refresh();
247
									RVariablesView.refresh();
248
								}
249
							});
250

  
251
							return Status.OK_STATUS;
252
						}
253
					};
254
					jobhandler.startJob();
255
				}
256
				catch(Exception e) {
257
					System.err.println(NLS.bind(RCPMessages.Error_computing_specificities, e));
258
				}
259
			}
260
		}
261
		else if(s instanceof LexicalTable) {
262
			final LexicalTable table = (LexicalTable) s;
263
			JobHandler jobhandler = new JobHandler(RCPMessages.ComputeSpecificities_0) {
264
				@Override
265
				protected IStatus run(IProgressMonitor monitor) {
266
					this.runInit(monitor);
267
					try {
268 179
						JobsTimer.start();
269 180
						monitor.beginTask(NLS.bind(RCPMessages.ComputeSpecifities_11, table.getPartition().getName()), 100);
270
						try {
271
							System.out.println(RCPMessages.ComputeSpecificities_0 + ": " + table.getPartition().getName()); //$NON-NLS-1$
272
							this.acquireSemaphore();
273
							specificitiesResult = new SpecificitesResult(table, maxScore);
274
							this.releaseSemaphore();
275
							System.out.println(NLS.bind(RCPMessages.DONE, specificitiesResult.getName()));
276
						}
277
						catch(StatException e) {
278
							System.err.println(NLS.bind(RCPMessages.Error_computing_specificities, e));
279
							org.txm.rcp.utils.Logger.printStackTrace(e);
280
							return Status.CANCEL_STATUS;
281
						}
282
						monitor.worked(45);
283
						if(monitor.isCanceled())
284
							return Status.CANCEL_STATUS;
285

  
181
						System.out.println(RCPMessages.ComputeSpecificities_0 + ": " + table.getPartition().getName()); //$NON-NLS-1$
182
						
286 183
						this.acquireSemaphore();
287
						table.addResult(specificitiesResult);
184
						specifRes = new Specificities(table, maxScore);
288 185
						this.releaseSemaphore();
289
						monitor.worked(5);
186
						
187
						System.out.println(NLS.bind(RCPMessages.DONE, specifRes.getName()));
188
						monitor.worked(45);
290 189

  
291
						monitor.subTask(RCPMessages.ComputeSpecifities_10);
292
						syncExec(new Runnable() {
293
							@Override
294
							public void run() {
295
								IWorkbenchPage page = window.getActivePage();
296
								SpecificitiesResultEditorInput editorInput = null;
297
								if(table.getPartition() == null) {
298
									editorInput = new SpecificitiesResultEditorInput(specificitiesResult, table.getCorpus());
299
								}
300
								else {
301
									editorInput = new SpecificitiesResultEditorInput(specificitiesResult, table.getPartition());
302
								}
303
								try {
304
									StatusLine.setMessage(RCPMessages.ComputeSpecifities_10);
305
									page.openEditor(editorInput, SpecificitiesTableEditor.ID); //$NON-NLS-1$
190
						if (monitor.isCanceled()) return Status.CANCEL_STATUS;
191
					} else if (s instanceof Specificities) { // re-openning a Speicificties result
192
						specifRes = (Specificities) s;
193
					}
306 194

  
307
								}
308
								catch(PartInitException e) {
309
									org.txm.rcp.utils.Logger.printStackTrace(e);
310
								}
311
							}
312
						});
195
					if (specifRes == null) {
196
						System.out.println("Cannot compute Specificities with "+s);
197
						return Status.CANCEL_STATUS; 
198
					}
199
					
200
					if (monitor.isCanceled()) return Status.CANCEL_STATUS;
313 201

  
314
						monitor.worked(50);
315
						if(monitor.isCanceled()) {
316
							return Status.CANCEL_STATUS;
317
						}
202
					final Specificities specifResFinal = specifRes;
203
					this.syncExec(new Runnable() {
204
						@Override
205
						public void run() {
206
							CorporaView.refresh();
207
							CorporaView.expand(specifResFinal.getParent());
318 208

  
319
						monitor.subTask(RCPMessages.ComputeSpecifities_2);
320
						syncExec(new Runnable() {
321
							@Override
322
							public void run() {
323
								CorporaView.refresh();
324
								CorporaView.expand(specificitiesResult.getParent());
325
								QueriesView.refresh();
326
								RVariablesView.refresh();
327
							}
328
						});
209
							TXMResultEditorInput editorInput = null;
329 210

  
330
						monitor.worked(100);
331
					}
332
					catch(ThreadDeath td) {
333
						return Status.CANCEL_STATUS;
334
					}
335
					catch(CqiClientException e) {
336
						org.txm.rcp.utils.Logger.printStackTrace(e);
337
					}
338
					finally {
339
						monitor.done();
340
						JobsTimer.stopAndPrint();
341
					}
342
					return Status.OK_STATUS;
343
				}
344
			};
345
			jobhandler.startJob();
346
		}
347
		// reopens an existing result
348
		else if(s instanceof SpecificitesResult) {
349
			SpecificitesResult specifRes = (SpecificitesResult) s;
350
			Partition partition = null;
351
			TXMResultEditorInput editorInput = null;
211
							editorInput = new SpecificitiesResultEditorInput(specifResFinal);
352 212

  
353
			if(specifRes.getLexicalTable() != null) {
354
				if(specifRes.getLexicalTable().getPartition() != null) {
355
					partition = specifRes.getLexicalTable().getPartition();
356
					editorInput = new SpecificitiesResultEditorInput(specifRes, partition);
213
							TXMEditorPart.openEditor(editorInput, SpecificitiesTableEditor.ID);
214
						}
215
					});
216
					
217
				} catch(Exception e) {
218
					System.out.println(RCPMessages.Error_computing_specificities);
219
					Log.printStackTrace(e);
220
					return Status.CANCEL_STATUS;
357 221
				}
358
				else {
359
					editorInput = new SpecificitiesResultEditorInput(specifRes, specifRes.getLexicalTable().getCorpus());
360
				}
361
			}
362
			else {
363
				editorInput = new SpecificitiesResultEditorInput(specifRes, specifRes.getCorpus());
364
			}
365 222

  
366
			TXMEditorPart.openEditor(editorInput, SpecificitiesTableEditor.ID);
367
		}
368

  
223
				return Status.OK_STATUS;
224
			}
225
		};
226
		jobhandler.startJob();
369 227
		return null;
370 228
	}
371 229
}
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/handlers/ComputeSpecifictiesBarChart.java (revision 534)
17 17
import org.txm.chartsengine.rcp.swt.ChartEditorToolBar;
18 18
import org.txm.core.preferences.TXMPreferences;
19 19
import org.txm.rcp.IImageKeys;
20
import org.txm.specificities.core.functions.SpecificitesResult;
20
import org.txm.specificities.core.functions.Specificities;
21 21
import org.txm.specificities.core.preferences.SpecificitiesPreferences;
22 22
import org.txm.specificities.rcp.editors.SpecificitiesTableEditor;
23 23
import org.txm.specificities.rcp.editors.SpecificitiesTableLines;
......
41 41
			}
42 42

  
43 43
			SpecificitiesTableEditor editor = (SpecificitiesTableEditor)ieditor;
44
			SpecificitesResult specificitiesResult = editor.getSpecificitiesResult();
44
			Specificities specificitiesResult = editor.getSpecificitiesResult();
45 45
			Table specificitesTable = editor.getSpecificitesTable();
46 46
			SpecificitiesTableLines tableLines = editor.getTableLines();
47 47
			double[][] specIndex = specificitiesResult.getSpecificitesIndex();
......
78 78
	 * @param typeNames
79 79
	 * @param specificteIndices
80 80
	 */
81
	public void openEditor(SpecificitesResult specificitiesResult, String[] partNames, String[] typeNames, double[][] specificteIndices) {
81
	public void openEditor(Specificities specificitiesResult, String[] partNames, String[] typeNames, double[][] specificteIndices) {
82 82
		try {
83 83

  
84 84
			// Set the data to focus on
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/adapters/SpecificitiesAdapterFactory.java (revision 534)
7 7
import org.osgi.framework.FrameworkUtil;
8 8
import org.txm.rcp.adapters.TXMResultAdapter;
9 9
import org.txm.rcp.adapters.TXMResultAdapterFactory;
10
import org.txm.specificities.core.functions.SpecificitesResult;
10
import org.txm.specificities.core.functions.Specificities;
11 11

  
12 12

  
13 13
/**
......
26 26

  
27 27
	@Override
28 28
	public Object getAdapter(Object adaptableObject, Class adapterType) {
29
		if(adapterType == IWorkbenchAdapter.class && adaptableObject instanceof SpecificitesResult)	{
29
		if(adapterType == IWorkbenchAdapter.class && adaptableObject instanceof Specificities)	{
30 30
			return new TXMResultAdapter() {
31 31
				@Override
32 32
				public ImageDescriptor getImageDescriptor(Object object) {
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/messages/messages_ru.properties (revision 534)
18 18
SpecificitiesTableEditor_11= T
19 19
SpecificitiesTableEditor_16=График: 
20 20
SpecificitiesTableEditor_17=Загрузка таблицы специфичности
21
SpecificitiesTableEditor_5=Неожиданная ошибка в статистической машине R
21
SpecificitiesTableEditor_5=Неожиданная ошибка в статистической машине R : {0}
22 22
SpecificitiesTableEditor_8=Построить гистограмму выделенных строк
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/messages/messages_fr.properties (revision 534)
19 19
SpecificitiesTableEditor_11=T
20 20
SpecificitiesTableEditor_16=Graphique : 
21 21
SpecificitiesTableEditor_17=Chargement de la table des spécificités
22
SpecificitiesTableEditor_5=Erreur inattendue dans le moteur statistique R
22
SpecificitiesTableEditor_5=Erreur inattendue dans le moteur statistique R : {0}
23 23
SpecificitiesTableEditor_8=Calculer le diagramme en bâtons des lignes sélectionnées
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/editors/SpecificitiesTableEditor.java (revision 534)
35 35
import java.util.Locale;
36 36

  
37 37
import org.eclipse.core.runtime.IProgressMonitor;
38
import org.eclipse.core.runtime.IStatus;
39
import org.eclipse.core.runtime.Status;
38 40
import org.eclipse.jface.action.MenuManager;
39 41
import org.eclipse.jface.operation.IRunnableWithProgress;
40 42
import org.eclipse.jface.viewers.IStructuredContentProvider;
......
50 52
import org.eclipse.swt.widgets.Label;
51 53
import org.eclipse.swt.widgets.Menu;
52 54
import org.eclipse.swt.widgets.ScrollBar;
55
import org.eclipse.swt.widgets.Spinner;
53 56
import org.eclipse.swt.widgets.Table;
54 57
import org.eclipse.swt.widgets.TableColumn;
55 58
import org.eclipse.ui.IEditorInput;
56 59
import org.eclipse.ui.IEditorSite;
57 60
import org.eclipse.ui.PartInitException;
58 61
import org.eclipse.ui.PlatformUI;
62
import org.eclipse.ui.part.EditorPart;
59 63
import org.txm.core.results.TXMResult;
60 64
import org.txm.objects.TxmObject;
61 65
import org.txm.rcp.RCPMessages;
62 66
import org.txm.rcp.StatusLine;
63 67
import org.txm.rcp.editors.TXMEditorPart;
64 68
import org.txm.rcp.editors.TableKeyListener;
65
import org.txm.specificities.core.functions.SpecificitesResult;
69
import org.txm.rcp.utils.JobHandler;
70
import org.txm.specificities.core.functions.Specificities;
71
import org.txm.specificities.core.preferences.SpecificitiesPreferences;
66 72
import org.txm.specificities.rcp.messages.SpecificitiesUIMessages;
67 73
import org.txm.statsengine.core.StatException;
74
import org.txm.utils.logger.Log;
68 75
/**
69 76
 * Display a table editor with specificites index.
70 77
 * 
......
74 81
public class SpecificitiesTableEditor extends TXMEditorPart {
75 82

  
76 83
	public static String ID = SpecificitiesTableEditor.class.getName();
77
	
84

  
78 85
	/** The specificities table. */
79 86
	private Table specificitesTable;
80 87
	private TableViewer viewer;
81
	
88

  
82 89
	/** Column for table typeNameTable. */
83 90
	private TableColumn typeNameColumn;
84 91

  
......
92 99
	private List<TableColumn> specificitesTableColumn = new ArrayList<TableColumn>();
93 100

  
94 101
	/** The result of specificities*/
95
	private SpecificitesResult specificitiesResult;
102
	private Specificities specificitiesResult;
96 103

  
97 104
	/** The table lines : table input */
98 105
	private SpecificitiesTableLines tableLines;
......
108 115
		super.init(site, input);
109 116

  
110 117
		SpecificitiesResultEditorInput spinput = (SpecificitiesResultEditorInput) getEditorInput();
111
		this.specificitiesResult = (SpecificitesResult) ((SpecificitiesResultEditorInput) getEditorInput()).getResult();
118
		this.specificitiesResult = (Specificities) ((SpecificitiesResultEditorInput) getEditorInput()).getResult();
112 119
		if (this.specificitiesResult.getLexicalTable()!= null && this.specificitiesResult.getLexicalTable().getPartition() != null)	{
113 120
			setPartName(this.specificitiesResult.getLexicalTable().getPartition().getName()+": "+specificitiesResult.getName()); //$NON-NLS-1$
114 121
		} else if (spinput.getSubcorpus() != null) {
......
123 130
	 */
124 131
	@Override
125 132
	public void createPartControl(Composite parent) {
126
		Composite displayArea = new Composite(parent, SWT.BORDER);
127
		displayArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
133
		super.createPartControl(parent);
134

  
135
		Composite parametersArea = getCommandParametersGroup();
136
		
137
		new Label(parametersArea, SWT.NONE).setText("Maximum score");
138
		
139
		Spinner maxScore = new Spinner(parametersArea, SWT.BORDER);
140
		maxScore.setToolTipText("The maximum score to show");
141
		maxScore.setMinimum(0);
142
		maxScore.setSelection(SpecificitiesPreferences.getInt(SpecificitiesPreferences.MAX_SCORE, SpecificitiesPreferences.PREFERENCES_NODE));
143
		
144
		Composite displayArea = getDisplayArea();
145
		//displayArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
128 146
		try {
129 147
			composeDisplayArea(displayArea);
130 148
		} catch (StatException e) {
......
140 158
						new IRunnableWithProgress() {
141 159
							@Override
142 160
							public void run(IProgressMonitor monitor)
143
							throws InvocationTargetException,
144
							InterruptedException {
161
									throws InvocationTargetException,
162
									InterruptedException {
145 163
								tableLines.sort(currentComparator);
146 164
							}
147 165
						});
......
165 183
		layout.marginWidth = layout.marginHeight = layout.horizontalSpacing = 0;
166 184
		parent.setLayout(layout);
167 185

  
168
		final SpecificitesResult specificitiesResult = this.specificitiesResult;
169
		// units
170
		final String[] typeNames = specificitiesResult.getTypeNames();
171
		// units' total freq
172
		final int[] typeFreq = specificitiesResult.getFormFrequencies();
173
		// units' index fr each part
174
		final double[][] specIndex = specificitiesResult.getSpecificitesIndex();
175
		final int[][] specFreqs = specificitiesResult.getFrequency();
176
		// units' total in parts
177
		//final int[] sortedPartIndexes = specificitesResult.getSortedPartIndexes();
178

  
179
		// Create an array of lines to fill the tables
180
//		System.out.println("len types: "+typeNames.length);
181
//		System.out.println("len freq: "+typeFreq.length);
182
//		System.out.println("len spec: "+specFreqs.length);
183
//		System.out.println("len specidx: "+specIndex.length);
184
		Object[] lines = new Object[typeNames.length];
185
		for (int j = 0; j < lines.length; j++)
186
			lines[j] = new Object[] { typeNames[j], new Integer(typeFreq[j]), specFreqs[j], specIndex[j] };
187

  
188
		// final SpecificitesTableLines
189
		tableLines = new SpecificitiesTableLines(lines);
190

  
191 186
		// create table viewer
192 187
		viewer = new TableViewer(parent, SWT.VIRTUAL | SWT.MULTI | SWT.FULL_SELECTION);
193 188
		viewer.getTable().addKeyListener(new TableKeyListener(viewer));
194 189
		viewer.getTable().setLinesVisible(true);
195 190
		viewer.getTable().setHeaderVisible(true);
196 191
		viewer.setLabelProvider(new SpecificitiesTableLabelProvider());
197
		viewer.setContentProvider(new IStructuredContentProvider() {
198
			@Override
199
			public Object[] getElements(Object inputElement) {
200
				return ((SpecificitiesTableLines) inputElement).getLines();
201
			}
202 192

  
203
			@Override
204
			public void dispose() { }
205

  
206
			@Override
207
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
208
			}
209
		});
210

  
211 193
		specificitesTable = viewer.getTable();
212 194
		GridData table2Data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2);
213 195
		specificitesTable.setLayoutData(table2Data);
......
319 301
			partSize = specificitiesResult.getPartSizes();
320 302
		} catch (StatException e) {
321 303
			System.err.println(NLS.bind(SpecificitiesUIMessages.SpecificitiesTableEditor_5, e));
304
			Log.printStackTrace(e);
322 305
			return;
323 306
		}
324 307
		// System.out.println("partnames: "+Arrays.toString(partNames));
......
351 334
									((int[]) line2[2])[columnIndex]));
352 335
						}
353 336
					};
354
					
337

  
355 338
					if (specificitesTable.getSortColumn() != freqpartTableColumn) {
356 339
						specificitesTable.setSortColumn(freqpartTableColumn);
357 340
						specificitesTable.setSortDirection(SWT.DOWN);
......
442 425
		specificitesTable.setMenu(menu);
443 426
		getSite().setSelectionProvider(viewer);
444 427
		getSite().registerContextMenu(menuManager, viewer);
445
		
446
		// Draw lines
447
		fillDisplay();
448 428

  
429

  
430

  
449 431
		// and first sort
450 432
		specificitesTable.setSortColumn(typeNameColumn);
451 433
		specificitesTable.setSortDirection(SWT.UP);
......
457 439
				return collator.compare(line1[0], line2[0]);
458 440
			}
459 441
		};
460
		
461
		sort();
462
		
463
		specificitesTable.setFocus();
442

  
443
		// compute the specif scores
444
		computeResult();
445

  
464 446
	}
465
	
447

  
466 448
	public Table getSpecificitesTable() {
467 449
		return specificitesTable;
468 450
	}
......
471 453
	 * Fills display.
472 454
	 */
473 455
	private void fillDisplay() {
474
		
456

  
475 457
		viewer.setInput(tableLines);
476 458

  
477 459
		// Pack the columns so the label of the sort column is not truncated due of the sorting order arrow display
......
534 516
	 *
535 517
	 * @return the specificities result
536 518
	 */
537
	public SpecificitesResult getSpecificitiesResult() {
519
	public Specificities getSpecificitiesResult() {
538 520
		return this.specificitiesResult;
539 521
	}
540
	
522

  
541 523
	public SpecificitiesTableLines getTableLines() {
542 524
		return tableLines;
543 525
	}
......
551 533

  
552 534
	@Override
553 535
	public void computeResult() {
554
		// FIXME! not yet implemented
555
		System.err.println("SpecificitiesTableEditor.computeResult(): not yet implemented.");
536
		JobHandler job = new JobHandler("Computing specificities...") {
537

  
538
			@Override
539
			protected IStatus run(IProgressMonitor monitor) {
540
				this.runInit(monitor);
541
				try {
542
					if (!specificitiesResult.compute(true, monitor)) {
543
						System.out.println("Error: Specificities not computed.");
544
						return Status.CANCEL_STATUS;
545
					}
546

  
547
					// units
548
					String[] typeNames = specificitiesResult.getTypeNames();
549
					// units' total freq
550
					int[] typeFreq = specificitiesResult.getFormFrequencies();
551
					// units' index fr each part
552
					double[][] specIndex = specificitiesResult.getSpecificitesIndex();
553
					int[][] specFreqs = specificitiesResult.getFrequency();
554
					
555
					// units' total in parts
556
					//final int[] sortedPartIndexes = specificitesResult.getSortedPartIndexes();
557

  
558
					// Create an array of lines to fill the tables
559
					//		System.out.println("len types: "+typeNames.length);
560
					//		System.out.println("len freq: "+typeFreq.length);
561
					//		System.out.println("len spec: "+specFreqs.length);
562
					//		System.out.println("len specidx: "+specIndex.length);
563
					Object[] lines = new Object[typeNames.length];
564
					for (int j = 0; j < lines.length; j++)
565
						lines[j] = new Object[] { typeNames[j], new Integer(typeFreq[j]), specFreqs[j], specIndex[j] };
566

  
567
					// final SpecificitesTableLines
568
					tableLines = new SpecificitiesTableLines(lines);
569
					
570
					// set the TableViewer input
571
					viewer.setContentProvider(new IStructuredContentProvider() {
572
						@Override
573
						public Object[] getElements(Object inputElement) {
574
							return ((SpecificitiesTableLines) inputElement).getLines();
575
						}
576

  
577
						@Override
578
						public void dispose() { }
579

  
580
						@Override
581
						public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
582
						}
583
					});
584
					
585
					this.syncExec(new Runnable() {
586
						@Override
587
						public void run() {
588
							viewer.refresh();
589
							SpecificitiesTableEditor.this.firePropertyChange(EditorPart.PROP_DIRTY);
590
							// Draw lines
591
							fillDisplay();
592
							sort();
593
							specificitesTable.setFocus();
594
						}
595
					});
596
					
597
				} catch (Exception e) {
598
					System.out.println("Error while computing specificities: "+e.getLocalizedMessage());
599
					Log.printStackTrace(e);
600
				}
601
				return Status.OK_STATUS;
602
			}
603
		};
604
		job.schedule();
556 605
	}
557 606

  
558 607
	@Override
559 608
	protected void initializeFields() {
560 609
		// TODO Auto-generated method stub
561
		
610

  
562 611
	}
563 612
}
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/editors/SpecificitiesResultEditorInput.java (revision 534)
51 51
import org.txm.rcp.editors.input.IProvidingMultiPageEditorInput;
52 52
import org.txm.searchengine.cqp.corpus.Corpus;
53 53
import org.txm.searchengine.cqp.corpus.Partition;
54
import org.txm.specificities.core.functions.SpecificitesResult;
54
import org.txm.specificities.core.functions.Specificities;
55 55
import org.txm.specificities.rcp.messages.SpecificitiesUIMessages;
56 56
import org.txm.statsengine.core.StatException;
57 57
// TODO: Auto-generated Javadoc
......
91 91
	 * @param specificitiesResult the specificities result
92 92
	 * @param subcorpus the subcorpus
93 93
	 */
94
	public SpecificitiesResultEditorInput(SpecificitesResult specificitiesResult, Corpus subcorpus) {
94
	public SpecificitiesResultEditorInput(Specificities specificitiesResult, Corpus subcorpus) {
95 95
		this(specificitiesResult);
96 96
		this.subcorpus = subcorpus;
97 97
		init();
......
103 103
	 * @param specificitiesResult the specificities result
104 104
	 * @param partition the partition
105 105
	 */
106
	public SpecificitiesResultEditorInput(SpecificitesResult specificitiesResult, Partition partition) {
106
	public SpecificitiesResultEditorInput(Specificities specificitiesResult, Partition partition) {
107 107
		this(specificitiesResult);
108 108
		this.partition = partition;
109 109
		specificitiesResult.getLexicalTable().getPartition();
......
114 114
	}
115 115

  
116 116
	
117
	public SpecificitiesResultEditorInput(SpecificitesResult specificitiesResult)	{
117
	public SpecificitiesResultEditorInput(Specificities specificitiesResult)	{
118 118
		super(specificitiesResult);
119 119
	}
120 120
	
......
323 323
		 */
324 324
		@Override
325 325
		public Object[] getElements(Object inputElement) {
326
			SpecificitesResult res = (SpecificitesResult) inputElement;
326
			Specificities res = (Specificities) inputElement;
327 327
			int[][] freq = null;
328 328
			double[][] specificitiesIndex = null;
329 329
			String[] names = null;
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/office/SetOfficeMacro.groovy (revision 534)
1
// STANDARD DECLARATIONS
2
package org.txm.macro.office
3

  
4
import org.kohsuke.args4j.*
5
import groovy.transform.Field
6
import org.txm.rcpapplication.swt.widget.parameters.*
7

  
8
// BEGINNING OF PARAMETERS
9

  
10
@Field @Option(name="office_path", usage="Path to LibreOffice or OpenOffice installation directory", widget="Folder", required=false, def="libreoffice or openoffice install directory")
11
def office_path
12

  
13
// Open the parameters input dialog box
14
if (!ParametersDialog.open(this)) return;
15

  
16
// END OF PARAMETERS
17

  
18
if (office_path == null) {
19
	println "No path to office directory given."
20
	return
21
}
22

  
23
if (!office_path.exists()) {
24
	println "'$office_path' directory not found."
25
	return
26
}
27

  
28
if (!office_path.isDirectory()) {
29
	println "'$office_path' exists but is not a directory."
30
	return
31
}
32

  
33
if (!office_path.canExecute()) {
34
	println "'$office_path' exists but has not sufficent rights to be used."
35
	return
36
}
37

  
38
def old = System.getProperty("office.home")
39
System.setProperty("office.home", office_path.getAbsolutePath())
40
println "Office path set to '"+System.getProperty("office.home")+"'."
41
if (old != null) {
42
	println "	Previous path was '${old}'."
43
}
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/stats/BasicVocabularyMacro.groovy (revision 534)
34 34
import org.kohsuke.args4j.*
35 35
import groovy.transform.Field
36 36
import org.txm.rcp.swt.widget.parameters.*
37
import org.txm.specificities.core.functions.SpecificitesResult
37
import org.txm.specificities.core.functions.Specificities
38 38

  
39
if (!(corpusViewSelection instanceof SpecificitesResult)) {
39
if (!(corpusViewSelection instanceof Specificities)) {
40 40
	println "** You need to select a Specificities result icon in the Corpus view before calling this macro. Aborting."
41 41
	return
42 42
}
tmp/org.txm.groovy.core/src/groovy/org/txm/macroproto/SelectSpecifMacro.groovy (revision 534)
4 4
import org.txm.searchengine.cqp.corpus.*
5 5
import org.txm.searchengine.cqp.corpus.query.*
6 6
import org.txm.statsengine.r.core.RWorkspace
7
import org.txm.specificities.core.functions.SpecificitesResult
7
import org.txm.specificities.core.functions.Specificities
8 8
import org.kohsuke.args4j.*
9 9
import groovy.transform.Field
10 10
import org.txm.rcp.swt.widget.parameters.*
11 11

  
12
if (!(corpusViewSelection instanceof SpecificitesResult)) {
12
if (!(corpusViewSelection instanceof Specificities)) {
13 13
	println "Selection if not a Specificites Result"
14 14
	return;
15 15
}
tmp/org.txm.groovy.core/src/groovy/org/txm/macroproto/SelectBanal.groovy (revision 534)
4 4
import org.txm.searchengine.cqp.corpus.*
5 5
import org.txm.searchengine.cqp.corpus.query.*
6 6
import org.txm.statsengine.r.core.RWorkspace
7
import org.txm.specificities.core.functions.SpecificitesResult
7
import org.txm.specificities.core.functions.Specificities
8 8
import org.kohsuke.args4j.*
9 9
import groovy.transform.Field
10 10
import org.txm.rcp.swt.widget.parameters.*
11 11

  
12
if (!(corpusViewSelection instanceof SpecificitesResult)) {
12
if (!(corpusViewSelection instanceof Specificities)) {
13 13
	println "Selection if not a Specificites Result"
14 14
	return;
15 15
}
tmp/org.txm.groovy.core/build.properties (revision 534)
1 1
source.. = src/
2 2
output.. = bin/
3 3
bin.includes = META-INF/,\
4
               .
4
               .,\
5
               bin/
5 6
jars.compile.order = .
tmp/org.txm.groovy.core/.classpath (revision 534)
2 2
<classpath>
3 3
	<classpathentry kind="src" path="src/groovy"/>
4 4
	<classpathentry kind="src" path="src/java"/>
5
	<classpathentry exported="true" kind="lib" path="bin/"/>
5 6
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
6 7
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
7 8
	<classpathentry kind="con" path="GROOVY_DSL_SUPPORT"/>
tmp/org.txm.groovy.core/META-INF/MANIFEST.MF (revision 534)
36 36
 org.txm.libs.cqp;bundle-version="1.0.0",
37 37
 org.txm.searchengine.core;bundle-version="1.0.0",
38 38
 org.eclipse.swt;bundle-version="3.103.2"
39
Export-Package: filters.BuildXmlLiturgie,
39
Export-Package: .,
40
 filters.BuildXmlLiturgie,
40 41
 filters.Concatenator,
41 42
 filters.CutHeader,
42 43
 filters.EliminateWhiteSpaces,
......
124 125
 org.txm.test,
125 126
 org.txm.tokenizer,
126 127
 tests
127
Bundle-ClassPath: .
128
Bundle-ClassPath: .,
129
 bin/
128 130
Bundle-ActivationPolicy: lazy
tmp/org.txm.cooccurrence.core/src/org/txm/cooccurrence/core/functions/Cooccurrence.java (revision 534)
61 61
import org.txm.searchengine.cqp.corpus.query.Match;
62 62
import org.txm.searchengine.cqp.corpus.query.Query;
63 63
import org.txm.searchengine.cqp.serverException.CqiServerError;
64
import org.txm.specificities.core.statsengine.r.function.SpecificitiesImpl;
64
import org.txm.specificities.core.statsengine.r.function.SpecificitiesR;
65 65
import org.txm.statsengine.core.StatException;
66 66
import org.txm.statsengine.r.core.RWorkspace;
67 67
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
......
1370 1370
	 */
1371 1371
	public boolean stepGetScores() throws CqiClientException, StatException {
1372 1372

  
1373
		SpecificitiesImpl specif = new SpecificitiesImpl(lt);
1373
		SpecificitiesR specif = new SpecificitiesR(lt);
1374 1374
		//System.out.println("Specif N part: "+specif.getNbrPart()); //$NON-NLS-1$
1375 1375
		//System.out.println("Specif N lines number: "+specif.getSpecificitesIndex().length); //$NON-NLS-1$
1376 1376
		//System.out.println("T specif e: "+(System.currentTimeMillis()- time)); //$NON-NLS-1$
tmp/org.txm.ca.rcp/src/org/txm/ca/rcp/editors/CAEditor.java (revision 534)
326 326

  
327 327
		// FIXME: need to create ChartResult for CASingularValues + some ChartCreators 
328 328
		// Editor part
329
		EditorPart caSingularValuesEditorPart = new ChartEditorPart(SWTChartsComponentsProvider.getCurrent().createChartEditorInput(ca, "Singular Values")); //$NON-NLS-1$ 
329
		EditorPart caSingularValuesEditorPart = new ChartEditorPart(SWTChartsComponentsProvider.getCurrent().createChartEditorInput(ca)); //$NON-NLS-1$ 
330 330
		editors.add(caSingularValuesEditorPart);
331 331

  
332 332
		// Editor input
tmp/org.txm.specificities.core/src/org/txm/specificities/core/functions/SpecificitesResult.java (revision 534)
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: 2017-01-24 18:11:42 +0100 (Tue, 24 Jan 2017) $
25
// $LastChangedRevision: 3400 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.specificities.core.functions;
29

  
30
import java.io.BufferedWriter;
31
import java.io.File;
32
import java.io.FileNotFoundException;
33
import java.io.FileOutputStream;
34
import java.io.IOException;
35
import java.io.OutputStreamWriter;
36
import java.io.UnsupportedEncodingException;
37
import java.util.Arrays;
38
import java.util.List;
39

  
40
import org.rosuda.REngine.REXPMismatchException;
41
import org.rosuda.REngine.Rserve.RserveException;
42
import org.txm.chartsengine.core.results.ChartResult;
43
import org.txm.core.results.TXMParameters;
44
import org.txm.lexicaltable.core.functions.LexicalTable;
45
import org.txm.lexicaltable.core.functions.LexicalTableFactory;
46
import org.txm.lexicon.core.corpusengine.cqp.Lexicon;
47
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
48
import org.txm.searchengine.cqp.corpus.Corpus;
49
import org.txm.searchengine.cqp.corpus.Partition;
50
import org.txm.searchengine.cqp.corpus.Property;
51
import org.txm.searchengine.cqp.corpus.Subcorpus;
52
import org.txm.specificities.core.messages.SpecificitiesCoreMessages;
53
import org.txm.specificities.core.statsengine.r.function.SpecificitiesImpl;
54
import org.txm.statsengine.core.StatException;
55
import org.txm.statsengine.core.data.Vector;
56
import org.txm.statsengine.core.utils.ArrayIndex;
57
import org.txm.statsengine.core.utils.CheckArray;
58
import org.txm.statsengine.r.core.RWorkspace;
59
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
60

  
61
/**
62
 * Hold specificities computation result.
63
 * 
64
 * @author mdecorde
65
 * @author sloiseau
66
 * 
67
 */
68
public class SpecificitesResult extends ChartResult  {
69

  
70
	public static int MAXSPECIF = 1000;
71

  
72
	/** The indices. */
73
	private double[][] indices;
74

  
75
	/** The table. */
76
	private LexicalTable table;
77

  
78
	/** The rowindex. */
79
	private int[] rowindex = null;
80

  
81
	/** The colindex. */
82
	private int[] colindex = null;
83

  
84
	/** The frequencies. */
85
	private int[][] frequencies = null;
86

  
87
	/** The lexicon. */
88
	private Lexicon lexicon;
89

  
90
	/** The sub lexicon. */
91
	private Lexicon subLexicon;
92

  
93
	/** The colnames. */
94
	private List<String> colnames = null;
95

  
96
	/** The rownames. */
97
	private List<String> rownames = null;
98

  
99
	/** The corpus. */
100
	private Corpus corpus = null;
101

  
102
	/** The sub corpus. */
103
	private Corpus subCorpus = null;
104

  
105
	/** The name. */
106
	private String name;
107

  
108
	/** The symbol. */
109
	private String symbol;
110

  
111
	/** The subcorpus. */
112
	private Corpus subcorpus;
113

  
114
	/** The writer. */
115
	@Deprecated
116
	private BufferedWriter writer;
117
	
118
	/**
119
	 * The selected type names to focus on.
120
	 */
121
	protected String[] selectedTypeNames;
122

  
123
	/**
124
	 * The selected part names to focus on.
125
	 */
126
	protected String[] selectedPartNames;
127

  
128
	/**
129
	 * The selected specificities indices to focus on.
130
	 */
131
	protected double[][] selectedSpecificitiesIndex;
132
	
133
	
134
	protected boolean _compute(boolean update) {
135
		//TODO: not implemented yet. The specificitesResults should work with a LexicalTable only? if yes, then the calling commands must build it
136
		return false;
137
	}
138
	
139
	/**
140
	 * Compute the specificity index for all the cells of a complete lexical
141
	 * table, as defined by a {@link Partition} and a {@link Property}.
142
	 * 
143
	 * This may be used for extracting, for all part, the forms the most or the
144
	 * less specif ic.
145
	 *
146
	 * @param partition the partition
147
	 * @param analysisProperty the analysis property
148
	 * @param formFocus the form focus
149
	 * @param partsFocus the parts focus
150
	 * @param Fmin the fmin
151
	 * @return the specificites result
152
	 * @throws CqiClientException the cqi client exception
153
	 * @throws StatException the stat exception
154
	 */
155
	public SpecificitesResult(Partition partition, Property analysisProperty, int Fmin, int maxScore) throws Exception {
156
		this(LexicalTableFactory.getLexicalTable(partition, analysisProperty, Fmin), maxScore);
157

  
158
		if (partition.getParts().size() < 2) {
159
			throw new IllegalArgumentException(SpecificitiesCoreMessages.ComputeError_NEED_AT_LEAST_2_PARTS);
160
		}
161
	}
162

  
163
	/**
164
	 * Specificites.
165
	 *
166
	 * @param table the table
167
	 * @return the specificites result
168
	 * @throws CqiClientException the cqi client exception
169
	 * @throws StatException the stat exception
170
	 */
171
	public SpecificitesResult(LexicalTable table, int maxScore)	throws CqiClientException, StatException {
172
		super(table);
173
		if (table.getNColumns() < 2) {
174
			throw new IllegalArgumentException(SpecificitiesCoreMessages.ComputeError_NEED_AT_LEAST_2_PARTS);
175
		}
176

  
177
		SpecificitiesImpl si = new SpecificitiesImpl(table.getData());
178

  
179
		double[][] specIndex = si.getScores();
180

  
181
		if (table.getPartition() != null) {
182
//			System.out.println("table="+table);
183
//			System.out.println("rows="+table.getRowNames());
184
//			System.out.println("cols="+table.getColNames());
185
//			System.out.println("prop="+table.getProperty());
186
			init(symbol, specIndex, table, Arrays
187
					.asList(table.getRowNames().asStringsArray()), Arrays.asList(table.getColNames().asStringsArray()), table.getProperty().getName(), maxScore); 
188
		} else {
189
			init(si.getSymbol(), specIndex, table, Arrays
190
					.asList(table.getRowNames().asStringsArray()), Arrays.asList(table.getColNames().asStringsArray()),
191
					"TLNONAME: " + table.getProperty().getName(), maxScore); //$NON-NLS-1$
192
		}
193
	}
194

  
195
	/**
196
	 * Specificites.
197
	 *
198
	 * @param corpus the corpus
199
	 * @param subcorpus the subcorpus
200
	 * @param property the property
201
	 * @return the specificites result
202
	 * @throws CqiClientException the cqi client exception
203
	 * @throws StatException the stat exception
204
	 * @throws REXPMismatchException 
205
	 * @throws RserveException 
206
	 */
207
	public SpecificitesResult(Corpus corpus, Subcorpus subcorpus, Property property, int maxScore) throws Exception {
208
		super(corpus);
209
		Lexicon totalFrequencies = Lexicon.getLexicon(corpus, property);
210
		Lexicon subFrequencies = Lexicon.getLexicon(subcorpus, property);
211

  
212
		//System.out.println("Send corpus vector");
213
		Vector totalFSymbol;
214
		Vector subFSymbol;
215
		try {
216
			totalFSymbol = totalFrequencies.asVector();
217
			subFSymbol = subFrequencies.asVector();
218
		} catch (StatException e) {
219
			throw new RWorkspaceException(e);
220
		}
221

  
222
		SpecificitiesImpl si = new SpecificitiesImpl(totalFSymbol, subFSymbol);
223
		double[][] specIndex = si.getScores();
224

  
225
		init(si.getSymbol(), specIndex, totalFrequencies, subFrequencies, corpus.getName()+"\\"+subcorpus.getName(), maxScore);
226
	}
227
	
228

  
229
	/**
230
	 * Instantiates a new specificities result : for subcorpus specificities.
231
	 *
232
	 * @param symbol the symbol
233
	 * @param specIndex the spec index
234
	 * @param lexicon the lexicon
235
	 * @param subLexicon the sub lexicon
236
	 * @param name the name
237
	 */
238
	protected void init(String symbol, double[][] specIndex, Lexicon lexicon, Lexicon subLexicon, String name, int maxScore) {
239
		
240
		//super(subLexicon.getCorpus());
241
		this.corpus = subLexicon.getCorpus();
242
		this.symbol = symbol;
243
		this.indices = specIndex;
244

  
245
		this.lexicon = lexicon;
246
		this.subLexicon = subLexicon;
247
		this.corpus = lexicon.getCorpus();
248
		this.subCorpus = subLexicon.getCorpus();
249
		this.name = name;
250

  
251
		int MAX = MAXSPECIF;
252
		int MIN = -MAXSPECIF;
253

  
254
		if (maxScore > 0) {
255
			MAX = maxScore;
256
			MIN = -maxScore;
257
		}
258
		for (int i = 0 ; i < indices.length ; i++) {
259
			for (int j = 0 ; j < indices[i].length ; j++) {
260
				if (indices[i][j] > MAX) {
261
					indices[i][j] = MAX;
262
				} else if (indices[i][j] < MIN) {
263
					indices[i][j] = MIN;
264
				}
265
			}
266
		}
267

  
268
		this.table = null;
269
	}
270

  
271
	/**
272
	 * Instantiates a new specificities result.
273
	 *
274
	 * @param symbol the symbol
275
	 * @param specIndex the spec index (as double[row][column])
276
	 * @param table the table
277
	 * @param typeFocus names of the rows of the lexical table with corresponding rows
278
	 * in the specIndex array; <code>null</code> if all the rows are
279
	 * represented in specIndex.
280
	 * @param partFocus names of the cols of the lexical table with corresponding cols
281
	 * in the specIndex array; <code>null</code> if all the cols are
282
	 * represented in specIndex.
283
	 * @param name the name
284
	 * @param maxScore if abs(score) > maxScore -> score = +/- maxScore
285
	 * @throws StatException the stat exception
286
	 */
287
	protected void init(String symbol, double[][] specIndex, LexicalTable table,
288
			List<String> typeFocus, List<String> partFocus, String name, int maxScore)
289
					throws StatException {
290
		
291
		this.table = table;
292
		this.symbol = symbol;
293

  
294
		if (table == null) {
295
			throw new IllegalArgumentException(SpecificitiesCoreMessages.SpecificitesResult_2);
296
		}
297
		this.name = name;
298

  
299
		if (specIndex == null || specIndex.length == 0) {
300
			throw new IllegalArgumentException(SpecificitiesCoreMessages.SpecificitesResult_0);
301
		}
302
		boolean ok = CheckArray.checkMatrixRepresentation(specIndex);
303
		if (!ok) {
304
			throw new IllegalArgumentException(SpecificitiesCoreMessages.SpecificitesResult_1);
305
		}
306

  
307
		this.indices = specIndex;
308
		this.table = table;
309
		this.colnames = partFocus;
310
		this.rownames = typeFocus;
311

  
312
		// filter by max&min
313
		int MAX = MAXSPECIF;
314
		int MIN = -MAXSPECIF;
315

  
316
		if (maxScore > 0) {
317
			MAX = maxScore;
318
			MIN = -maxScore;
319
		}
320

  
321
		for (int i = 0 ; i < indices.length ; i++) {
322
			for (int j = 0 ; j < indices[i].length ; j++) {
323
				if (indices[i][j] > MAX) {
324
					indices[i][j] = MAX;
325
				} else if (indices[i][j] < MIN) {
326
					indices[i][j] = MIN;
327
				}
328
			}
329
		}
330

  
331
		if (typeFocus != null && typeFocus.size() != 0) {
332
			if (typeFocus.size() != specIndex.length) {
333
				throw new IllegalArgumentException(
334
						SpecificitiesCoreMessages.bind(SpecificitiesCoreMessages.ComputeError_FOUND_AND_WANTED_ROWS_MISMATCH, typeFocus.size(), specIndex.length));
335
			}
336

  
337
			rowindex = ArrayIndex.getIndex(
338
					table.getRowNames().asStringsArray(), typeFocus
339
					.toArray(new String[] {}));
340
			for (int i : rowindex) {
341
				if (i == -1) {
342
					throw new IllegalArgumentException(
343
							SpecificitiesCoreMessages.SpecificitesResult_6);
344
				}
345
			}
346
		}
347
//		if (partFocus != null && partFocus.size() != 0) {
348
//			if (partFocus.size() != specIndex[0].length) {
349
//				throw new IllegalArgumentException(
350
//						SpecificitiesCoreMessages.SpecificitesResult_7 + partFocus.size()
351
//						+ ", " + specIndex[0].length + ")."); //$NON-NLS-1$//$NON-NLS-2$ 
352
//			}
353
//			colindex = ArrayIndex.getIndex(
354
//					table.getColNames().asStringsArray(), partFocus
355
//					.toArray(new String[] {}));
356
//			for (int i : colindex) {
357
//				if (i == -1) {
358
//					throw new IllegalArgumentException(
359
//							SpecificitiesCoreMessages.SpecificitesResult_10);
360
//				}
361
//			}
362
//		}
363
	}
364

  
365
	/**
366
	 * Gets the type focus.
367
	 *
368
	 * @return the type focus
369
	 */
370
	public List<String> getTypeFocus() {
371
		return rownames;
372
	}
373

  
374
	/**
375
	 * Gets the part focus.
376
	 *
377
	 * @return the part focus
378
	 */
379
	public List<String> getPartFocus() {
380
		return colnames;
381
	}
382

  
383
	/**
384
	 * Gets the nbr part.
385
	 *
386
	 * @return the nbr part
387
	 * @throws StatException the stat exception
388
	 */
389
	public int getNbrPart() throws StatException {
390
		if (table != null)
391
			return table.getNColumns();
392
		else
393
			return getPartShortNames().length;
394
	}
395

  
396
	/**
397
	 * Gets the corpus size.
398
	 *
399
	 * @return the corpus size
400
	 * @throws StatException the stat exception
401
	 */
402
	public int getCorpusSize() throws StatException {
403
		return table != null ? table.getData().getTotal() : lexicon.nbrOfToken();
404
	}
405

  
406
	/**
407
	 * Gets the specificities index.
408
	 * 
409
	 * @return the specificities index
410
	 */
411
	public double[][] getSpecificitesIndex() {
412
		return indices;
413
	}
414

  
415
	/**
416
	 * Name of the type for which specificities are computed.
417
	 *
418
	 * @return the type names
419
	 * @throws StatException the stat exception
420
	 */
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff