Revision 25
tmp/org.txm.wordcloud.core/.project (revision 25) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.wordcloud.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.wordcloud.core/src/org/txm/wordcloud/core/messages/messages.properties (revision 25) | ||
---|---|---|
1 |
ComputeWordCloud_3=The {0} R package was not installed. Reason: {1}. |
|
2 |
ComputeWordCloud_7=Operation canceled by user. |
|
3 |
Log_Aborting=Aborting WordCloud. |
|
4 |
Log_Could_not_install_R_package=Could not install the {0} package. |
|
5 |
Log_Installing_R_package=Installing {0} R package... |
|
6 |
Log_Loading_R_package=Loading package: |
|
7 |
Log_R_Packages_installation_failed=The necessary R packages have not been installed properly, it is not possible to complete the installation of the WordCloud command.\nSee instructions at https://groupes.renater.fr/wiki/txm-users/public/extensions#wordcloud |
|
8 |
Log_R_Packages_loaded=R packages loaded. Now running WordCloud. |
|
9 |
Log_Stats_Engine_not_ready=StatEngine is not ready. Canceling command. |
|
10 |
StatusBar_Opening_result=Opening WordCloud results. |
|
11 |
WordCloudTitle=WordCloud |
|
0 | 12 |
tmp/org.txm.wordcloud.core/src/org/txm/wordcloud/core/messages/TBXWordCloudMessages.java (revision 25) | ||
---|---|---|
1 |
package org.txm.wordcloud.core.messages; |
|
2 |
|
|
3 |
import org.eclipse.osgi.util.NLS; |
|
4 |
|
|
5 |
public class TBXWordCloudMessages extends NLS { |
|
6 |
|
|
7 |
private static final String BUNDLE_NAME = "org.txm.wordcloud.core.messages.messages"; //$NON-NLS-1$ |
|
8 |
|
|
9 |
public static String ComputeWordCloud_3; |
|
10 |
public static String ComputeWordCloud_7; |
|
11 |
public static String Log_Aborting; |
|
12 |
public static String Log_Could_not_install_R_package; |
|
13 |
public static String Log_Installing_R_package; |
|
14 |
public static String Log_Loading_R_package; |
|
15 |
public static String Log_R_Packages_installation_failed; |
|
16 |
public static String Log_R_Packages_loaded; |
|
17 |
public static String Log_Stats_Engine_not_ready; |
|
18 |
public static String StatusBar_Opening_result; |
|
19 |
public static String WordCloudTitle; |
|
20 |
|
|
21 |
static { |
|
22 |
// initialize resource bundle |
|
23 |
NLS.initializeMessages(BUNDLE_NAME, TBXWordCloudMessages.class); |
|
24 |
} |
|
25 |
|
|
26 |
private TBXWordCloudMessages() { |
|
27 |
} |
|
28 |
} |
|
0 | 29 |
tmp/org.txm.wordcloud.core/src/org/txm/wordcloud/core/messages/messages_fr.properties (revision 25) | ||
---|---|---|
1 |
ComputeWordCloud_6=Echec de l'installation du package {0}. |
|
2 |
ComputeWordCloud_7=Annulation par l'utilisateur. |
|
3 |
Log_Aborting=Abandon du calcul. |
|
4 |
Log_Could_not_install_R_package=Le package R {0} n'a pas pu ?tre install?. Raison : {1}. |
|
5 |
Log_Installing_R_package=Installation du package R {0}... |
|
6 |
Log_Loading_R_package=Chargement du package : |
|
7 |
Log_R_Packages_installation_failed=Les packages n?c?ssaires au fonctionnement de la fonctionnalit? n'ont pas pu ?tre install?s. Voir les instructions pour installation manuelle ? l'adresse https://groupes.renater.fr/wiki/txm-users/public/extensions#wordcloud |
|
8 |
Log_R_Packages_loaded=Les packages R ont ?t? charg?s. Lancement du calcul. |
|
9 |
Log_Stats_Engine_not_ready=Le moteur de statistique n'est pas pr?t. Abandon. |
|
10 |
StatusBar_Opening_result=Ouverture du r?sultat. |
|
11 |
WordCloudTitle=Nuage de mots |
|
0 | 12 |
tmp/org.txm.wordcloud.core/src/org/txm/wordcloud/core/functions/WordCloud.java (revision 25) | ||
---|---|---|
1 |
package org.txm.wordcloud.core.functions; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
import org.txm.HasResults; |
|
9 |
import org.txm.functions.Function; |
|
10 |
import org.txm.functions.TXMResult; |
|
11 |
import org.txm.functions.index.Index; |
|
12 |
import org.txm.functions.index.Line; |
|
13 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
14 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
15 |
import org.txm.searchengine.cqp.corpus.Lexicon; |
|
16 |
import org.txm.searchengine.cqp.corpus.Property; |
|
17 |
import org.txm.searchengine.cqp.corpus.query.Query; |
|
18 |
import org.txm.searchengine.cqp.serverException.CqiServerError; |
|
19 |
import org.txm.stat.engine.r.RWorkspace; |
|
20 |
import org.txm.stat.engine.r.RWorkspaceException; |
|
21 |
import org.txm.tbx.preferences.TXMPreferences; |
|
22 |
import org.txm.utils.logger.Log; |
|
23 |
import org.txm.wordcloud.core.messages.TBXWordCloudMessages; |
|
24 |
import org.txm.wordcloud.core.preferences.WordCloudPreferences; |
|
25 |
|
|
26 |
public class WordCloud extends Function implements TXMResult { |
|
27 |
|
|
28 |
//TODO: test rw.setStringEncoding("UTF-8"); // or connection |
|
29 |
private int[] freqs; |
|
30 |
private String[] labels; |
|
31 |
private Corpus corpus; |
|
32 |
private Object source; |
|
33 |
|
|
34 |
public WordCloud(Lexicon lex) { |
|
35 |
//List<Line> lines = voc.getAllLines(); |
|
36 |
corpus = lex.getCorpus(); |
|
37 |
source = lex; |
|
38 |
this.freqs = lex.getFreq(); |
|
39 |
this.labels = lex.getForms(); |
|
40 |
|
|
41 |
//removeDiacritics(); |
|
42 |
} |
|
43 |
|
|
44 |
// public WordCloud(LexicalTable table) throws RWorkspaceException, REXPMismatchException { |
|
45 |
// parent = table.getPartition(); |
|
46 |
// if (parent == null) parent = table.getCorpus(); |
|
47 |
// |
|
48 |
// RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
49 |
// this.labels = rw.evalToString("rownames("+table.getSymbol()+")"); |
|
50 |
// this.freqs = rw.eval("rowSums("+table.getSymbol()+")").asIntegers(); |
|
51 |
// |
|
52 |
// removeDiacritics(); |
|
53 |
// } |
|
54 |
|
|
55 |
/** |
|
56 |
* |
|
57 |
* @param voc |
|
58 |
*/ |
|
59 |
public WordCloud(Index voc) { |
|
60 |
initWith(voc); |
|
61 |
//removeDiacritics(); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* |
|
66 |
* @param voc |
|
67 |
*/ |
|
68 |
private void initWith(Index voc) { |
|
69 |
corpus = voc.getCorpus(); |
|
70 |
source = voc; |
|
71 |
List<Line> lines = voc.getAllLines(); |
|
72 |
this.freqs = new int[lines.size()]; |
|
73 |
this.labels = new String[lines.size()]; |
|
74 |
|
|
75 |
int i = 0; |
|
76 |
for (Line line : lines) { |
|
77 |
freqs[i] = line.getFrequency(); |
|
78 |
labels[i] = line.toString("_"); //$NON-NLS-1$ |
|
79 |
i++; |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* |
|
85 |
* @param corpus |
|
86 |
* @throws CqiClientException |
|
87 |
* @throws IOException |
|
88 |
* @throws CqiServerError |
|
89 |
*/ |
|
90 |
public WordCloud(Corpus corpus) throws CqiClientException, IOException, CqiServerError { |
|
91 |
Query query; |
|
92 |
String lang = corpus.getLang(); |
|
93 |
if (corpus.getProperty(lang+"pos") != null) { |
|
94 |
query = new Query(getQueryForLang(lang)); |
|
95 |
} else { |
|
96 |
query = new Query("[]"); |
|
97 |
} |
|
98 |
|
|
99 |
System.out.println("Used query: "+query); |
|
100 |
|
|
101 |
ArrayList<Property> props = new ArrayList<Property>(); |
|
102 |
props.add(corpus.getProperty("word")); |
|
103 |
Index voc = new Index(corpus, query, props); |
|
104 |
if (!query.toString().equals("[]")) { |
|
105 |
corpus.storeResult(voc); |
|
106 |
} |
|
107 |
List<Line> lines = voc.getAllLines(); |
|
108 |
if (lines != null && lines.size() > 0) { |
|
109 |
this.initWith(voc); |
|
110 |
} else { |
|
111 |
Log.severe("Error: Could not build a word selection with this corpus"); |
|
112 |
throw new IllegalArgumentException("Error: Index failed with corpus "+corpus+" with lang "+lang+" and query "+query); |
|
113 |
} |
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
// public WordCloud(QueryIndex qindex) { |
|
118 |
// parent = qindex.getCorpus(); |
|
119 |
// source = qindex; |
|
120 |
// Collection<QueryIndexLine> lines = qindex.getLines(); |
|
121 |
// this.freqs = new int[lines.size()]; |
|
122 |
// this.labels = new String[lines.size()]; |
|
123 |
// |
|
124 |
// int i = 0; |
|
125 |
// for (QueryIndexLine line : lines) { |
|
126 |
// freqs[i] = line.getFrequency(); |
|
127 |
// labels[i] = line.getName(); |
|
128 |
// } |
|
129 |
// //removeDiacritics(); |
|
130 |
// } |
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
private String getQueryForLang(String lang) { |
|
135 |
if ("fr".equals(lang)) { |
|
136 |
return "[frpos=\"NOM|NAM|ADJ|VER.*\" & frlemma!=\"être|avoir|faire|pouvoir|devoir|vouloir|falloir|aller|dire|savoir\"]"; // requete de Serge pour le français TT |
|
137 |
} else if ("en".equals(lang)) { |
|
138 |
return "[enpos=\"N.*|JJ.*|V.*\" & enlemma!=\"be|have|do|say|go|make|other\"]"; // requete de Serge pour l'anglais TT |
|
139 |
} else { |
|
140 |
return ".*"; |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
144 |
public Corpus getCorpus() { |
|
145 |
return corpus; |
|
146 |
} |
|
147 |
|
|
148 |
public Object getSource() { |
|
149 |
return source; |
|
150 |
} |
|
151 |
|
|
152 |
private void removeDiacritics() { |
|
153 |
//for (int i = 0; i < labels.length ; i++) |
|
154 |
// labels[i] = AsciiUtils.convertNonAscii(labels[i]); |
|
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* |
|
159 |
* @return |
|
160 |
*/ |
|
161 |
public String getName() { |
|
162 |
return "WordCloud (" + TXMPreferences.getInt(WordCloudPreferences.PREFERENCES_NODE, this, WordCloudPreferences.FMIN) |
|
163 |
+ " / " |
|
164 |
+ TXMPreferences.getInt(WordCloudPreferences.PREFERENCES_NODE, this, WordCloudPreferences.MAX_WORDS) |
|
165 |
+ ")"; |
|
166 |
} |
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
/** |
|
171 |
* Check and init R packages. |
|
172 |
* @return |
|
173 |
*/ |
|
174 |
// FIXME: to factorize and move to RWorkspace |
|
175 |
public static boolean initPackages() { |
|
176 |
String[] packages = {"Rcpp", "RColorBrewer", "wordcloud"}; //$NON-NLS-1$ //$NON-NLS-2$ |
|
177 |
try { |
|
178 |
if (!loadAndInstallNeededPackages(RWorkspace.getRWorkspaceInstance(), packages)) { |
|
179 |
System.out.println(TBXWordCloudMessages.Log_Aborting); |
|
180 |
return false; |
|
181 |
} |
|
182 |
} catch (RWorkspaceException e) { |
|
183 |
System.out.println(TBXWordCloudMessages.Log_Stats_Engine_not_ready); |
|
184 |
Log.printStackTrace(e); |
|
185 |
return false; |
|
186 |
} |
|
187 |
return true; |
|
188 |
} |
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
/** |
|
194 |
* |
|
195 |
* @param rw |
|
196 |
* @param packages |
|
197 |
* @return |
|
198 |
*/ |
|
199 |
// FIXME: to factorize and move to RWorkspace |
|
200 |
public static boolean loadAndInstallNeededPackages(RWorkspace rw, String[] packages) { |
|
201 |
boolean installFailed = false; |
|
202 |
for (String p : packages) { |
|
203 |
try { |
|
204 |
Log.severe(TBXWordCloudMessages.bind(TBXWordCloudMessages.Log_Loading_R_package, p)); |
|
205 |
loadPackage(rw, p); |
|
206 |
} catch(Exception e) { |
|
207 |
//Log.severe(Messages.bind(Messages.ComputeWordCloud_3,p,e)); |
|
208 |
System.out.println(TBXWordCloudMessages.bind(TBXWordCloudMessages.Log_Installing_R_package, p)); |
|
209 |
try { |
|
210 |
rw.eval("install.packages(\""+p+"\", dependencies=TRUE, repos=\"http://cran.rstudio.com\");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
211 |
rw.eval("library(\""+p+"\")"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
212 |
} catch(Exception e2) { |
|
213 |
System.out.println(TBXWordCloudMessages.bind(TBXWordCloudMessages.Log_Could_not_install_R_package, p)); |
|
214 |
Log.printStackTrace(e2); |
|
215 |
installFailed = true; |
|
216 |
} |
|
217 |
} |
|
218 |
} |
|
219 |
|
|
220 |
if (installFailed) { |
|
221 |
System.out.println(TBXWordCloudMessages.Log_R_Packages_installation_failed); |
|
222 |
return false; |
|
223 |
} else { |
|
224 |
Log.info(TBXWordCloudMessages.Log_R_Packages_loaded); |
|
225 |
return true; |
|
226 |
} |
|
227 |
} |
|
228 |
|
|
229 |
/** |
|
230 |
* |
|
231 |
* @param rw |
|
232 |
* @param p |
|
233 |
* @throws RWorkspaceException |
|
234 |
*/ |
|
235 |
// FIXME: to factorize and move to RWorkspace |
|
236 |
public static void loadPackage(RWorkspace rw, String p) throws RWorkspaceException { |
|
237 |
rw.eval("library(\""+p+"\")"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
238 |
} |
|
239 |
|
|
240 |
/** |
|
241 |
* @return the freqs |
|
242 |
*/ |
|
243 |
public int[] getFreqs() { |
|
244 |
return freqs; |
|
245 |
} |
|
246 |
|
|
247 |
/** |
|
248 |
* @return the labels |
|
249 |
*/ |
|
250 |
public String[] getLabels() { |
|
251 |
return labels; |
|
252 |
} |
|
253 |
|
|
254 |
@Override |
|
255 |
public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception { |
|
256 |
// TODO Auto-generated method stub |
|
257 |
return false; |
|
258 |
} |
|
259 |
|
|
260 |
@Override |
|
261 |
public void clean() { |
|
262 |
// TODO Auto-generated method stub |
|
263 |
|
|
264 |
} |
|
265 |
|
|
266 |
@Override |
|
267 |
public boolean delete() { |
|
268 |
return this.corpus.removeResult(this); |
|
269 |
} |
|
270 |
|
|
271 |
@Override |
|
272 |
public HasResults getParent() { |
|
273 |
return this.corpus; |
|
274 |
} |
|
275 |
} |
|
0 | 276 |
tmp/org.txm.wordcloud.core/src/org/txm/wordcloud/core/chartsengine/jfreechart/JFCWordCloudChartCreator.java (revision 25) | ||
---|---|---|
1 |
package org.txm.wordcloud.core.chartsengine.jfreechart; |
|
2 |
|
|
3 |
import org.jfree.chart.JFreeChart; |
|
4 |
import org.jfree.data.xy.XYSeriesCollection; |
|
5 |
import org.txm.chartsengine.jfreechart.core.JFCChartCreator; |
|
6 |
import org.txm.wordcloud.core.functions.WordCloud; |
|
7 |
|
|
8 |
public class JFCWordCloudChartCreator extends JFCChartCreator { |
|
9 |
|
|
10 |
public JFCWordCloudChartCreator() { |
|
11 |
// TODO Auto-generated constructor stub |
|
12 |
} |
|
13 |
|
|
14 |
@Override |
|
15 |
public JFreeChart createChart(Object resultData, String preferencesNode) { |
|
16 |
|
|
17 |
// TODO Auto-generated method stub |
|
18 |
System.err.println("JFCWordCloudChartCreator.createChart(): Not yet implemented"); |
|
19 |
|
|
20 |
WordCloud wordCloud = (WordCloud) resultData; |
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
JFreeChart chart = null; |
|
25 |
|
|
26 |
XYSeriesCollection dataset = new XYSeriesCollection(); |
|
27 |
|
|
28 |
// XYSeries series = new XYSeries("test wordcloud"); |
|
29 |
// dataset.addSeries(series); |
|
30 |
|
|
31 |
String[] xAxisSymbols = new String[0]; |
|
32 |
|
|
33 |
|
|
34 |
// for (int i = 0 ; i < 0 ; i++) { |
|
35 |
// //series.add(i, Math.random()); |
|
36 |
// |
|
37 |
// // Add X axis symbol |
|
38 |
// xAxisSymbols[i] = "test " + i; |
|
39 |
// } |
|
40 |
|
|
41 |
// Create chart title |
|
42 |
String title = ""; |
|
43 |
|
|
44 |
// Create the chart |
|
45 |
chart = this.getChartsEngine().createXYBarChart(dataset, title, "", "", false, true, false, xAxisSymbols); |
|
46 |
//((IItemSelectionRenderer) chart.getXYPlot().getRenderer()).setChartType(ChartsEngine.CHART_TYPE_PARTITION_DIMENSIONS); |
|
47 |
|
|
48 |
chart.getPlot().setNoDataMessage("JFCWordCloudChartCreator.createChart(): Not yet implemented in JFreeChart charts engine."); |
|
49 |
|
|
50 |
|
|
51 |
// Custom range axis for ticks drawing options |
|
52 |
//chart.getXYPlot().setRangeAxis(new ExtendedNumberAxis((NumberAxis) chart.getXYPlot().getRangeAxis(), false, true, 0, DatasetUtilities.findMaximumRangeValue(chart.getXYPlot().getDataset()).doubleValue())); |
|
53 |
|
|
54 |
//this.getChartsEngine().getTheme().apply(chart); |
|
55 |
|
|
56 |
|
|
57 |
return chart; |
|
58 |
|
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
@Override |
|
63 |
public Class getResultDataType() { |
|
64 |
return WordCloud.class; |
|
65 |
} |
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
} |
|
0 | 70 |
tmp/org.txm.wordcloud.core/src/org/txm/wordcloud/core/chartsengine/r/RWordCloudChartCreator.java (revision 25) | ||
---|---|---|
1 |
package org.txm.wordcloud.core.chartsengine.r; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
import org.txm.chartsengine.r.core.RChartCreator; |
|
6 |
import org.txm.chartsengine.r.core.RChartsEngine; |
|
7 |
import org.txm.stat.StatException; |
|
8 |
import org.txm.stat.engine.r.RWorkspace; |
|
9 |
import org.txm.stat.engine.r.RWorkspaceException; |
|
10 |
import org.txm.tbx.preferences.TXMPreferences; |
|
11 |
import org.txm.wordcloud.core.functions.WordCloud; |
|
12 |
import org.txm.wordcloud.core.preferences.WordCloudPreferences; |
|
13 |
|
|
14 |
public class RWordCloudChartCreator extends RChartCreator { |
|
15 |
|
|
16 |
public RWordCloudChartCreator() { |
|
17 |
// TODO Auto-generated constructor stub |
|
18 |
} |
|
19 |
|
|
20 |
@Override |
|
21 |
public Object createChart(Object resultData, String preferencesNode) { |
|
22 |
// TODO Auto-generated method stub |
|
23 |
return null; |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public File createChartFile(Object resultData, File file, String preferencesNode) { |
|
28 |
|
|
29 |
try { |
|
30 |
WordCloud wordCloud = (WordCloud) resultData; |
|
31 |
|
|
32 |
|
|
33 |
// parameters |
|
34 |
int maxWords = TXMPreferences.getInt(preferencesNode, resultData, WordCloudPreferences.MAX_WORDS); |
|
35 |
int minFreq = TXMPreferences.getInt(preferencesNode, resultData, WordCloudPreferences.FMIN); |
|
36 |
float rotPer = TXMPreferences.getFloat(preferencesNode, resultData, WordCloudPreferences.ROT); |
|
37 |
boolean randomOrder = TXMPreferences.getBoolean(preferencesNode, resultData, WordCloudPreferences.RANDOM_POSITION); |
|
38 |
|
|
39 |
|
|
40 |
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); |
|
41 |
// System.out.println("load wordcloud..."); |
|
42 |
rw.eval("library(wordcloud)"); //$NON-NLS-1$ |
|
43 |
//System.out.println("tmpfreqs..."); |
|
44 |
rw.addVectorToWorkspace("tmpfreqs", wordCloud.getFreqs()); //$NON-NLS-1$ |
|
45 |
//System.out.println("tmplabels..."); |
|
46 |
rw.addVectorToWorkspace("tmplabels", wordCloud.getLabels()); //$NON-NLS-1$ |
|
47 |
|
|
48 |
//wordcloud(words,freq, |
|
49 |
// scale : A vector of length 2 indicating the range of the size of the words. |
|
50 |
// min.freq: words with frequency below min.freq will not be plotted |
|
51 |
// max.words : Maximum number of words to be plotted. least frequent terms dropped |
|
52 |
// random.order : plot words in random order. If false, they will be plotted in decreasing frequency |
|
53 |
// random.color : choose colors randomly from the colors. If false, the color is chosen based on the frequency |
|
54 |
// rot.per : proportion words with 90 degree rotation |
|
55 |
// colors : color words from least to most frequent |
|
56 |
// ordered.colors : if true, then colors are assigned to words in order |
|
57 |
//System.out.println("wordcloud..."); |
|
58 |
String cmd = "wordcloud(tmplabels, tmpfreqs, random.color=FALSE, colors=brewer.pal(10,\"Dark2\")"; //$NON-NLS-1$ |
|
59 |
|
|
60 |
if (randomOrder == false) |
|
61 |
cmd += ", random.order=FALSE"; //$NON-NLS-1$ |
|
62 |
|
|
63 |
if (maxWords > 0) { |
|
64 |
cmd += ", max.words="+maxWords; //$NON-NLS-1$ |
|
65 |
} else { |
|
66 |
cmd += ", max.words=Inf"; //$NON-NLS-1$ |
|
67 |
} |
|
68 |
|
|
69 |
if (minFreq > 0) { |
|
70 |
cmd += ", min.freq="+minFreq; //$NON-NLS-1$ |
|
71 |
} |
|
72 |
|
|
73 |
if (rotPer >= 0 && rotPer <= 1) { |
|
74 |
cmd += ", rot.per="+rotPer; //$NON-NLS-1$ |
|
75 |
} |
|
76 |
cmd +=");"; //$NON-NLS-1$ |
|
77 |
//System.out.println("ploting..."); |
|
78 |
//rw.plot(svgFile, cmd, device); |
|
79 |
|
|
80 |
((RChartsEngine) this.chartsEngine).plot(file, cmd); |
|
81 |
|
|
82 |
|
|
83 |
//System.out.println("cleaning"); |
|
84 |
rw.eval("rm(tmplabels)"); //$NON-NLS-1$ |
|
85 |
rw.eval("rm(tmpfreqs)"); //$NON-NLS-1$ |
|
86 |
} |
|
87 |
catch(RWorkspaceException e) { |
|
88 |
// TODO Auto-generated catch block |
|
89 |
e.printStackTrace(); |
|
90 |
} |
|
91 |
catch(StatException e) { |
|
92 |
// TODO Auto-generated catch block |
|
93 |
e.printStackTrace(); |
|
94 |
} |
|
95 |
|
|
96 |
return file; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public Class getResultDataType() { |
|
101 |
return WordCloud.class; |
|
102 |
} |
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
} |
|
0 | 107 |
tmp/org.txm.wordcloud.core/src/org/txm/wordcloud/core/preferences/WordCloudPreferences.java (revision 25) | ||
---|---|---|
1 |
package org.txm.wordcloud.core.preferences; |
|
2 |
|
|
3 |
|
|
4 |
import org.eclipse.core.runtime.preferences.DefaultScope; |
|
5 |
import org.osgi.framework.FrameworkUtil; |
|
6 |
import org.osgi.service.prefs.Preferences; |
|
7 |
import org.txm.tbx.preferences.TXMPreferences; |
|
8 |
|
|
9 |
public class WordCloudPreferences extends TXMPreferences { |
|
10 |
|
|
11 |
|
|
12 |
// auto populate the preference node qualifier from the current bundle id |
|
13 |
public static final String PREFERENCES_NODE = FrameworkUtil.getBundle(WordCloudPreferences.class).getSymbolicName(); |
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
public static final String PREFERENCES_PREFIX = "wordcloud_"; |
|
19 |
|
|
20 |
|
|
21 |
public static final String MAX_WORDS = PREFERENCES_PREFIX + "max_words"; //$NON-NLS-1$ |
|
22 |
public static final String FMIN = PREFERENCES_PREFIX + "f_min"; //$NON-NLS-1$ |
|
23 |
public static final String ROT = PREFERENCES_PREFIX + "rotation_percent"; //$NON-NLS-1$ |
|
24 |
public static final String RANDOM_POSITION = PREFERENCES_PREFIX + "random_positions"; //$NON-NLS-1$ |
|
25 |
|
|
26 |
|
|
27 |
public WordCloudPreferences() { |
|
28 |
// TODO Auto-generated constructor stub |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
public void initializeDefaultPreferences() { |
|
33 |
|
|
34 |
// FIXME: tests |
|
35 |
//Preferences preferences = InstanceScope.INSTANCE.getNode("org.txm.tbx.wordcloud"); |
|
36 |
//Application.PLUGIN_ID |
|
37 |
//Preferences preferences = ConfigurationScope.INSTANCE.getNode(ConfigurationScope.SCOPE); |
|
38 |
// default preferences |
|
39 |
|
|
40 |
|
|
41 |
//System.out.println("WordCloudPreferencesInitializer.initializeDefaultPreferences() tests MAXWORDS ConfigurationScope: " + ConfigurationScope.INSTANCE.getNode(PREFERENCE_NODE).get(MAXWORDS, "tt")); |
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
Preferences defaultPreferences = DefaultScope.INSTANCE.getNode(PREFERENCES_NODE); |
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
defaultPreferences.putInt(MAX_WORDS, 50); |
|
50 |
defaultPreferences.putInt(FMIN, 20); |
|
51 |
defaultPreferences.putInt(ROT, 10); |
|
52 |
defaultPreferences.putBoolean(RANDOM_POSITION, false); |
|
53 |
|
|
54 |
// FIXME: tests |
|
55 |
// IPreferencesService service = Platform.getPreferencesService(); |
|
56 |
// System.out.println("WordCloudPreferencesInitializer.initializeDefaultPreferences() tests MAXWORDS IPreferenceService: " + service.getString(PREFERENCE_NODE, MAXWORDS, "tttt", null)); |
|
57 |
|
|
58 |
//System.err.println("WordCloudPreferencesInitializer.initializeDefaultPreferences()"); |
|
59 |
|
|
60 |
// preferences from file |
|
61 |
// Preferences userPreferences = ConfigurationScope.INSTANCE.getNode("org.txm.tbx.wordcloud"); |
|
62 |
// System.err.println("***********************************************WordCloudPreferencesInitializer.initializeDefaultPreferences(): " + Platform.getProduct().getId()); |
|
63 |
} |
|
64 |
|
|
65 |
} |
|
0 | 66 |
tmp/org.txm.wordcloud.core/build.properties (revision 25) | ||
---|---|---|
1 |
source.. = src/ |
|
2 |
output.. = bin/ |
|
3 |
bin.includes = META-INF/,\ |
|
4 |
.,\ |
|
5 |
plugin.xml |
|
0 | 6 |
tmp/org.txm.wordcloud.core/plugin.xml (revision 25) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<?eclipse version="3.4"?> |
|
3 |
<plugin> |
|
4 |
<extension |
|
5 |
point="org.txm.chartsengine.chartcreator"> |
|
6 |
<ChartCreator |
|
7 |
chartsEngineName="TMP_jfreechart_charts_engine" |
|
8 |
class="org.txm.wordcloud.core.chartsengine.jfreechart.JFCWordCloudChartCreator" |
|
9 |
fileNamePrefix="wordcloud"> |
|
10 |
</ChartCreator> |
|
11 |
<ChartCreator |
|
12 |
chartsEngineName="r_charts_engine" |
|
13 |
class="org.txm.wordcloud.core.chartsengine.r.RWordCloudChartCreator" |
|
14 |
fileNamePrefix="wordcloud"> |
|
15 |
</ChartCreator> |
|
16 |
</extension> |
|
17 |
<extension |
|
18 |
point="org.eclipse.core.runtime.preferences"> |
|
19 |
<initializer |
|
20 |
class="org.txm.wordcloud.core.preferences.WordCloudPreferences"> |
|
21 |
</initializer> |
|
22 |
</extension> |
|
23 |
|
|
24 |
</plugin> |
|
0 | 25 |
tmp/org.txm.wordcloud.core/.settings/org.eclipse.jdt.core.prefs (revision 25) | ||
---|---|---|
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.wordcloud.core/.classpath (revision 25) | ||
---|---|---|
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.wordcloud.core/META-INF/MANIFEST.MF (revision 25) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: WordCloud TBX |
|
4 |
Bundle-SymbolicName: org.txm.wordcloud.core;singleton:=true |
|
5 |
Bundle-Version: 1.0.0.qualifier |
|
6 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 |
|
7 |
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.10.0", |
|
8 |
org.txm.toolbox;bundle-version="0.7.0", |
|
9 |
org.txm.chartsengine.jfreechart.core;bundle-version="1.0.0", |
|
10 |
org.txm.chartsengine.r.core;bundle-version="1.0.0" |
|
11 |
Export-Package: org.txm.wordcloud.core.chartsengine.jfreechart, |
|
12 |
org.txm.wordcloud.core.chartsengine.r, |
|
13 |
org.txm.wordcloud.core.functions, |
|
14 |
org.txm.wordcloud.core.messages, |
|
15 |
org.txm.wordcloud.core.preferences |
|
16 |
Import-Package: org.txm.chartsengine.core |
|
17 |
Bundle-Vendor: TXM |
|
0 | 18 |
Also available in: Unified diff