Révision 3385
TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/LoadBinaryCorporaDirectory.java (revision 3385) | ||
---|---|---|
273 | 273 |
// lsd.setInitialSelections(files); |
274 | 274 |
lsd.setTitle(TXMUIMessages.LoadBinaryCorporaDirectory_corpusLoad); |
275 | 275 |
if (lsd.open() == ListSelectionDialog.OK) { |
276 |
System.out.println(lsd.getResult());
|
|
276 |
//Log.info(lsd.getResult());
|
|
277 | 277 |
for (Object o : lsd.getResult()) { |
278 | 278 |
selectedFiles.add(new File(o.toString())); |
279 | 279 |
} |
TXM/trunk/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/views/RVariablesView.java (revision 3385) | ||
---|---|---|
387 | 387 |
*/ |
388 | 388 |
@Override |
389 | 389 |
public Object[] getElements(Object element) { |
390 |
System.out.println("input: "+element); |
|
390 |
|
|
391 | 391 |
Collection<Project> input = (Collection<Project>) element; |
392 | 392 |
Object[] objects = new Object[input.size()]; |
393 | 393 |
Iterator<Project> it = input.iterator(); |
TXM/trunk/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/statsengine/data/ILexicalTable.java (revision 3385) | ||
---|---|---|
189 | 189 |
*/ |
190 | 190 |
public abstract List<Integer> getFreqs(); |
191 | 191 |
|
192 |
/** |
|
193 |
* Export data. |
|
194 |
* |
|
195 |
* @param file the file |
|
196 |
* @param colseparator the colseparator |
|
197 |
* @param txtseparator the txtseparator |
|
198 |
*/ |
|
199 |
public abstract void exportData(File file, String colseparator, String txtseparator); |
|
200 |
|
|
201 | 192 |
public abstract boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator); |
202 | 193 |
|
203 | 194 |
/** |
TXM/trunk/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/handlers/ImportTable.java (revision 3385) | ||
---|---|---|
43 | 43 |
import org.txm.core.preferences.TXMPreferences; |
44 | 44 |
import org.txm.lexicaltable.core.functions.LexicalTable; |
45 | 45 |
import org.txm.lexicaltable.rcp.editors.LexicalTableEditor; |
46 |
import org.txm.rcp.TXMWindows; |
|
46 | 47 |
import org.txm.rcp.handlers.BaseAbstractHandler; |
47 | 48 |
import org.txm.rcp.swt.dialog.LastOpened; |
49 |
import org.txm.rcp.utils.SWTEditorsUtils; |
|
50 |
import org.txm.rcp.views.corpora.CorporaView; |
|
48 | 51 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
49 | 52 |
import org.txm.utils.logger.Log; |
50 | 53 |
|
... | ... | |
73 | 76 |
|
74 | 77 |
if (editor instanceof LexicalTableEditor) { |
75 | 78 |
LexicalTableEditor LTeditor = (LexicalTableEditor) editor; |
76 |
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event) |
|
77 |
.getShell(); |
|
79 |
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(); |
|
78 | 80 |
FileDialog d = new FileDialog(shell, SWT.OPEN); |
79 | 81 |
if (LastOpened.getFile(ID) != null) { |
80 | 82 |
d.setFilterPath(LastOpened.getFolder(ID)); |
... | ... | |
85 | 87 |
File file = new File(path); |
86 | 88 |
LastOpened.set(ID, file.getParent(), file.getName()); |
87 | 89 |
if (file.exists()) { |
88 |
LTeditor.importData(file); |
|
90 |
try { |
|
91 |
LTeditor.getLexicalTable().getData().importData(file, encoding, colseparator, txtseparator); |
|
92 |
SWTEditorsUtils.closeEditors(LTeditor.getLexicalTable(), true); |
|
93 |
Log.info("Re-open the lexical table to see the modifications"); |
|
94 |
} |
|
95 |
catch (Exception e) { |
|
96 |
System.out.println("Error: data import failed: " + e); |
|
97 |
Log.printStackTrace(e); |
|
98 |
} |
|
99 |
|
|
89 | 100 |
} |
90 | 101 |
} |
91 | 102 |
} |
92 | 103 |
else if (sel instanceof LexicalTable) { |
93 | 104 |
LexicalTable lt = (LexicalTable) sel; |
94 |
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event) |
|
95 |
.getShell(); |
|
105 |
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(); |
|
96 | 106 |
FileDialog d = new FileDialog(shell, SWT.OPEN); |
97 | 107 |
if (LastOpened.getFile(ID) != null) { |
98 | 108 |
d.setFilterPath(LastOpened.getFolder(ID)); |
... | ... | |
108 | 118 |
lt.getData().importData(file, encoding, colseparator, txtseparator); |
109 | 119 |
lt.setAltered(); |
110 | 120 |
System.out.println(NLS.bind("Data imported: {0} columns and {1} rows.", lt.getNColumns(), lt.getNRows())); |
121 |
SWTEditorsUtils.closeEditors(lt, true); |
|
122 |
Log.info("Re-open the lexical table to see the modifications"); |
|
111 | 123 |
} |
112 | 124 |
catch (Exception e) { |
113 | 125 |
System.out.println("Error: data import failed: " + e); |
TXM/trunk/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/data/MatrixImpl.java (revision 3385) | ||
---|---|---|
27 | 27 |
// |
28 | 28 |
package org.txm.statsengine.r.core.data; |
29 | 29 |
|
30 |
import java.io.BufferedReader; |
|
30 | 31 |
import java.io.File; |
32 |
import java.io.FileNotFoundException; |
|
33 |
import java.io.UnsupportedEncodingException; |
|
31 | 34 |
import java.util.ArrayList; |
32 | 35 |
import java.util.Arrays; |
33 | 36 |
import java.util.Collections; |
... | ... | |
43 | 46 |
import org.txm.statsengine.r.core.RWorkspace; |
44 | 47 |
import org.txm.statsengine.r.core.exceptions.RException; |
45 | 48 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
49 |
import org.txm.utils.CsvReader; |
|
46 | 50 |
import org.txm.utils.OSDetector; |
51 |
import org.txm.utils.io.IOUtils; |
|
47 | 52 |
import org.txm.utils.logger.Log; |
48 | 53 |
|
49 | 54 |
import cern.colt.matrix.DoubleMatrix2D; |
... | ... | |
287 | 292 |
} |
288 | 293 |
// de la liste rows |
289 | 294 |
} |
290 |
|
|
291 |
|
|
292 |
|
|
295 |
|
|
293 | 296 |
/** |
294 |
* Export data. |
|
295 |
* |
|
296 |
* @param f the f |
|
297 |
* @param colseparator the colseparator |
|
298 |
* @param txtseparator the txtseparator |
|
299 |
*/ |
|
300 |
@Deprecated |
|
301 |
public void exportData(File f, String colseparator, String txtseparator) { |
|
302 |
try { |
|
303 |
org.txm.statsengine.r.core.RWorkspace |
|
304 |
.getRWorkspaceInstance().safeEval( |
|
305 |
"write.table(" + symbol + ", file=\"" + f.getAbsolutePath().replace("\\", "\\\\") + "\", fileEncoding=\"UTF-8\");"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
|
306 |
} |
|
307 |
catch (Exception e1) { |
|
308 |
org.txm.utils.logger.Log.printStackTrace(e1); |
|
309 |
RWorkspace.printLastSafeEvalExpr(); |
|
310 |
} |
|
311 |
} |
|
312 |
|
|
313 |
/** |
|
314 | 297 |
* Filter. |
315 | 298 |
* |
316 | 299 |
* @param freqs the freqs |
... | ... | |
680 | 663 |
* t3 <- t2[1:nrow(t2),]; |
681 | 664 |
* colnames(t3) <- header; |
682 | 665 |
*/ |
683 |
rw.voidEval("tmpmat <- as.matrix(read.table(file=\"" + path + "\", sep=\"" + colseparator + "\", row.names=1, skip=1, fileEncoding=\"" + encoding + "\"));"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
684 |
rw.voidEval("tmpheader <- scan(file=\"" + path + "\", what = character(), nlines=1, sep=\"" + colseparator + "\", fileEncoding=\"" + encoding + "\");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
685 |
rw.voidEval("tmpheader <- tmpheader[2:length(tmpheader)];"); //$NON-NLS-1$ |
|
686 |
rw.voidEval("tmpmat <- tmpmat[1:nrow(tmpmat),];"); //$NON-NLS-1$ |
|
687 |
rw.voidEval("colnames(tmpmat) <- tmpheader"); //$NON-NLS-1$ |
|
666 |
// rw.voidEval("tmpmat <- as.matrix(read.table(file=\"" + path + "\", sep=\"" + colseparator + "\", row.names=1, skip=1, fileEncoding=\"" + encoding + "\"));"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
667 |
// rw.voidEval("tmpheader <- scan(file=\"" + path + "\", what = character(), nlines=1, sep=\"" + colseparator + "\", fileEncoding=\"" + encoding + "\");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
668 |
// rw.voidEval("tmpheader <- tmpheader[2:length(tmpheader)];"); //$NON-NLS-1$ |
|
669 |
// rw.voidEval("tmpmat <- tmpmat[1:nrow(tmpmat),];"); //$NON-NLS-1$ |
|
670 |
// rw.voidEval("colnames(tmpmat) <- tmpheader"); //$NON-NLS-1$ |
|
671 |
// rw.eval(symbol + "<- tmpmat"); //$NON-NLS-1$ |
|
688 | 672 |
|
689 |
rw.eval(symbol + "<- tmpmat"); //$NON-NLS-1$ |
|
673 |
try { |
|
674 |
BufferedReader input = IOUtils.getReader(f, encoding); |
|
675 |
CsvReader reader = new CsvReader(input); |
|
676 |
reader.readHeaders(); |
|
677 |
String[] header = reader.getHeaders(); |
|
678 |
String[] rheader = new String[header.length-1]; |
|
679 |
System.arraycopy(header, 1, rheader, 0, header.length-1); |
|
680 |
|
|
681 |
int ncols = reader.getHeaderCount(); |
|
682 |
if (ncols == 1) { |
|
683 |
Log.warning("LexicalTable data import : no column found in: "+f); |
|
684 |
return false; |
|
685 |
} |
|
686 |
rw.voidEval("tmpmat <- matrix(ncol="+(ncols-1)+");"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
687 |
|
|
688 |
ArrayList<String> rownames = new ArrayList<>(); |
|
689 |
while (reader.readRecord()) { |
|
690 |
|
|
691 |
rownames.add(reader.get(0)); |
|
692 |
|
|
693 |
double[] values = new double[ncols-1]; |
|
694 |
for (int i = 1 ; i < ncols ; i++) { |
|
695 |
String r = reader.get(i); |
|
696 |
|
|
697 |
if (r != null) { |
|
698 |
values[i-1] = Double.parseDouble(r); |
|
699 |
} else { |
|
700 |
values[i-1] = 0; |
|
701 |
} |
|
702 |
} |
|
703 |
System.out.println("values="+Arrays.toString(values)); |
|
704 |
rw.addVectorToWorkspace("tmpvec", values); |
|
705 |
rw.voidEval("tmpmat <- rbind(tmpmat, tmpvec);"); |
|
706 |
} |
|
707 |
rw.voidEval("tmpmat <- tmpmat[-1,];"); // $NON-NLS-1$ remove the null first line |
|
708 |
rw.addVectorToWorkspace("tmprownames", rownames.toArray(new String[rownames.size()])); //$NON-NLS-1$ |
|
709 |
rw.addVectorToWorkspace("tmpcolnames", rheader); |
|
710 |
rw.assignRowNamesToMatrix("tmpmat", "tmprownames"); |
|
711 |
rw.assignColNamesToMatrix("tmpmat", "tmpcolnames"); |
|
712 |
|
|
713 |
rw.voidEval(symbol + "<- tmpmat;"); //$NON-NLS-1$ |
|
714 |
//rw.voidEval("rm(tmpmat);"); //$NON-NLS-1$ |
|
715 |
reader.close(); |
|
716 |
input.close(); |
|
717 |
} |
|
718 |
catch (Exception e) { |
|
719 |
Log.warning("LexicalTable data import : error."); |
|
720 |
Log.printStackTrace(e); |
|
721 |
return false; |
|
722 |
} |
|
690 | 723 |
|
691 | 724 |
return true; |
692 | 725 |
} |
... | ... | |
1086 | 1119 |
try { |
1087 | 1120 |
String path = f.getAbsolutePath().replace("\\", "\\\\"); //$NON-NLS-1$ //$NON-NLS-2$ |
1088 | 1121 |
org.txm.statsengine.r.core.RWorkspace.getRWorkspaceInstance().safeEval( |
1089 |
"write.table(" + symbol + ", file=\"" + path + "\""//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
1122 |
"write.csv(" + symbol + ", file=\"" + path + "\""//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
1090 | 1123 |
+ ", col.names = NA, row.names = TRUE, fileEncoding=\"" + encoding + "\"" //$NON-NLS-1$ //$NON-NLS-2$ |
1091 | 1124 |
+ ", sep=\"" + colseparator + "\");"); //$NON-NLS-1$ //$NON-NLS-2$ |
1092 | 1125 |
} |
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/txt/importer.groovy (revision 3385) | ||
---|---|---|
243 | 243 |
cpb.tick() |
244 | 244 |
Sequence S = new Sequence(); |
245 | 245 |
Filter F1 = new CutHeader(); |
246 |
Filter F7 = new TagSentences(); |
|
246 |
Filter F7 = new TagSentences(TokenizerClasses.newTokenizerClasses(project.getPreferencesScope(), lang));
|
|
247 | 247 |
Filter F11 = new FusionHeader(); |
248 | 248 |
S.add(F1); |
249 | 249 |
S.add(F7); |
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/scripts/filters/TagSentences/TagSentences.groovy (revision 3385) | ||
---|---|---|
116 | 116 |
corr_tags = tc.corr_tags; |
117 | 117 |
|
118 | 118 |
strongPunct = tc.punct_strong; |
119 |
|
|
120 |
reg_comment = /\A\s*<!--.*-->\s*\Z/ |
|
121 |
reg_out_of_sentence = /^(.*)<s( [^>]*)?>(.*)$/ |
|
122 |
reg_sentence_with_no_n_attribute = /<s( [^>]*)?>/ |
|
123 |
reg_end_of_sentence = /^(.*)<\/s>(.*)$/ |
|
124 |
reg_punct = /^(.*)<w type="pon"[^>]*>.*<\/w>(.*)$/ |
|
125 |
reg_strong_punct = /^(.*)<w [^>]*>$strongPunct<\/w>(.*)/ |
|
126 |
reg_word = /^(.*)<w .*<\/w>(.*)/ |
|
127 |
reg_corr_tags_no_seg = /^\s*(<($corr_tags_no_seg)( [^>\/]*)?>)\s*$/ |
|
128 |
reg_corr_tags_no_seg_alone = "<($corr_tags_no_seg)>" |
|
129 |
reg_corr_tags_no_seg2 = /^(.*)<\/($corr_tags_no_seg)>(.*)$/ |
|
130 |
reg_block_tags = /^(.*)<\/($div_tags|$q_tags)>(.*)$/ |
|
131 |
reg_block_tag_alone = "<($div_tags|$q_tags)>" |
|
119 | 132 |
} |
120 | 133 |
|
134 |
public TagSentences(TokenizerClasses tc) { |
|
135 |
|
|
136 |
/** The div_tags. */ |
|
137 |
div_tags = tc.div_tags; |
|
138 |
|
|
139 |
/** The q_tags. */ |
|
140 |
q_tags = tc.q_tags; |
|
141 |
|
|
142 |
/** The corr_tags_no_seg. */ |
|
143 |
corr_tags_no_seg = tc.corr_tags_no_seg; |
|
144 |
|
|
145 |
/** The corr_tags. */ |
|
146 |
corr_tags = tc.corr_tags; |
|
147 |
|
|
148 |
strongPunct = tc.punct_strong; |
|
149 |
|
|
150 |
reg_comment = /\A\s*<!--.*-->\s*\Z/ |
|
151 |
reg_out_of_sentence = /^(.*)<s( [^>]*)?>(.*)$/ |
|
152 |
reg_sentence_with_no_n_attribute = /<s( [^>]*)?>/ |
|
153 |
reg_end_of_sentence = /^(.*)<\/s>(.*)$/ |
|
154 |
reg_punct = /^(.*)<w type="pon"[^>]*>.*<\/w>(.*)$/ |
|
155 |
reg_strong_punct = /^(.*)<w [^>]*>$strongPunct<\/w>(.*)/ |
|
156 |
reg_word = /^(.*)<w .*<\/w>(.*)/ |
|
157 |
reg_corr_tags_no_seg = /^\s*(<($corr_tags_no_seg)( [^>\/]*)?>)\s*$/ |
|
158 |
reg_corr_tags_no_seg_alone = "<($corr_tags_no_seg)>" |
|
159 |
reg_corr_tags_no_seg2 = /^(.*)<\/($corr_tags_no_seg)>(.*)$/ |
|
160 |
reg_block_tags = /^(.*)<\/($div_tags|$q_tags)>(.*)$/ |
|
161 |
reg_block_tag_alone = "<($div_tags|$q_tags)>" |
|
162 |
} |
|
163 |
|
|
121 | 164 |
/* (non-Javadoc) |
122 | 165 |
* @see org.txm.importer.filters.Filter#SetUsedParam(java.lang.Object) |
123 | 166 |
*/ |
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/prototypes/stats/AFCMacro.groovy (revision 3385) | ||
---|---|---|
1 |
// STANDARD DECLARATIONS |
|
2 |
package org.txm.macro |
|
3 |
|
|
4 |
import org.kohsuke.args4j.* |
|
5 |
import groovy.transform.Field |
|
6 |
import org.txm.rcpapplication.swt.widget.parameters.* |
|
7 |
import org.txm.searchengine.cqp.clientExceptions.* |
|
8 |
import org.txm.searchengine.cqp.corpus.* |
|
9 |
import org.txm.searchengine.cqp.corpus.query.* |
|
10 |
import org.apache.commons.lang.time.StopWatch |
|
11 |
import java.util.Arrays |
|
12 |
import org.jfree.chart.renderer.xy.* |
|
13 |
import org.jfree.chart.renderer.* |
|
14 |
import org.jfree.chart.plot.* |
|
15 |
import org.jfree.data.xy.* |
|
16 |
import org.jfree.chart.axis.* |
|
17 |
import java.awt.*; |
|
18 |
import java.awt.geom.*; |
|
19 |
import org.jfree.chart.labels.* |
|
20 |
|
|
21 |
import org.txm.ca.core.chartsengine.jfreechart.themes.highcharts.renderers.* |
|
22 |
import org.txm.ca.rcp.editors.* |
|
23 |
import org.txm.libs.office.ReadODS |
|
24 |
import org.txm.ca.core.chartsengine.jfreechart.datasets.* |
|
25 |
import org.jfree.chart.renderer.AbstractRenderer |
|
26 |
|
|
27 |
println "editor: "+editor |
|
28 |
|
|
29 |
if (!(editor instanceof CAEditor)) { |
|
30 |
println "editor is not a CA editor: $editor, Run the macro with F12 when the editor is selected :-)" |
|
31 |
return |
|
32 |
} |
|
33 |
|
|
34 |
@Field @Option(name="patternsODSFile", usage="The starting word", widget="FileOpen", required=true, def='patterns.ods') |
|
35 |
def patternsODSFile |
|
36 |
@Field @Option(name="debug", usage="Show internal variable content", widget="StringArray", metaVar="OFF ON ALL REALLY ALL", required=true, def="OFF") |
|
37 |
debug |
|
38 |
|
|
39 |
// Open the parameters input dialog box |
|
40 |
if (!ParametersDialog.open(this)) return; |
|
41 |
if (debug == "OFF") debug = 0; else if (debug == "ON") debug = 1; else if (debug == "ALL") debug = 2 else if (debug == "REALLY ALL") debug = 3 |
|
42 |
|
|
43 |
if (!patternsODSFile.exists()) { |
|
44 |
println "Pattern file not found: $patternsODSFile" |
|
45 |
return false; |
|
46 |
} |
|
47 |
if (!patternsODSFile.isFile() || !patternsODSFile.getName().toLowerCase().endsWith(".ods")) { |
|
48 |
println "Wrong pattern file: $patternsODSFile" |
|
49 |
return false; |
|
50 |
} |
|
51 |
|
|
52 |
def data = ReadODS.toTable(patternsODSFile, "rows") |
|
53 |
def keys = data[0] |
|
54 |
def row_styles = [:] // reformat data |
|
55 |
for (int i = 1 ; i < data.size() ; i++) { |
|
56 |
def h = data[i] |
|
57 |
def style = [:] // create style entry |
|
58 |
String s = h[0]; |
|
59 |
row_styles[/$s/] = style // with a regexp pattern as key |
|
60 |
|
|
61 |
// fill the style |
|
62 |
for (int j = 1 ; j < h.size() ; j++) { |
|
63 |
style[keys[j]] = h[j] |
|
64 |
} |
|
65 |
} |
|
66 |
if (debug > 0) { |
|
67 |
println "ROW STYLES=$row_styles" |
|
68 |
} |
|
69 |
|
|
70 |
data = ReadODS.toTable(patternsODSFile, "cols") |
|
71 |
keys = data[0] |
|
72 |
def col_styles = [:] // reformat data |
|
73 |
for (int i = 1 ; i < data.size() ; i++) { |
|
74 |
def h = data[i] |
|
75 |
def style = [:] // create style entry |
|
76 |
String s = h[0]; |
|
77 |
col_styles[/$s/] = style // with a regexp pattern as key |
|
78 |
|
|
79 |
// fill the style |
|
80 |
for (int j = 1 ; j < h.size() ; j++) { |
|
81 |
style[keys[j]] = h[j] |
|
82 |
} |
|
83 |
} |
|
84 |
if (debug > 0) { |
|
85 |
println "COL STYLES=$col_styles" |
|
86 |
} |
|
87 |
|
|
88 |
ica = editor.getCA() |
|
89 |
ca = ica.getCA() |
|
90 |
|
|
91 |
// http://txm.sourceforge.net/javadoc/TXM/TBX/org/txm/stat/engine/r/function/CA.html |
|
92 |
|
|
93 |
// SOME DATA |
|
94 |
rows = ica.getRowNames() |
|
95 |
rowsinfo = ica.getRowInfos() |
|
96 |
rowscos2 = ca.getRowCos2() |
|
97 |
cols = ica.getColNames() |
|
98 |
println cols |
|
99 |
colssinfo = ica.getColInfos() |
|
100 |
colscos2 = ca.getColCos2() |
|
101 |
D1 = ica.getFirstDimension() -1; |
|
102 |
D2 = ica.getSecondDimension() -1; |
|
103 |
|
|
104 |
shapes = [:] |
|
105 |
shapes["square"] = AbstractRenderer.DEFAULT_SHAPE; |
|
106 |
shapes["circle"] = AbstractRenderer.DEFAULT_SHAPE; |
|
107 |
shapes["triangle"] = AbstractRenderer.DEFAULT_SHAPE; |
|
108 |
shapes["star"] = AbstractRenderer.DEFAULT_SHAPE; |
|
109 |
shapes["disk"] = AbstractRenderer.DEFAULT_SHAPE; |
|
110 |
|
|
111 |
// styles per col index in dataset |
|
112 |
// set col points label |
|
113 |
colLabelStyle = new HashMap<Integer, String>(); |
|
114 |
// set col points visibility |
|
115 |
colHiddenStyle = new HashSet<Integer>(); // true false |
|
116 |
// set col font size |
|
117 |
colFontSizeStyle = new HashMap<Integer, Integer>(); // 0.0 to 10.0 |
|
118 |
// set col points size |
|
119 |
colSizeStyle = new HashMap<Integer, Double>(); // 0.0 to 10.0 |
|
120 |
// set col points RGBA color |
|
121 |
colColorStyle = new HashMap<Integer, Color>(); |
|
122 |
// set col points shape (circle, square, triangle, ... + color ? + size ?) -> expert |
|
123 |
colShapeStyle = new HashMap<Integer, Shape>(); // circle, square, triangle, etc. |
|
124 |
|
|
125 |
|
|
126 |
rowLabelStyle = new HashMap<Integer, String>(); |
|
127 |
// set row points visibility |
|
128 |
rowHiddenStyle = new HashSet<Integer>(); // true false |
|
129 |
// set row font size |
|
130 |
rowFontSizeStyle = new HashMap<Integer, Integer>(); // 0.0 to 10.0 |
|
131 |
// set row points size |
|
132 |
rowSizeStyle = new HashMap<Integer, Double>(); // 0.0 to 10.0 |
|
133 |
// set row points RGBA color |
|
134 |
rowColorStyle = new HashMap<Integer, Color>(); |
|
135 |
// set row points shape (circle, square, triangle, ... + color ? + size ?) -> expert |
|
136 |
rowShapeStyle = new HashMap<Integer, Shape>(); // circle, square, triangle, etc. |
|
137 |
|
|
138 |
// prepare col style data for the dataset |
|
139 |
for (int i = 0 ; i < cols.length ; i++) { |
|
140 |
for (def p : col_styles.keySet()) { |
|
141 |
if (cols[i] ==~ p) { |
|
142 |
def style = col_styles[p] |
|
143 |
if (style["shape"] != null && shapes.containsKey(style["shape"])) { |
|
144 |
colShapeStyle[i] = shapes[style["shape"]] |
|
145 |
} |
|
146 |
if (style["color"] != null && style["color"].length() > 0 ) { |
|
147 |
colColorStyle[i] = new Color(Integer.parseInt(style["color"]), true) |
|
148 |
} |
|
149 |
if (style["label"] != null && style["label"].length() > 0) { |
|
150 |
colLabelStyle[i] = style["label"] |
|
151 |
} |
|
152 |
if (style["size"] != null && style["size"].length() > 0) { |
|
153 |
colSizeStyle[i] = Double.parseDouble(style["size"]) |
|
154 |
} |
|
155 |
if (style["font-size"] != null && style["font-size"].length() > 0) { |
|
156 |
colFontSizeStyle[i] = Integer.parseInt(style["font-size"]) |
|
157 |
} |
|
158 |
if (style["hidden"] != null && style["hidden"].toUpperCase() == "T") { |
|
159 |
colHiddenStyle << i |
|
160 |
} |
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
if (debug > 0) { |
|
165 |
println "COL COL=$colColorStyle" |
|
166 |
println "COL SHP=$colShapeStyle" |
|
167 |
println "COL LAB=$colLabelStyle" |
|
168 |
println "COL FONT-SIZ=$colFontSizeStyle" |
|
169 |
println "COL SIZ=$colSizeStyle" |
|
170 |
println "COL VIZ=$colHiddenStyle" |
|
171 |
} |
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
// UPDATE THE CHART RENDERER |
|
176 |
|
|
177 |
def chartEditor = editor.getEditors()[0] |
|
178 |
def chartComposite = chartEditor.getComposite() |
|
179 |
|
|
180 |
ddebug = debug |
|
181 |
monitor.syncExec( new Runnable() { |
|
182 |
public void run() { |
|
183 |
println chartComposite |
|
184 |
def chart = chartEditor.getChart(); |
|
185 |
|
|
186 |
//println "chart: "+chart |
|
187 |
//println "Plot: "+chart.getPlot() |
|
188 |
//println "Dataset: "+chart.getPlot().getDataset() |
|
189 |
//println "Renderer: "+chart.getPlot().getRenderer() |
|
190 |
|
|
191 |
def renderer = new CAItemSelectionRenderer(ica, chart) { |
|
192 |
Area EMPTYAREA = new Area() |
|
193 |
|
|
194 |
@Override |
|
195 |
public void initItemLabelGenerator() { |
|
196 |
XYItemLabelGenerator generator = new XYItemLabelGenerator() { |
|
197 |
|
|
198 |
@Override |
|
199 |
public String generateLabel(XYDataset dataset, int series, int item) { |
|
200 |
if (series == 0 && rowHiddenStyle.contains(item)) { |
|
201 |
if (ddebug > 1) println "HIDDING ROW LABEL '$item' '${rows[item]}'" |
|
202 |
return "" |
|
203 |
} else if (series == 1 && colHiddenStyle.contains(item)) { |
|
204 |
if (ddebug > 1) println "HIDDING COL LABEL '$item' '${cols[item]}'" |
|
205 |
return "" |
|
206 |
} else if (series == 0 && rowLabelStyle.containsKey(item)) { |
|
207 |
if (ddebug > 1) println "RENAME ROW LABEL '$item' '${rows[item]}' -> '${rowLabelStyle[item]}'" |
|
208 |
return rowLabelStyle[item] |
|
209 |
} else if (series == 1 && colLabelStyle.containsKey(item)) { |
|
210 |
if (ddebug > 1) println "RENAME COL LABEL '$item' '${cols[item]}' -> '${colLabelStyle[item]}'" |
|
211 |
return colLabelStyle[item] |
|
212 |
} else { |
|
213 |
CAXYDataset caDataset = (CAXYDataset) dataset; |
|
214 |
return caDataset.getLabel(series, item); |
|
215 |
} |
|
216 |
} |
|
217 |
}; |
|
218 |
|
|
219 |
this.setBaseItemLabelGenerator(generator); |
|
220 |
this.setBaseItemLabelsVisible(true); |
|
221 |
} |
|
222 |
|
|
223 |
@Override |
|
224 |
public Font getItemLabelFont(int series, int item) { |
|
225 |
Font d = super.getItemLabelFont(series, item); |
|
226 |
if (series == 0 && rowFontSizeStyle.containsKey(item)) { |
|
227 |
if (ddebug > 1) println "FIX ROW FONT-SIZE $item "+rows[item] |
|
228 |
return new Font(d.getFontName(), d.getStyle(), rowFontSizeStyle[item]); |
|
229 |
} else if (series == 1 && colFontSizeStyle.containsKey(item)) { |
|
230 |
if (ddebug > 1) println "FIX COL FONT-SIZE $item "+cols[item] |
|
231 |
return new Font(d.getFontName(), d.getStyle(), colFontSizeStyle[item]); |
|
232 |
} else { |
|
233 |
return d; |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
237 |
@Override |
|
238 |
public Shape getItemShape(int series, int item) { |
|
239 |
// Rows (series == 0), Cols (series == 1) |
|
240 |
if (series == 0 && rowHiddenStyle.contains(item)) { |
|
241 |
return EMPTYAREA; |
|
242 |
} else if (series == 1 && colHiddenStyle.contains(item)) { |
|
243 |
return EMPTYAREA; |
|
244 |
} else { |
|
245 |
AffineTransform t = new AffineTransform(); |
|
246 |
Shape shape = super.getItemShape(series, item); |
|
247 |
if (series == 0 && rowSizeStyle.containsKey(item)) { |
|
248 |
t.setToScale(rowSizeStyle.get(item), rowSizeStyle.get(item)); |
|
249 |
shape = t.createTransformedShape(shape); |
|
250 |
} else if (series == 1 && colSizeStyle.containsKey(item)) { |
|
251 |
t.setToScale(colSizeStyle.get(item), colSizeStyle.get(item)); |
|
252 |
shape = t.createTransformedShape(shape); |
|
253 |
} |
|
254 |
return shape; |
|
255 |
} |
|
256 |
} |
|
257 |
|
|
258 |
@Override |
|
259 |
public Paint getItemPaint(int series, int item) { |
|
260 |
if (series == 0 && rowColorStyle.containsKey(item)) { |
|
261 |
return rowColorStyle.get(item); |
|
262 |
} else if (series == 1 && colColorStyle.containsKey(item)) { |
|
263 |
return colColorStyle.get(item); |
|
264 |
} else { |
|
265 |
return super.getItemPaint(series, item); |
|
266 |
} |
|
267 |
} |
|
268 |
}; |
|
269 |
|
|
270 |
def cp = editor.editors[0].getChart(); |
|
271 |
renderer.chart = cp |
|
272 |
renderer.setSeriesVisible(0, ica.isShowVariables()); // Rows |
|
273 |
renderer.setSeriesVisible(1, ica.isShowIndividuals()); // Columns |
|
274 |
chart.getXYPlot().setRenderer(renderer) |
|
275 |
|
|
276 |
ica.getChartCreator().getChartsEngine().getJFCTheme().apply(chart); // need to be call AFTER setRenderer() cause this method changes some renderering parameters |
|
277 |
} |
|
278 |
}); |
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/prototypes/stats/PlotEllipsesMacro.groovy (revision 3385) | ||
---|---|---|
1 | 1 |
// STANDARD DECLARATIONS |
2 | 2 |
package org.txm.macro |
3 | 3 |
|
4 |
import org.kohsuke.args4j.* |
|
4 |
import org.txm.ca.core.functions.CA |
|
5 |
import org.txm.statsengine.r.core.RWorkspace |
|
5 | 6 |
import groovy.transform.Field |
6 |
import org.txm.rcpapplication.swt.widget.parameters.* |
|
7 |
import org.txm.functions.ca.CA |
|
8 |
import org.txm.stat.engine.r.RWorkspace |
|
9 | 7 |
// BEGINNING OF PARAMETERS |
10 | 8 |
|
11 | 9 |
if (!(corpusViewSelection instanceof CA)) { |
12 |
println "selection is not a CA. Please select a CA result in the Corpus view"
|
|
10 |
println "Selection is not a CA. Please select a CA result in the Corpus view"
|
|
13 | 11 |
return; |
14 | 12 |
} |
15 | 13 |
|
14 |
def ca = corpusViewSelection |
|
15 |
|
|
16 | 16 |
@Field @Option(name="outputFile", usage="an example file", widget="FileSave", required=true, def="file.svg") |
17 | 17 |
def outputFile |
18 | 18 |
|
... | ... | |
22 | 22 |
if (!ParametersDialog.open(this)) return; |
23 | 23 |
|
24 | 24 |
// END OF PARAMETERS |
25 |
def ca = corpusViewSelection |
|
26 |
def s = ca.getSymbol() |
|
25 |
|
|
26 |
def s = ca.getRSymbol()
|
|
27 | 27 |
def RW = RWorkspace.getRWorkspaceInstance() |
28 | 28 |
|
29 | 29 |
def script = """ |
Formats disponibles : Unified diff