Révision 133
tmp/org.txm.cah.core/.settings/org.eclipse.jdt.core.prefs (revision 133) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 |
|
4 |
org.eclipse.jdt.core.compiler.compliance=1.6 |
|
5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
6 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
7 |
org.eclipse.jdt.core.compiler.source=1.6 |
|
0 | 8 |
tmp/org.txm.cah.core/.classpath (revision 133) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
|
5 |
<classpathentry kind="src" path="src"/> |
|
6 |
<classpathentry kind="output" path="bin"/> |
|
7 |
</classpath> |
|
0 | 8 |
tmp/org.txm.cah.core/META-INF/MANIFEST.MF (revision 133) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: CAH TBX |
|
4 |
Bundle-SymbolicName: org.txm.cah.core |
|
5 |
Bundle-Version: 1.0.0.qualifier |
|
6 |
Bundle-Activator: org.txm.cah.core.Activator |
|
7 |
Require-Bundle: org.eclipse.ui, |
|
8 |
org.eclipse.core.runtime, |
|
9 |
org.txm.core;bundle-version="0.7.0", |
|
10 |
org.txm.chartsengine.core;bundle-version="1.0.0", |
|
11 |
org.txm.chartsengine.r.core;bundle-version="1.0.0", |
|
12 |
org.txm.chartsengine.jfreechart.core;bundle-version="1.0.0" |
|
13 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 |
|
14 |
Bundle-ActivationPolicy: lazy |
|
15 |
Export-Package: org.txm.cah.core, |
|
16 |
org.txm.cah.functions |
|
0 | 17 |
tmp/org.txm.cah.core/.project (revision 133) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.cah.core</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
<buildCommand> |
|
14 |
<name>org.eclipse.pde.ManifestBuilder</name> |
|
15 |
<arguments> |
|
16 |
</arguments> |
|
17 |
</buildCommand> |
|
18 |
<buildCommand> |
|
19 |
<name>org.eclipse.pde.SchemaBuilder</name> |
|
20 |
<arguments> |
|
21 |
</arguments> |
|
22 |
</buildCommand> |
|
23 |
</buildSpec> |
|
24 |
<natures> |
|
25 |
<nature>org.eclipse.pde.PluginNature</nature> |
|
26 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
27 |
</natures> |
|
28 |
</projectDescription> |
|
0 | 29 |
tmp/org.txm.cah.core/src/org/txm/cah/core/Activator.java (revision 133) | ||
---|---|---|
1 |
package org.txm.cah.core; |
|
2 |
|
|
3 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
4 |
import org.osgi.framework.BundleContext; |
|
5 |
|
|
6 |
/** |
|
7 |
* The activator class controls the plug-in life cycle |
|
8 |
*/ |
|
9 |
public class Activator extends AbstractUIPlugin { |
|
10 |
|
|
11 |
// The plug-in ID |
|
12 |
public static final String PLUGIN_ID = "org.txm.cah.core"; //$NON-NLS-1$ |
|
13 |
|
|
14 |
// The shared instance |
|
15 |
private static Activator plugin; |
|
16 |
|
|
17 |
/** |
|
18 |
* The constructor |
|
19 |
*/ |
|
20 |
public Activator() { |
|
21 |
} |
|
22 |
|
|
23 |
/* |
|
24 |
* (non-Javadoc) |
|
25 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
|
26 |
*/ |
|
27 |
public void start(BundleContext context) throws Exception { |
|
28 |
super.start(context); |
|
29 |
plugin = this; |
|
30 |
} |
|
31 |
|
|
32 |
/* |
|
33 |
* (non-Javadoc) |
|
34 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
|
35 |
*/ |
|
36 |
public void stop(BundleContext context) throws Exception { |
|
37 |
plugin = null; |
|
38 |
super.stop(context); |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* Returns the shared instance |
|
43 |
* |
|
44 |
* @return the shared instance |
|
45 |
*/ |
|
46 |
public static Activator getDefault() { |
|
47 |
return plugin; |
|
48 |
} |
|
49 |
|
|
50 |
} |
|
0 | 51 |
tmp/org.txm.cah.core/src/org/txm/cah/functions/package.html (revision 133) | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
<p>Classifcation using FactoMineR's CAH.</p> |
|
4 |
</body> |
|
5 |
</html> |
|
0 | 6 |
tmp/org.txm.cah.core/src/org/txm/cah/functions/CAH.java (revision 133) | ||
---|---|---|
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:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.cah.functions; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
|
|
32 |
import org.rosuda.REngine.REXP; |
|
33 |
import org.rosuda.REngine.REXPMismatchException; |
|
34 |
import org.txm.HasResults; |
|
35 |
import org.txm.Messages; |
|
36 |
import org.txm.functions.Function; |
|
37 |
import org.txm.functions.TXMResult; |
|
38 |
import org.txm.functions.ca.CA; |
|
39 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
40 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
41 |
import org.txm.stat.data.LexicalTable; |
|
42 |
import org.txm.stat.engine.r.RWorkspace; |
|
43 |
import org.txm.stat.engine.r.RWorkspaceException; |
|
44 |
|
|
45 |
// TODO: Auto-generated Javadoc |
|
46 |
/** |
|
47 |
* The Class CAH. |
|
48 |
* |
|
49 |
* @author mdecorde |
|
50 |
* |
|
51 |
*/ |
|
52 |
public class CAH extends Function implements TXMResult |
|
53 |
{ |
|
54 |
/** The metric. */ |
|
55 |
String metric = "euclidean"; // euclidean, manhattan //$NON-NLS-1$ |
|
56 |
|
|
57 |
/** The method. */ |
|
58 |
String method = "ward"; // METHODS <- c("average", "single", "complete", "ward", "weighted", "flexible") //$NON-NLS-1$ |
|
59 |
|
|
60 |
/** The N cluster. */ |
|
61 |
int NCluster = 3; |
|
62 |
|
|
63 |
/** The columns. */ |
|
64 |
boolean columns = true; |
|
65 |
|
|
66 |
/** The symbol. */ |
|
67 |
String symbol = null; |
|
68 |
|
|
69 |
/** The target. */ |
|
70 |
String target; |
|
71 |
|
|
72 |
/** The partition. */ |
|
73 |
Partition partition; |
|
74 |
Corpus corpus; |
|
75 |
|
|
76 |
/** The source. */ |
|
77 |
Object source; |
|
78 |
|
|
79 |
/** The name. */ |
|
80 |
String name; |
|
81 |
|
|
82 |
/** The display2 d. */ |
|
83 |
// FIXME : to remove when charts engine will be validated |
|
84 |
@Deprecated |
|
85 |
boolean display2D; |
|
86 |
|
|
87 |
// FIXME : to remove when charts engine will be validated |
|
88 |
@Deprecated |
|
89 |
private File svgFile; |
|
90 |
|
|
91 |
|
|
92 |
/** |
|
93 |
* The coordinates of the clusters. |
|
94 |
*/ |
|
95 |
protected double[][] clusterCoords = null; |
|
96 |
|
|
97 |
/** |
|
98 |
* The numbers of the clusters. |
|
99 |
*/ |
|
100 |
protected int[] clusterNumbers = null; |
|
101 |
|
|
102 |
/** |
|
103 |
* The names of the cluster rows. |
|
104 |
*/ |
|
105 |
protected String[] clusterRowNames = null; |
|
106 |
|
|
107 |
/** |
|
108 |
* The ordered names of the cluster rows. |
|
109 |
*/ |
|
110 |
protected String[] clusterOrderedRowNames = null; |
|
111 |
|
|
112 |
/** |
|
113 |
* The cluster tree heights. |
|
114 |
*/ |
|
115 |
protected double[] clusterHeights = null; |
|
116 |
|
|
117 |
/** |
|
118 |
* The cluster tree merges. |
|
119 |
*/ |
|
120 |
protected double[][] clusterMerges = null; |
|
121 |
|
|
122 |
/** |
|
123 |
* The inertia gains. |
|
124 |
*/ |
|
125 |
protected double[] inertiaGains = null; |
|
126 |
|
|
127 |
protected CA ca; |
|
128 |
protected LexicalTable table; |
|
129 |
|
|
130 |
|
|
131 |
/** |
|
132 |
* Instantiates a new cAH. |
|
133 |
* |
|
134 |
* @param ca the ca |
|
135 |
* @param col the col |
|
136 |
* @param method the method |
|
137 |
* @param metric the metric |
|
138 |
* @param NCluster the n cluster |
|
139 |
* @param display2D the display mode |
|
140 |
*/ |
|
141 |
public CAH(CA ca, boolean col, String method, String metric, int NCluster, Boolean display2D) |
|
142 |
{ |
|
143 |
this.ca = ca; |
|
144 |
this.table = ca.getLexicalTable(); |
|
145 |
this.columns = col; |
|
146 |
this.metric = metric; |
|
147 |
this.NCluster = NCluster; |
|
148 |
this.method = method; |
|
149 |
this.display2D = display2D; |
|
150 |
|
|
151 |
this.source = ca; |
|
152 |
this.partition = ca.getPartition(); |
|
153 |
this.corpus = ca.getCorpus(); |
|
154 |
this.target = ca.getSymbol(); |
|
155 |
this.name = ca.getName(); |
|
156 |
} |
|
157 |
|
|
158 |
/** |
|
159 |
* Instantiates a new cAH. |
|
160 |
* |
|
161 |
* @param table the table |
|
162 |
* @param col the col |
|
163 |
* @param method the method |
|
164 |
* @param metric the metric |
|
165 |
* @param NCluster the n cluster |
|
166 |
* @param displayMode the display mode |
|
167 |
*/ |
|
168 |
public CAH(LexicalTable table, boolean col, String method, String metric, int NCluster, Boolean display2D) |
|
169 |
{ |
|
170 |
this.columns = col; |
|
171 |
this.metric = metric; |
|
172 |
this.NCluster = NCluster; |
|
173 |
this.method = method; |
|
174 |
this.display2D = display2D; |
|
175 |
|
|
176 |
this.source = table; |
|
177 |
this.partition = table.getPartition(); |
|
178 |
this.corpus = table.getCorpus(); |
|
179 |
this.target = table.getSymbol(); |
|
180 |
this.name = table.getName(); |
|
181 |
this.table = table; |
|
182 |
} |
|
183 |
|
|
184 |
|
|
185 |
/** |
|
186 |
* Resets the cached data so the next getter calls will request the values from R. |
|
187 |
*/ |
|
188 |
public void resetCache() { |
|
189 |
this.clusterCoords = null; |
|
190 |
this.clusterNumbers = null; |
|
191 |
this.clusterRowNames = null; |
|
192 |
this.clusterOrderedRowNames = null; |
|
193 |
this.clusterHeights = null; |
|
194 |
this.clusterMerges = null; |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* Gets the symbol. |
|
199 |
* |
|
200 |
* @return the symbol |
|
201 |
*/ |
|
202 |
public String getSymbol() |
|
203 |
{ |
|
204 |
return symbol; |
|
205 |
} |
|
206 |
|
|
207 |
/** |
|
208 |
* Gets the methods. |
|
209 |
* |
|
210 |
* @return the methods |
|
211 |
*/ |
|
212 |
public static String[] getMethods() |
|
213 |
{ |
|
214 |
String[] methods = {"average", "single", "complete", "ward", "weighted", "flexible"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ |
|
215 |
return methods; |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* Gets the metrics. |
|
220 |
* |
|
221 |
* @return the metrics |
|
222 |
*/ |
|
223 |
public static String[] getMetrics() |
|
224 |
{ |
|
225 |
String[] metrics = {"euclidean", "manhattan"}; //$NON-NLS-1$ //$NON-NLS-2$ |
|
226 |
return metrics; |
|
227 |
} |
|
228 |
|
|
229 |
/** The prefix r. */ |
|
230 |
protected static String prefixR = "FactoMineRAHC"; //$NON-NLS-1$ |
|
231 |
|
|
232 |
/** The nocah. */ |
|
233 |
protected static int nocah = 1; |
|
234 |
|
|
235 |
/** |
|
236 |
* Step compute. |
|
237 |
* |
|
238 |
* @throws RWorkspaceException the r workspace exception |
|
239 |
*/ |
|
240 |
public void stepCompute() throws RWorkspaceException |
|
241 |
{ |
|
242 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
243 |
|
|
244 |
String colOrLine = "columns"; //$NON-NLS-1$ |
|
245 |
if (!columns) |
|
246 |
colOrLine ="rows"; //$NON-NLS-1$ |
|
247 |
|
|
248 |
if(symbol == null) { |
|
249 |
symbol = prefixR+(nocah++); |
|
250 |
} |
|
251 |
|
|
252 |
rw.eval("library(FactoMineR)"); //$NON-NLS-1$ |
|
253 |
|
|
254 |
if (source instanceof LexicalTable) |
|
255 |
{ |
|
256 |
// PCA("+target+", scale.unit = FALSE, ncp = Inf, graph = FALSE) |
|
257 |
rw.eval(symbol +" <- HCPC(PCA("+target+", scale.unit = FALSE, ncp = Inf, graph = FALSE)" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
258 |
", cluster.CA=\""+colOrLine+"\"" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
259 |
", nb.clust="+NCluster + //$NON-NLS-1$ |
|
260 |
", metric=\""+metric+"\"" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
261 |
", method=\""+method+"\"" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
262 |
", graph=FALSE)"); //$NON-NLS-1$ |
|
263 |
} |
|
264 |
else |
|
265 |
{ |
|
266 |
rw.eval(symbol +" <- HCPC("+target + //$NON-NLS-1$ |
|
267 |
", cluster.CA=\""+colOrLine+"\"" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
268 |
", nb.clust="+NCluster + //$NON-NLS-1$ |
|
269 |
", metric=\""+metric+"\"" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
270 |
", method=\""+method+"\"" + //$NON-NLS-1$ //$NON-NLS-2$ |
|
271 |
", graph=FALSE)"); //$NON-NLS-1$ |
|
272 |
} |
|
273 |
|
|
274 |
// Reset the cached data |
|
275 |
this.resetCache(); |
|
276 |
} |
|
277 |
|
|
278 |
/** |
|
279 |
* |
|
280 |
* @param outfile |
|
281 |
* @param encoding |
|
282 |
* @return |
|
283 |
*/ |
|
284 |
public boolean toTxt(File outfile, String encoding) { |
|
285 |
boolean ret = true; |
|
286 |
acquireSemaphore(); |
|
287 |
RWorkspace rw; |
|
288 |
try { |
|
289 |
rw = RWorkspace.getRWorkspaceInstance(); |
|
290 |
rw.eval("sink(file=\"" + outfile.getAbsolutePath().replace("\\", "\\\\")+"\")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
291 |
rw.eval("print("+symbol+"$call)"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
292 |
rw.eval("sink()"); //$NON-NLS-1$ |
|
293 |
} catch (RWorkspaceException e) { |
|
294 |
// TODO Auto-generated catch block |
|
295 |
System.out.println(Messages.CAH_0+e); |
|
296 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
297 |
ret = false; |
|
298 |
} finally { |
|
299 |
releaseSemaphore(); |
|
300 |
} |
|
301 |
return true; |
|
302 |
} |
|
303 |
|
|
304 |
public boolean toTxt(File outfile, String encoding, String colsep, String txtsep) { |
|
305 |
return toTxt(outfile, encoding); |
|
306 |
} |
|
307 |
|
|
308 |
/** |
|
309 |
* Gets the name. |
|
310 |
* |
|
311 |
* @return the name |
|
312 |
*/ |
|
313 |
public String getName() { |
|
314 |
return name; |
|
315 |
} |
|
316 |
|
|
317 |
/** |
|
318 |
* Gets the source. |
|
319 |
* |
|
320 |
* @return the source |
|
321 |
*/ |
|
322 |
public Object getSource() { |
|
323 |
return source; |
|
324 |
} |
|
325 |
|
|
326 |
/** |
|
327 |
* Gets the partition. |
|
328 |
* |
|
329 |
* @return the partition |
|
330 |
*/ |
|
331 |
public Partition getPartition() { |
|
332 |
return partition; |
|
333 |
} |
|
334 |
|
|
335 |
/** |
|
336 |
* Gets the corpus. |
|
337 |
* @return the corpus |
|
338 |
*/ |
|
339 |
public Corpus getCorpus() { |
|
340 |
return corpus; |
|
341 |
} |
|
342 |
|
|
343 |
@Deprecated |
|
344 |
public File getSVGFile() { |
|
345 |
return svgFile; |
|
346 |
} |
|
347 |
|
|
348 |
/** |
|
349 |
* Gets the default method. |
|
350 |
* |
|
351 |
* @return the default method |
|
352 |
*/ |
|
353 |
public static String getDefaultMethod() { |
|
354 |
return "ward"; //$NON-NLS-1$ |
|
355 |
} |
|
356 |
|
|
357 |
/** |
|
358 |
* Gets the default metric. |
|
359 |
* |
|
360 |
* @return the default metric |
|
361 |
*/ |
|
362 |
public static String getDefaultMetric() { |
|
363 |
return "euclidean"; //$NON-NLS-1$ |
|
364 |
} |
|
365 |
|
|
366 |
@Override |
|
367 |
public void clean() { |
|
368 |
// TODO Auto-generated method stub |
|
369 |
|
|
370 |
} |
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
/** |
|
375 |
* Gets the clusters coordinates. |
|
376 |
* @return the clusters coordinates |
|
377 |
*/ |
|
378 |
public double[][] getClusterCoords() { |
|
379 |
if (this.clusterCoords == null) { |
|
380 |
try { |
|
381 |
|
|
382 |
// FIXME: check this code for the CAH 3D chart implementation |
|
383 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
384 |
for(int i = 0; i < 2; i++) { // 2 dimensions |
|
385 |
REXP sv = rw.extractItemFromListByName(symbol, "data.clust[,"+ (i + 1)+ "]"); //$NON-NLS-1$ |
|
386 |
double[] coords = RWorkspace.toDouble(sv); |
|
387 |
for(int j = 0; j < coords.length; j++) { |
|
388 |
if(this.clusterCoords == null) { |
|
389 |
this.clusterCoords = new double[coords.length][2]; |
|
390 |
} |
|
391 |
this.clusterCoords[j][i] = coords[j]; |
|
392 |
} |
|
393 |
} |
|
394 |
} |
|
395 |
catch (Exception e) { |
|
396 |
// TODO Auto-generated catch block |
|
397 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
398 |
} |
|
399 |
} |
|
400 |
return this.clusterCoords; |
|
401 |
} |
|
402 |
|
|
403 |
|
|
404 |
/** |
|
405 |
* Gets the clusters numbers. |
|
406 |
* @return |
|
407 |
*/ |
|
408 |
public int[] getClusterNumbers() { |
|
409 |
if (this.clusterNumbers == null) { |
|
410 |
try { |
|
411 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
412 |
// FIXME: not sorted version |
|
413 |
REXP sv = rw.extractItemFromListByName(symbol, "data$clust"); //$NON-NLS-1$ |
|
414 |
// FIXME: sorted version |
|
415 |
//REXP sv = rw.extractItemFromListByName(symbol, "data$clust[c(" + symbol + "$call$t$tree$order)]"); //$NON-NLS-1$ |
|
416 |
this.clusterNumbers = sv.asIntegers(); |
|
417 |
} |
|
418 |
catch (Exception e) { |
|
419 |
// TODO Auto-generated catch block |
|
420 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
421 |
} |
|
422 |
} |
|
423 |
return this.clusterNumbers; |
|
424 |
} |
|
425 |
|
|
426 |
/** |
|
427 |
* Gets the cluster row names. |
|
428 |
* @return |
|
429 |
*/ |
|
430 |
public String[] getClusterRowNames() { |
|
431 |
if (this.clusterRowNames == null) { |
|
432 |
try { |
|
433 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
434 |
|
|
435 |
// FIXME: old method, Save the row names in the R data frame |
|
436 |
// rw.safeEval(symbol + "$rownames <- rownames(" + symbol + "$data)"); |
|
437 |
// REXP sv = rw.extractItemFromListByName(symbol, "rownames"); //$NON-NLS-1$ |
|
438 |
|
|
439 |
|
|
440 |
REXP sv = rw.extractItemFromListByName(symbol, "call$t$tree$labels"); //$NON-NLS-1$ |
|
441 |
|
|
442 |
|
|
443 |
this.clusterRowNames = sv.asStrings(); |
|
444 |
|
|
445 |
} |
|
446 |
catch (Exception e) { |
|
447 |
// TODO Auto-generated catch block |
|
448 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
449 |
} |
|
450 |
} |
|
451 |
return this.clusterRowNames; |
|
452 |
} |
|
453 |
|
|
454 |
|
|
455 |
|
|
456 |
/** |
|
457 |
* Gets the cluster orderer row names. |
|
458 |
* @return |
|
459 |
*/ |
|
460 |
public String[] getClusterOrderedRowNames() { |
|
461 |
if (this.clusterOrderedRowNames == null) { |
|
462 |
try { |
|
463 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
464 |
REXP sv = rw.extractItemFromListByName(symbol, "call$t$tree$labels[c(" + symbol + "$call$t$tree$order)]"); //$NON-NLS-1$ |
|
465 |
this.clusterOrderedRowNames = sv.asStrings(); |
|
466 |
} |
|
467 |
catch (Exception e) { |
|
468 |
// TODO Auto-generated catch block |
|
469 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
470 |
} |
|
471 |
} |
|
472 |
return this.clusterOrderedRowNames; |
|
473 |
} |
|
474 |
|
|
475 |
|
|
476 |
/** |
|
477 |
* Gets the cluster tree heights. |
|
478 |
* @return |
|
479 |
*/ |
|
480 |
public double[] getClusterTreeHeights() { |
|
481 |
if (this.clusterHeights == null) { |
|
482 |
try { |
|
483 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
484 |
REXP sv = rw.extractItemFromListByName(symbol, "call$t$tree$height"); //$NON-NLS-1$ |
|
485 |
this.clusterHeights = sv.asDoubles(); |
|
486 |
} |
|
487 |
catch (Exception e) { |
|
488 |
// TODO Auto-generated catch block |
|
489 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
490 |
} |
|
491 |
} |
|
492 |
return this.clusterHeights; |
|
493 |
} |
|
494 |
|
|
495 |
|
|
496 |
/** |
|
497 |
* Gets the inertia gains. |
|
498 |
* @return |
|
499 |
*/ |
|
500 |
// FIXME: for test purpose, this method is not used for the chart computing |
|
501 |
public double[] getInertiaGains() { |
|
502 |
if (this.inertiaGains == null) { |
|
503 |
try { |
|
504 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
505 |
REXP sv = rw.extractItemFromListByName(symbol, "call$t$inert.gain"); //$NON-NLS-1$ |
|
506 |
// FIXME: tests |
|
507 |
// REXP sv = rw.extractItemFromListByName(symbol, "call$t$within"); //$NON-NLS-1$ |
|
508 |
|
|
509 |
this.inertiaGains = sv.asDoubles(); |
|
510 |
} |
|
511 |
catch (Exception e) { |
|
512 |
// TODO Auto-generated catch block |
|
513 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
514 |
} |
|
515 |
} |
|
516 |
return this.inertiaGains; |
|
517 |
} |
|
518 |
|
|
519 |
|
|
520 |
/** |
|
521 |
* Gets the cluster tree merges. |
|
522 |
* @return |
|
523 |
*/ |
|
524 |
public double[][] getClusterTreeMerges() { |
|
525 |
if (this.clusterMerges == null) { |
|
526 |
try { |
|
527 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
528 |
REXP sv = rw.extractItemFromListByName(symbol, "call$t$tree$merge"); //$NON-NLS-1$ |
|
529 |
this.clusterMerges = sv.asDoubleMatrix(); |
|
530 |
} |
|
531 |
catch (Exception e) { |
|
532 |
// TODO Auto-generated catch block |
|
533 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
534 |
} |
|
535 |
} |
|
536 |
return this.clusterMerges; |
|
537 |
} |
|
538 |
|
|
539 |
|
|
540 |
|
|
541 |
|
|
542 |
|
|
543 |
|
|
544 |
/** |
|
545 |
* Sets the metric to use for computing. |
|
546 |
* @param metric the metric to set |
|
547 |
*/ |
|
548 |
public void setMetric(String metric) { |
|
549 |
this.metric = metric; |
|
550 |
} |
|
551 |
|
|
552 |
/** |
|
553 |
* Sets the method to use for computing |
|
554 |
* @param method the method to set |
|
555 |
*/ |
|
556 |
public void setMethod(String method) { |
|
557 |
this.method = method; |
|
558 |
} |
|
559 |
|
|
560 |
/** |
|
561 |
* Sets the computing to columns or rows. |
|
562 |
* @param columns the columns to set |
|
563 |
*/ |
|
564 |
public void setColumnsComputing(boolean columns) { |
|
565 |
this.columns = columns; |
|
566 |
} |
|
567 |
|
|
568 |
/** |
|
569 |
* Sets the number of clusters to use for computing |
|
570 |
* @param nCluster the nCluster to set |
|
571 |
*/ |
|
572 |
public void setNCluster(int nCluster) { |
|
573 |
NCluster = nCluster; |
|
574 |
} |
|
575 |
|
|
576 |
/** |
|
577 |
* Checks if the computing mode is set as columns. If not, the computing mode is set as rows. |
|
578 |
* @return the columns |
|
579 |
*/ |
|
580 |
public boolean isColumnsComputing() { |
|
581 |
return columns; |
|
582 |
} |
|
583 |
|
|
584 |
/** |
|
585 |
* Gets the maximum clusters available according to the current computing mode (columns or rows) and according to current source (<code>CA</code> or <code>LexicalTable</code>). |
|
586 |
* The maximum numbers of available clusters is for now limited to 16 by this method due of a limitation of FactoMineR plot.HCPC(). |
|
587 |
* @return the maximum clusters available according to the current computing mode |
|
588 |
*/ |
|
589 |
public int getMaxClustersCount() { |
|
590 |
|
|
591 |
int maxClustersCount = -1; |
|
592 |
|
|
593 |
try { |
|
594 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
595 |
REXP sv = rw.eval("min(length(" + symbol + "$data$clust) - 1, 16)"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
596 |
maxClustersCount = sv.asInteger(); |
|
597 |
} |
|
598 |
|
|
599 |
catch(RWorkspaceException e) { |
|
600 |
// TODO Auto-generated catch block |
|
601 |
e.printStackTrace(); |
|
602 |
} |
|
603 |
catch(REXPMismatchException e) { |
|
604 |
// TODO Auto-generated catch block |
|
605 |
e.printStackTrace(); |
|
606 |
} |
|
607 |
|
|
608 |
|
|
609 |
// FIXME: FactoMineR plot.HCPC doesn't manage more than 16 clusters when tree.barplot=TRUE, therefore we can't plot a SVG with more than that, see ticket #836 then use the code below in ChartsEngine to compute |
|
610 |
// the real maximum available clusters count |
|
611 |
// // CA |
|
612 |
// if(this.source instanceof CA) { |
|
613 |
// if(this.columns == true) { |
|
614 |
// maxClustersCount = ((CA)this.source).getColumnsCount() - 1; |
|
615 |
// } |
|
616 |
// else { |
|
617 |
// maxClustersCount = ((CA)this.source).getRowsCount() - 1; |
|
618 |
// } |
|
619 |
// } |
|
620 |
// // Lexical table |
|
621 |
// else if(this.source instanceof LexicalTable) { |
|
622 |
// if(this.columns == true) { |
|
623 |
// maxClustersCount = ((LexicalTable)this.source).getColumnsCount() - 1; |
|
624 |
// } |
|
625 |
// else { |
|
626 |
// maxClustersCount = ((LexicalTable)this.source).getRowsCount() - 1; |
|
627 |
// } |
|
628 |
// } |
|
629 |
|
|
630 |
return maxClustersCount; |
|
631 |
} |
|
632 |
|
|
633 |
/** |
|
634 |
* @return the display2D |
|
635 |
*/ |
|
636 |
public boolean isDisplay2D() { |
|
637 |
return display2D; |
|
638 |
} |
|
639 |
|
|
640 |
@Override |
|
641 |
public boolean delete() { |
|
642 |
return getParent().removeResult(this); |
|
643 |
} |
|
644 |
|
|
645 |
@Override |
|
646 |
public String[] getExportTXTExtensions() { |
|
647 |
return new String[]{"*.txt"}; |
|
648 |
} |
|
649 |
|
|
650 |
@Override |
|
651 |
public HasResults getParent() { |
|
652 |
if (ca != null) |
|
653 |
return ca; |
|
654 |
return table; |
|
655 |
} |
|
656 |
|
|
657 |
/** |
|
658 |
* Returns the number of clusters. |
|
659 |
* @return the nCluster |
|
660 |
*/ |
|
661 |
public int getNCluster() { |
|
662 |
return NCluster; |
|
663 |
} |
|
664 |
|
|
665 |
public CA getCA() { |
|
666 |
return ca; |
|
667 |
} |
|
668 |
|
|
669 |
public LexicalTable getLexicalTable() { |
|
670 |
return table; |
|
671 |
} |
|
672 |
} |
|
0 | 673 |
tmp/org.txm.cah.core/build.properties (revision 133) | ||
---|---|---|
1 |
source.. = src/ |
|
2 |
output.. = bin/ |
|
3 |
bin.includes = META-INF/,\ |
|
4 |
. |
|
0 | 5 |
tmp/org.txm.cah.rcp/.settings/org.eclipse.jdt.core.prefs (revision 133) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 |
|
4 |
org.eclipse.jdt.core.compiler.compliance=1.6 |
|
5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
6 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
7 |
org.eclipse.jdt.core.compiler.source=1.6 |
|
0 | 8 |
tmp/org.txm.cah.rcp/.classpath (revision 133) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
|
5 |
<classpathentry kind="src" path="src"/> |
|
6 |
<classpathentry kind="output" path="bin"/> |
|
7 |
</classpath> |
|
0 | 8 |
tmp/org.txm.cah.rcp/META-INF/MANIFEST.MF (revision 133) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: CAH RCP |
|
4 |
Bundle-SymbolicName: org.txm.cah.rcp |
|
5 |
Bundle-Version: 1.0.0.qualifier |
|
6 |
Bundle-Activator: org.txm.cah.rcp.Activator |
|
7 |
Require-Bundle: org.txm.chartsengine.rcp;bundle-version="1.0.0", |
|
8 |
org.eclipse.ui, |
|
9 |
org.eclipse.core.runtime, |
|
10 |
org.txm.cah.core;bundle-version="1.0.0", |
|
11 |
org.txm.chartsengine.core;bundle-version="1.0.0", |
|
12 |
org.txm.chartsengine.jfreechart.core;bundle-version="1.0.0", |
|
13 |
org.txm.chartsengine.r.core;bundle-version="1.0.0", |
|
14 |
org.txm.core;bundle-version="0.7.0", |
|
15 |
org.txm.rcp;bundle-version="0.7.8", |
|
16 |
org.txm.chartsengine.jfreechart.rcp;bundle-version="1.0.0", |
|
17 |
org.txm.chartsengine.r.rcp;bundle-version="1.0.0", |
|
18 |
org.txm.chartsengine.raster.rcp;bundle-version="1.0.0", |
|
19 |
org.txm.chartsengine.svgbatik.rcp;bundle-version="1.0.0" |
|
20 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 |
|
21 |
Bundle-ActivationPolicy: lazy |
|
22 |
Export-Package: org.txm.cah.rcp.chartsengine.jfreechart.events, |
|
23 |
org.txm.cah.rcp.editors |
|
0 | 24 |
tmp/org.txm.cah.rcp/.project (revision 133) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.cah.rcp</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
<buildCommand> |
|
14 |
<name>org.eclipse.pde.ManifestBuilder</name> |
|
15 |
<arguments> |
|
16 |
</arguments> |
|
17 |
</buildCommand> |
|
18 |
<buildCommand> |
|
19 |
<name>org.eclipse.pde.SchemaBuilder</name> |
|
20 |
<arguments> |
|
21 |
</arguments> |
|
22 |
</buildCommand> |
|
23 |
</buildSpec> |
|
24 |
<natures> |
|
25 |
<nature>org.eclipse.pde.PluginNature</nature> |
|
26 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
27 |
</natures> |
|
28 |
</projectDescription> |
|
0 | 29 |
tmp/org.txm.cah.rcp/src/org/txm/cah/rcp/chartsengine/jfreechart/events/CAHSelectionListener.java (revision 133) | ||
---|---|---|
1 |
package org.txm.cah.rcp.chartsengine.jfreechart.events; |
|
2 |
|
|
3 |
import org.eclipse.swt.events.SelectionEvent; |
|
4 |
import org.eclipse.swt.widgets.Spinner; |
|
5 |
import org.eclipse.swt.widgets.ToolItem; |
|
6 |
import org.txm.cah.functions.CAH; |
|
7 |
import org.txm.cah.rcp.commands.ComputeCAH; |
|
8 |
import org.txm.cah.rcp.editors.CAHChartEditor; |
|
9 |
import org.txm.chartsengine.rcp.editors.ChartEditorPart; |
|
10 |
import org.txm.chartsengine.rcp.events.BaseSelectionListener; |
|
11 |
import org.txm.rcpapplication.TxmPreferences; |
|
12 |
import org.txm.rcpapplication.preferences.CAHPreferencePage; |
|
13 |
import org.txm.stat.engine.r.RWorkspaceException; |
|
14 |
|
|
15 |
/** |
|
16 |
* CAH listener. |
|
17 |
* @author sjacquot |
|
18 |
* |
|
19 |
*/ |
|
20 |
public class CAHSelectionListener extends BaseSelectionListener { |
|
21 |
|
|
22 |
|
|
23 |
/** |
|
24 |
* Command constants. |
|
25 |
*/ |
|
26 |
public final static int NUMBERS_OF_CLUSTERS = 0, COMPUTE_COLUMNS = 1; |
|
27 |
|
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
* @param chartEditor |
|
32 |
* @param commandId |
|
33 |
*/ |
|
34 |
public CAHSelectionListener(ChartEditorPart chartEditor, int commandId) { |
|
35 |
super(chartEditor, commandId); |
|
36 |
} |
|
37 |
|
|
38 |
|
|
39 |
@Override |
|
40 |
public void widgetSelected(SelectionEvent e) { |
|
41 |
|
|
42 |
try { |
|
43 |
CAH cah = ((CAHChartEditor) chartEditor).getResultData(); |
|
44 |
|
|
45 |
// Numbers of clusters |
|
46 |
if(this.commandId == CAHSelectionListener.NUMBERS_OF_CLUSTERS) { |
|
47 |
cah.setNCluster(((Spinner)e.getSource()).getSelection()); |
|
48 |
} |
|
49 |
// Compute columns or rows |
|
50 |
else if(this.commandId == CAHSelectionListener.COMPUTE_COLUMNS) { |
|
51 |
cah.setColumnsComputing(((ToolItem)e.getSource()).getSelection()); |
|
52 |
cah.setNCluster(TxmPreferences.getInt(CAHPreferencePage.NCLUSTER)); |
|
53 |
((CAHChartEditor) chartEditor).updateNumbersOfClustersCurrentValue(); |
|
54 |
} |
|
55 |
|
|
56 |
// Update the maximum value of the number of clusters spinner according to the new CAH configuration |
|
57 |
((CAHChartEditor) chartEditor).updateNumbersOfClustersMaxValue(); |
|
58 |
|
|
59 |
// Recompute the CAH |
|
60 |
ComputeCAH.compute(cah, chartEditor); |
|
61 |
|
|
62 |
} |
|
63 |
catch(RWorkspaceException e1) { |
|
64 |
// TODO Auto-generated catch block |
|
65 |
e1.printStackTrace(); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
|
|
70 |
} |
|
0 | 71 |
tmp/org.txm.cah.rcp/src/org/txm/cah/rcp/Activator.java (revision 133) | ||
---|---|---|
1 |
package org.txm.cah.rcp; |
|
2 |
|
|
3 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
4 |
import org.osgi.framework.BundleContext; |
|
5 |
|
|
6 |
/** |
|
7 |
* The activator class controls the plug-in life cycle |
|
8 |
*/ |
|
9 |
public class Activator extends AbstractUIPlugin { |
|
10 |
|
|
11 |
// The plug-in ID |
|
12 |
public static final String PLUGIN_ID = "org.txm.cah.rcp"; //$NON-NLS-1$ |
|
13 |
|
|
14 |
// The shared instance |
|
15 |
private static Activator plugin; |
|
16 |
|
|
17 |
/** |
|
18 |
* The constructor |
|
19 |
*/ |
|
20 |
public Activator() { |
|
21 |
} |
|
22 |
|
|
23 |
/* |
|
24 |
* (non-Javadoc) |
|
25 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
|
26 |
*/ |
|
27 |
public void start(BundleContext context) throws Exception { |
|
28 |
super.start(context); |
|
29 |
plugin = this; |
|
30 |
} |
|
31 |
|
|
32 |
/* |
|
33 |
* (non-Javadoc) |
|
34 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
|
35 |
*/ |
|
36 |
public void stop(BundleContext context) throws Exception { |
|
37 |
plugin = null; |
|
38 |
super.stop(context); |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* Returns the shared instance |
|
43 |
* |
|
44 |
* @return the shared instance |
|
45 |
*/ |
|
46 |
public static Activator getDefault() { |
|
47 |
return plugin; |
|
48 |
} |
|
49 |
|
|
50 |
} |
|
0 | 51 |
tmp/org.txm.cah.rcp/src/org/txm/cah/rcp/commands/ComputeCAH.java (revision 133) | ||
---|---|---|
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:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.cah.rcp.commands; |
|
29 |
|
|
30 |
import org.eclipse.core.commands.AbstractHandler; |
|
31 |
import org.eclipse.core.commands.ExecutionEvent; |
|
32 |
import org.eclipse.core.commands.ExecutionException; |
|
33 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
34 |
import org.eclipse.core.runtime.IStatus; |
|
35 |
import org.eclipse.core.runtime.Status; |
|
36 |
import org.eclipse.jface.dialogs.Dialog; |
|
37 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
38 |
import org.eclipse.jface.window.Window; |
|
39 |
import org.eclipse.swt.SWT; |
|
40 |
import org.eclipse.swt.layout.GridLayout; |
|
41 |
import org.eclipse.swt.widgets.Button; |
|
42 |
import org.eclipse.swt.widgets.Composite; |
|
43 |
import org.eclipse.swt.widgets.Control; |
|
44 |
import org.eclipse.swt.widgets.Display; |
|
45 |
import org.eclipse.swt.widgets.Label; |
|
46 |
import org.eclipse.swt.widgets.Shell; |
|
47 |
import org.eclipse.swt.widgets.Spinner; |
|
48 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
49 |
import org.txm.Toolbox; |
|
50 |
import org.txm.chartsengine.core.ChartsEngine; |
|
51 |
import org.txm.chartsengine.r.core.RChartsEngine; |
|
52 |
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider; |
|
53 |
import org.txm.chartsengine.rcp.editors.ChartEditorPart; |
|
54 |
import org.txm.chartsengine.svgbatik.rcp.SVGSWTChartsComponentsProvider; |
|
55 |
import org.txm.functions.ca.CA; |
|
56 |
import org.txm.cah.functions.CAH; |
|
57 |
import org.txm.cah.rcp.editors.CAHChartEditor; |
|
58 |
import org.txm.rcpapplication.IImageKeys; |
|
59 |
import org.txm.rcpapplication.JobsTimer; |
|
60 |
import org.txm.rcpapplication.Messages; |
|
61 |
import org.txm.rcpapplication.TxmPreferences; |
|
62 |
import org.txm.rcpapplication.actions.LexicalTableDialog; |
|
63 |
import org.txm.rcpapplication.preferences.CAHPreferencePage; |
|
64 |
import org.txm.rcpapplication.preferences.CAPreferencePage; |
|
65 |
import org.txm.rcpapplication.utils.JobHandler; |
|
66 |
import org.txm.rcpapplication.views.CorporaView; |
|
67 |
import org.txm.rcpapplication.views.QueriesView; |
|
68 |
import org.txm.rcpapplication.views.RVariablesView; |
|
69 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
70 |
import org.txm.searchengine.cqp.corpus.Property; |
|
71 |
import org.txm.stat.StatException; |
|
72 |
import org.txm.stat.data.LexicalTable; |
|
73 |
import org.txm.stat.engine.r.RWorkspaceException; |
|
74 |
import org.txm.utils.logger.Log; |
|
75 |
|
|
76 |
/** |
|
77 |
* If the selection is a CA or a Lexical Table result computes the CAH. |
|
78 |
* |
|
79 |
* @author mdecorde, sjacquot. |
|
80 |
*/ |
|
81 |
public class ComputeCAH extends AbstractHandler { |
|
82 |
|
|
83 |
|
|
84 |
/** |
|
85 |
* The command ID. |
|
86 |
*/ |
|
87 |
public static final String ID = ComputeCAH.class.getCanonicalName(); |
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
/* (non-Javadoc) |
|
92 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
93 |
*/ |
|
94 |
@Override |
|
95 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
96 |
|
|
97 |
|
|
98 |
if (!Toolbox.isStatEngineInitialized()) { |
|
99 |
System.out.println(Messages.ComputeCAH_4); |
|
100 |
return null; |
|
101 |
} |
|
102 |
|
|
103 |
CAH cah = null; |
|
104 |
CA ca = null; |
|
105 |
LexicalTable lexicaltable = null; |
|
106 |
Partition partition = null; |
|
107 |
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); |
|
108 |
|
|
109 |
|
|
110 |
// Build the CA or not depending on the selection |
|
111 |
if (selection.getFirstElement() instanceof CAH) { |
|
112 |
cah = (CAH) selection.getFirstElement(); |
|
113 |
} else if (selection.getFirstElement() instanceof CA) { |
|
114 |
//System.out.println("Compute CAH with CA : "+((CA)selection.getFirstElement()).getName()); |
|
115 |
ca = (CA) selection.getFirstElement(); |
|
116 |
} else if (selection.getFirstElement() instanceof LexicalTable) { |
|
117 |
//System.out.println("Compute CAH with LT : "+((LexicalTable)selection.getFirstElement()).getName()); |
|
118 |
lexicaltable = (LexicalTable) selection.getFirstElement(); |
|
119 |
|
|
120 |
try { |
|
121 |
ca = new CA(lexicaltable); |
|
122 |
} catch (StatException e) { |
|
123 |
System.out.println("Failed to build the CA with lexical table "+lexicaltable+": "+e); |
|
124 |
Log.printStackTrace(e); |
|
125 |
} |
|
126 |
lexicaltable.storeResult(ca); |
|
127 |
|
|
128 |
// if (lexicaltable.getPartition() != null) |
|
129 |
// lexicaltable.getPartition().storeResult(ca); |
|
130 |
// else if (lexicaltable.getCorpus() != null) |
|
131 |
// lexicaltable.getCorpus().storeResult(ca); |
|
132 |
} else if (selection.getFirstElement() instanceof Partition) { |
|
133 |
//System.out.println("Compute CAH with Partition : "+((Partition)selection.getFirstElement()).getName()); |
|
134 |
partition = (Partition)selection.getFirstElement(); |
|
135 |
try { |
|
136 |
String title = Messages.bind(Messages.ComputeCAH_0, partition.getName()); |
|
137 |
int vmax = TxmPreferences.getInt(CAPreferencePage.VMAX, 200); |
|
138 |
int fmin = TxmPreferences.getInt(CAPreferencePage.FMIN, 10); |
|
139 |
Shell shell = Display.getCurrent().getActiveShell(); |
|
140 |
LexicalTableDialog d = new LexicalTableDialog(shell, partition |
|
141 |
.getCorpus(), title); |
|
142 |
d.setFminAndVMax(fmin, vmax); |
|
143 |
|
|
144 |
if (d.open() == Window.OK) { |
|
145 |
Property property = d.getProperty(); |
|
146 |
fmin = d.getFmin(); |
|
147 |
vmax = d.getMaxLines(); |
|
148 |
|
|
149 |
lexicaltable = partition.getLexicalTable(property, fmin); // use the CAPreferencePage Fmin |
|
150 |
lexicaltable.cut(vmax); |
|
151 |
partition.storeResult(lexicaltable); |
|
152 |
|
|
153 |
ca = new CA(lexicaltable); |
|
154 |
lexicaltable.storeResult(ca); |
|
155 |
} else { |
|
156 |
// canceled |
|
157 |
return null; |
|
158 |
} |
|
159 |
} catch (Exception e) { |
|
160 |
System.out.println("Failed to build the lexical table of "+partition+": "+e); |
|
161 |
Log.printStackTrace(e); |
|
162 |
return null; |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
final int ncluster = TxmPreferences.getInt(CAHPreferencePage.NCLUSTER, 2); |
|
167 |
final String metric = TxmPreferences.getString(CAHPreferencePage.METRIC, CAH.getDefaultMetric()); |
|
168 |
final String method = TxmPreferences.getString(CAHPreferencePage.METHOD, CAH.getDefaultMethod()); |
|
169 |
final Boolean display2D = "2D".equals(TxmPreferences.getString(CAHPreferencePage.DISPLAY, "3D")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
170 |
final boolean computeColumns = true; |
|
171 |
|
|
172 |
// Use existent CAH (used when reopening an editor from a CAH result node) |
|
173 |
if (cah != null) { |
|
174 |
if (cah.getParent() != null) { |
|
175 |
cah.getParent().removeResult(cah); |
|
176 |
} |
|
177 |
} else { |
|
178 |
// if (ca == null) cah = new CAH(lexicaltable, computeColumns, method, metric, ncluster, display2D); |
|
179 |
// else |
|
180 |
cah = new CAH(ca, computeColumns, method, metric, ncluster, display2D); |
|
181 |
} |
|
182 |
|
|
183 |
try { |
|
184 |
compute(cah, null); |
|
185 |
} |
|
186 |
catch(RWorkspaceException e) { |
|
187 |
System.out.println("Failed to compute CAH: "+e); |
|
188 |
Log.printStackTrace(e); |
|
189 |
} |
|
190 |
|
|
191 |
return null; |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Computes the CAH. Also creates the chart. Opens a chart editor if <code>chartEditor</code> is null otherwise refreshes the existing chart editor. |
|
196 |
* @param newResult |
|
197 |
* @throws RWorkspaceException |
|
198 |
*/ |
|
199 |
public static void compute(final CAH cah, final ChartEditorPart chartEditor) throws RWorkspaceException { |
|
200 |
|
|
201 |
JobHandler jobhandler = new JobHandler(Messages.CAHEditor_0) { |
|
202 |
@Override |
|
203 |
protected IStatus run(IProgressMonitor monitor) { |
|
204 |
this.runInit(monitor); |
|
205 |
try { |
|
206 |
|
|
207 |
this.acquireSemaphore(); |
|
208 |
cah.stepCompute(); |
|
209 |
this.releaseSemaphore(); |
|
210 |
|
|
211 |
// Store result |
|
212 |
if(chartEditor == null) { |
|
213 |
// if (cah.getPartition() != null) { |
|
214 |
// cah.getPartition().storeResult(cah); |
|
215 |
// } |
|
216 |
// else if (cah.getCorpus() != null) { |
|
217 |
// cah.getCorpus().storeResult(cah); |
|
218 |
// } |
|
219 |
cah.getCA().storeResult(cah); |
|
220 |
} |
|
221 |
|
|
222 |
// Refresh views |
|
223 |
this.syncExec(new Runnable() { |
|
224 |
@Override |
|
225 |
public void run() { |
|
226 |
|
|
227 |
System.err.println("ComputeCAH.compute(): charts creator is not yet implemented."); |
|
228 |
|
|
229 |
// Create a new chart editor |
|
230 |
// FIXME: version to restore when the JFC CAH charts will be implemented |
|
231 |
// if(chartEditor == null) { |
|
232 |
// ChartEditorPart chartEditor = Application.swtComponentProvider.createCAHChartEditorPart(IImageKeys.getImage(IImageKeys.ACTION_CAH), cah); |
|
233 |
// // Create and open the chart editor |
|
234 |
// SWTChartsComponentProvider.openEditor(chartEditor); |
|
235 |
// } |
|
236 |
// // Refresh the existing chart editor |
|
237 |
// else { |
|
238 |
// // Create and load the new chart |
|
239 |
// chartEditor.getComposite().loadChart(Toolbox.getChartsEngine().createCAHChart(((CAHChartEditor) chartEditor).getResultData(), ((CAHChartEditor) chartEditor).getResultData().isDisplay2D())); |
|
240 |
// chartEditor.forceFocus(); |
|
241 |
// } |
|
242 |
|
|
243 |
// FIXME: temporary force R/SVG version because the CAH charts are not yet implemented in JFC mode |
|
244 |
RChartsEngine tmpChartsEngine = new RChartsEngine(ChartsEngine.OUTPUT_FORMAT_SVG); |
|
245 |
if(chartEditor == null) { |
|
246 |
SVGSWTChartsComponentsProvider tmpSWTComponentsProvider = (SVGSWTChartsComponentsProvider) SWTChartsComponentsProvider.getComponentsProvider(tmpChartsEngine); |
|
247 |
// FIXME: charts creator is not yet implemented |
|
248 |
//ChartEditorPart chartEditor = tmpSWTComponentsProvider.createCAHChartEditorPart(IImageKeys.getImage(IImageKeys.ACTION_CAH), cah); |
|
249 |
// Create and open the chart editor |
|
250 |
tmpSWTComponentsProvider.openEditor(chartEditor); |
|
251 |
} |
|
252 |
// Refresh the existing chart editor |
|
253 |
else { |
|
254 |
// FIXME: charts creator is not yet implemented |
|
255 |
// Create and load the new chart |
|
256 |
//chartEditor.getComposite().loadChart(tmpChartsEngine.createCAHChart(((CAHChartEditor) chartEditor).getResultData(), ((CAHChartEditor) chartEditor).getResultData().isDisplay2D())); |
|
257 |
chartEditor.forceFocus(); |
|
258 |
} |
|
259 |
|
|
260 |
|
|
261 |
// Refresh UI |
|
262 |
CorporaView.refresh(); |
|
263 |
CorporaView.expand(cah.getParent()); |
|
264 |
QueriesView.refresh(); |
|
265 |
RVariablesView.refresh(); |
|
266 |
} |
|
267 |
}); |
|
268 |
|
|
269 |
|
|
270 |
} |
|
271 |
catch (ThreadDeath td) { |
|
272 |
return Status.CANCEL_STATUS; |
|
273 |
} |
|
274 |
catch (Exception e) { |
|
275 |
System.out.println(e.getLocalizedMessage()); |
|
276 |
org.txm.rcpapplication.utils.Logger.printStackTrace(e); |
|
277 |
Log.severe("Error while computing CAH: "+e.getLocalizedMessage()); |
|
278 |
} |
|
279 |
finally { |
|
280 |
monitor.done(); |
|
281 |
JobsTimer.stopAndPrint(); |
|
282 |
} |
|
283 |
return Status.OK_STATUS; |
|
284 |
} |
|
285 |
}; |
|
286 |
jobhandler.startJob(); |
|
287 |
|
|
288 |
} |
|
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
// FIXME: to remove when charts engine will be validated, be careful this method contains some old code to open a dialog bog, do we need to keep it ? |
|
298 |
// public Object execute1(ExecutionEvent event) throws ExecutionException { |
|
299 |
// |
|
300 |
// if (!Toolbox.isStatEngineInitialized()) { |
|
301 |
// System.out.println("StatEngine is not ready. Canceling command."); |
|
302 |
// return null; |
|
303 |
// } |
|
304 |
// |
|
305 |
// HandlerUtil.getActiveWorkbenchWindow(event); |
|
306 |
// IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event); |
|
307 |
// |
|
308 |
// if (selection.getFirstElement() instanceof CA) { |
|
309 |
// //System.out.println("Compute CAH with CA : "+((CA)selection.getFirstElement()).getName()); |
|
310 |
// ca = (CA) selection.getFirstElement(); |
|
311 |
// } else if (selection.getFirstElement() instanceof LexicalTable) { |
|
312 |
// //System.out.println("Compute CAH with LT : "+((LexicalTable)selection.getFirstElement()).getName()); |
|
313 |
// lexicaltable = (LexicalTable) selection.getFirstElement(); |
|
314 |
// } |
|
315 |
// |
|
316 |
// openEditor1(ca, lexicaltable); |
|
317 |
// |
|
318 |
//// //Open CAH parameters dialog |
|
319 |
//// CAHParamDialog d = new CAHParamDialog(window.getShell()); |
|
320 |
//// |
|
321 |
//// if (d.open() == Window.OK) { |
|
322 |
//// final int ncluster = d.getNcluster(); |
|
323 |
//// final String metric = TxmPreferences.getString(CAHPreferencePage.METRIC, CAH.getDefaultMetric()); |
|
324 |
//// final String method = TxmPreferences.getString(CAHPreferencePage.METHOD, CAH.getDefaultMethod()); |
|
325 |
//// final Boolean displayMode = TxmPreferences.getBoolean(CAHPreferencePage.DISPLAY, false); |
|
326 |
//// final boolean docol = d.isDoculumns(); |
|
327 |
//// |
|
328 |
//// JobHandler jobhandler = new JobHandler(Messages.ComputeCAH_3+ca.getName()) { |
|
329 |
//// @Override |
|
330 |
//// protected IStatus run(IProgressMonitor monitor) { |
|
331 |
//// try { |
|
332 |
//// JobsTimer.start(); |
|
333 |
//// monitor.beginTask("", 100); //$NON-NLS-1$ |
|
334 |
//// |
|
335 |
//// monitor.subTask(Messages.ComputeCAH_0); |
|
336 |
//// |
|
337 |
//// final CAH cah; |
|
338 |
//// if (ca != null) { |
|
339 |
//// cah = new CAH(ca, docol, method, metric, ncluster, displayMode); |
|
340 |
//// cah.stepCompute(); |
|
341 |
//// ca.getPartition().storeResult(cah); |
|
342 |
//// } else { |
|
343 |
//// cah = new CAH(lexicaltable, docol, method, metric, ncluster, displayMode); |
|
344 |
//// cah.stepCompute(); |
|
345 |
//// lexicaltable.getPartition().storeResult(cah); |
|
346 |
//// } |
|
347 |
//// if (monitor.isCanceled()) |
|
348 |
//// return Status.CANCEL_STATUS; |
|
349 |
//// |
|
350 |
//// monitor.worked(20); |
|
351 |
//// |
|
352 |
//// monitor.subTask(Messages.ComputeCAH_1); |
|
353 |
//// |
|
354 |
//// syncExec(new Runnable() { |
|
355 |
//// @Override |
|
356 |
//// public void run() { |
|
357 |
//// |
|
358 |
//// RDevice device = RDevice.valueOf(TxmPreferences.getString(ExportPreferencePage.RDEVICE, RDevice.SVG.toString())); |
|
359 |
//// String txmhome = Toolbox.getParam(Toolbox.USER_TXM_HOME); |
|
360 |
//// File resultDir = new File(txmhome, "results"); //$NON-NLS-1$ |
|
361 |
//// resultDir.mkdirs(); |
|
362 |
//// File outfile; |
|
363 |
//// try { |
|
364 |
//// outfile = File.createTempFile("cah", device.getExt(), resultDir); //$NON-NLS-1$ |
|
365 |
//// if (!outfile.canWrite()) { |
|
366 |
//// System.out.println(NLS.bind(Messages.ComputeCAH_2, outfile)); |
|
367 |
//// } |
Formats disponibles : Unified diff