Révision 3970
TXM/trunk/bundles/org.txm.groovy.core/src/groovy/org/txm/macro/prototypes/SelectSpecifMacro.groovy (revision 3970) | ||
---|---|---|
87 | 87 |
for (def s : result.sort()) { |
88 | 88 |
buffer.append("|"+s.replace(".", "\\.").replace("|", "\\|")) |
89 | 89 |
} |
90 |
println buffer.toString().substring(1) |
|
90 |
println buffer.toString().substring(1) |
TXM/trunk/bundles/org.txm.groovy.core/src/groovy/org/txm/macro/stats/TopVocabularyMacro.groovy (revision 3970) | ||
---|---|---|
1 |
package org.txm.macro.stats |
|
2 |
// Copyright © 2010-2016 ENS de Lyon. |
|
3 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
4 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
5 |
// Sophia Antipolis, University of Paris 3. |
|
6 |
// @author mdecorde |
|
7 |
// @author sheiden |
|
8 |
// |
|
9 |
// The TXM platform is free software: you can redistribute it |
|
10 |
// and/or modify it under the terms of the GNU General Public |
|
11 |
// License as published by the Free Software Foundation, |
|
12 |
// either version 2 of the License, or (at your option) any |
|
13 |
// later version. |
|
14 |
// |
|
15 |
// The TXM platform is distributed in the hope that it will be |
|
16 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
17 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
18 |
// PURPOSE. See the GNU General Public License for more |
|
19 |
// details. |
|
20 |
// |
|
21 |
// You should have received a copy of the GNU General |
|
22 |
// Public License along with the TXM platform. If not, see |
|
23 |
// http://www.gnu.org/licenses. |
|
24 |
|
|
25 |
// This macro computes the basic vocabulary of a partition |
|
26 |
// given a specificities table. The result is saved in a |
|
27 |
// TSV file. |
|
28 |
|
|
29 |
import org.txm.Toolbox |
|
30 |
import org.txm.searchengine.cqp.clientExceptions.* |
|
31 |
import org.txm.searchengine.cqp.corpus.* |
|
32 |
import org.txm.searchengine.cqp.corpus.query.* |
|
33 |
import org.txm.statsengine.r.core.RWorkspace |
|
34 |
import org.kohsuke.args4j.* |
|
35 |
import groovy.transform.Field |
|
36 |
import org.txm.rcp.swt.widget.parameters.* |
|
37 |
import org.txm.specificities.core.functions.Specificities |
|
38 |
|
|
39 |
if (!(corpusViewSelection instanceof Specificities)) { |
|
40 |
println "** You need to select a Specificities result icon in the Corpus view before calling this macro. Aborting." |
|
41 |
return |
|
42 |
} |
|
43 |
|
|
44 |
// PARAMETERS |
|
45 |
|
|
46 |
@Field @Option(name="outputFile", usage="TSV result file", widget="String", required=true, def="top.tsv") |
|
47 |
def outputFile |
|
48 |
|
|
49 |
@Field @Option(name="nTop", usage="Number of words per column", widget="Integer", required=false, def="10") |
|
50 |
def nTop |
|
51 |
|
|
52 |
// END OF PARAMETERS |
|
53 |
if (!ParametersDialog.open(this)) return |
|
54 |
|
|
55 |
|
|
56 |
Specificities specif = corpusViewSelection |
|
57 |
def indices = specif.getSpecificitesIndices() |
|
58 |
def freqs = specif.getFrequencies() |
|
59 |
def rownames = specif.getRowNames() |
|
60 |
def colnames = specif.getColumnsNames() |
|
61 |
|
|
62 |
def output = new File(outputFile) |
|
63 |
def writer = output.newWriter("UTF-8") |
|
64 |
for (int j = 0; j < colnames.size() ; j++) { |
|
65 |
|
|
66 |
writer.println "## "+colnames[j] |
|
67 |
writer.println "unit\tF\tindice" |
|
68 |
|
|
69 |
def sorted = [] |
|
70 |
|
|
71 |
for (int i = 0; i < rownames.length ; i++) { |
|
72 |
sorted << [rownames[i], freqs[i][j], indices[i][j]] |
|
73 |
} |
|
74 |
|
|
75 |
sorted.sort() { -it[2]} |
|
76 |
|
|
77 |
for (int i = 0 ; i < nTop ; i++) { |
|
78 |
writer.println sorted[i].join("\t") |
|
79 |
} |
|
80 |
|
|
81 |
for (int i = nTop ; i >= 1 ; i--) { |
|
82 |
writer.println sorted[sorted.size() - i].join("\t") |
|
83 |
} |
|
84 |
|
|
85 |
writer.println "\n\n" |
|
86 |
} |
|
87 |
|
|
88 |
writer.close() |
|
89 |
println "Result: "+output.getAbsolutePath() |
|
90 |
|
TXM/trunk/bundles/org.txm.groovy.core/src/groovy/org/txm/macro/stats/SpecificVocabularyMacro.groovy (revision 3970) | ||
---|---|---|
1 |
package org.txm.macro.stats |
|
2 |
// Copyright © 2010-2016 ENS de Lyon. |
|
3 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
4 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
5 |
// Sophia Antipolis, University of Paris 3. |
|
6 |
// @author mdecorde |
|
7 |
// @author sheiden |
|
8 |
// |
|
9 |
// The TXM platform is free software: you can redistribute it |
|
10 |
// and/or modify it under the terms of the GNU General Public |
|
11 |
// License as published by the Free Software Foundation, |
|
12 |
// either version 2 of the License, or (at your option) any |
|
13 |
// later version. |
|
14 |
// |
|
15 |
// The TXM platform is distributed in the hope that it will be |
|
16 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
17 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
18 |
// PURPOSE. See the GNU General Public License for more |
|
19 |
// details. |
|
20 |
// |
|
21 |
// You should have received a copy of the GNU General |
|
22 |
// Public License along with the TXM platform. If not, see |
|
23 |
// http://www.gnu.org/licenses. |
|
24 |
|
|
25 |
// This macro computes the basic vocabulary of a partition |
|
26 |
// given a specificities table. The result is saved in a |
|
27 |
// TSV file. |
|
28 |
|
|
29 |
import org.txm.Toolbox |
|
30 |
import org.txm.searchengine.cqp.clientExceptions.* |
|
31 |
import org.txm.searchengine.cqp.corpus.* |
|
32 |
import org.txm.searchengine.cqp.corpus.query.* |
|
33 |
import org.txm.statsengine.r.core.RWorkspace |
|
34 |
import org.kohsuke.args4j.* |
|
35 |
import groovy.transform.Field |
|
36 |
import org.txm.rcp.swt.widget.parameters.* |
|
37 |
import org.txm.specificities.core.functions.Specificities |
|
38 |
import org.txm.libs.office.WriteODS |
|
39 |
|
|
40 |
if (!(corpusViewSelection instanceof Specificities)) { |
|
41 |
println "** You need to select a Specificities result icon in the Corpus view before calling this macro. Aborting." |
|
42 |
return |
|
43 |
} |
|
44 |
|
|
45 |
// PARAMETERS |
|
46 |
|
|
47 |
@Field @Option(name="outputFile", usage="TSV result file", widget="String", required=true, def="top.tsv") |
|
48 |
def outputFile |
|
49 |
|
|
50 |
@Field @Option(name="nTop", usage="Number of words per column", widget="Integer", required=false, def="10") |
|
51 |
def nTop |
|
52 |
|
|
53 |
@Field @Option(name="showPositiveIndices", usage="Show positive indices", widget="Boolean", required=false, def="true") |
|
54 |
def showPositiveIndices |
|
55 |
|
|
56 |
@Field @Option(name="showNegativeIndices", usage="Show negative indices", widget="Boolean", required=false, def="false") |
|
57 |
def showNegativeIndices |
|
58 |
|
|
59 |
// END OF PARAMETERS |
|
60 |
if (!ParametersDialog.open(this)) { return } |
|
61 |
|
|
62 |
if (!showPositiveIndices && !showNegativeIndices) { |
|
63 |
println "Select positive or/and negative indices. Aborting." |
|
64 |
return; |
|
65 |
} |
|
66 |
|
|
67 |
Specificities specif = corpusViewSelection |
|
68 |
def indices = specif.getSpecificitesIndices() |
|
69 |
def freqs = specif.getFrequencies() |
|
70 |
def rownames = specif.getRowNames() |
|
71 |
def colnames = specif.getColumnsNames() |
|
72 |
|
|
73 |
def allTopKeys = new LinkedHashSet() |
|
74 |
|
|
75 |
def output = new File(outputFile) |
|
76 |
def writer = output.newWriter("UTF-8") |
|
77 |
def allResults = new LinkedHashMap() |
|
78 |
for (int j = 0; j < colnames.size() ; j++) { |
|
79 |
|
|
80 |
writer.println "## "+colnames[j] |
|
81 |
writer.println "unit\tF\tindice" |
|
82 |
|
|
83 |
def sorted = [] |
|
84 |
def tops = [] |
|
85 |
for (int i = 0; i < rownames.length ; i++) { |
|
86 |
sorted << [rownames[i], freqs[i][j], indices[i][j]] |
|
87 |
} |
|
88 |
|
|
89 |
sorted.sort() { -it[2]} |
|
90 |
|
|
91 |
if (showPositiveIndices) { |
|
92 |
for (int i = 0 ; i < nTop ; i++) { |
|
93 |
writer.println sorted[i].join("\t") |
|
94 |
allTopKeys << rownames[i] |
|
95 |
tops << sorted[i] |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
if (showNegativeIndices) { |
|
100 |
if (showPositiveIndices) { |
|
101 |
writer.println "\n" |
|
102 |
tops << ["","",""] |
|
103 |
} |
|
104 |
|
|
105 |
for (int i = nTop ; i >= 1 ; i--) { |
|
106 |
writer.println sorted[sorted.size() - i].join("\t") |
|
107 |
allTopKeys << rownames[i] |
|
108 |
tops << sorted[sorted.size() - i] |
|
109 |
} |
|
110 |
} |
|
111 |
allResults[colnames[j]] = tops |
|
112 |
} |
|
113 |
|
|
114 |
writer.close() |
|
115 |
|
|
116 |
WriteODS odsWriter = new WriteODS(new File(output.getAbsolutePath()+".ods")) |
|
117 |
|
|
118 |
def firstLine = [] |
|
119 |
for (def c : colnames) { |
|
120 |
firstLine << c |
|
121 |
firstLine << "" |
|
122 |
firstLine << "" |
|
123 |
} |
|
124 |
odsWriter.writeLine(firstLine) |
|
125 |
|
|
126 |
int icol = 0; |
|
127 |
for (def c : colnames) { |
|
128 |
def cellRange = odsWriter.table.getCellRangeByPosition(icol, 1, icol+2, 1); |
|
129 |
cellRange.merge(); |
|
130 |
icol += 3; |
|
131 |
} |
|
132 |
|
|
133 |
firstLine = [] |
|
134 |
for (def c : colnames) { |
|
135 |
firstLine << "Unit" |
|
136 |
firstLine << "F" |
|
137 |
firstLine << "Indice" |
|
138 |
} |
|
139 |
odsWriter.writeLine(firstLine) |
|
140 |
|
|
141 |
println "write lines..." |
|
142 |
def lines = [] |
|
143 |
for (def col : allResults.keySet()) { |
|
144 |
iline = 0; |
|
145 |
for (def s : allResults[col]) { |
|
146 |
if (lines.size() == iline) lines << [] |
|
147 |
for (def ss : s) lines[iline] << ss |
|
148 |
iline++ |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
for (def line : lines) { |
|
153 |
odsWriter.writeLine(line) |
|
154 |
} |
|
155 |
|
|
156 |
|
|
157 |
odsWriter.save() |
|
158 |
|
|
159 |
println "Result: "+output.getAbsolutePath() |
|
160 |
|
Formats disponibles : Unified diff