Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macroproto / SelectBanal.groovy @ 479

History | View | Annotate | Download (2.1 kB)

1
package org.txm.macroproto;
2
import org.txm.Toolbox
3
import org.txm.searchengine.cqp.clientExceptions.*
4
import org.txm.searchengine.cqp.corpus.*
5
import org.txm.searchengine.cqp.corpus.query.*
6
import org.txm.statsengine.r.core.RWorkspace
7
import org.txm.specificities.core.functions.SpecificitesResult
8
import org.kohsuke.args4j.*
9
import groovy.transform.Field
10
import org.txm.rcpapplication.swt.widget.parameters.*
11

    
12
if (!(corpusViewSelection instanceof SpecificitesResult)) {
13
        println "Selection if not a Specificites Result"
14
        return;
15
}
16

    
17
// PARAMETERS
18
@Field @Option(name="outfile", usage="CSV result file ", widget="File", required=true, def="result.csv")
19
def outfile;// = new File("/home/mdecorde/Bureau/test.csv")
20

    
21
@Field @Option(name="MAX", usage="score limit", widget="Integer", required=false, def="1")
22
def MAX;// = 1.0
23

    
24
@Field @Option(name="suseSum", usage="Use the row sums : y/n", widget="String", required=false, def="n")
25
String suseSum;// = false
26

    
27
// END OF PARAMETERS
28
if (!ParametersDialog.open(this)) return;
29

    
30
if (suseSum == null || suseSum.length() == 0) suseSum = "n"
31
boolean useSum = suseSum.toLowerCase().charAt(0) == "y"
32
println "useSum $useSum"
33

    
34
def writer = outfile.newWriter("UTF-8")
35
def specif = corpusViewSelection
36
def indices = specif.getSpecificitesIndex()
37
def freqs = specif.getFrequency()
38
def rownames = specif.getTypeNames();
39
def colnames = specif.getPartShortNames() ;
40

    
41
def selected = []
42

    
43
writer.print "unit"
44
writer.print "\tF"
45
for (int j = 0; j < colnames.size() ; j++) {
46
        writer.print "\t"+colnames[j]
47
        writer.print "\tscore"
48
}
49
writer.println ""
50

    
51
for (int i = 0; i < rownames.length ; i++) {
52
        boolean add = true
53
        def totF = 0;
54
        def totscore = 0.0
55

    
56
        for (int j = 0; j < colnames.size() ; j++) {
57
                if (Math.abs(indices[i][j]) >= MAX) add = false
58
                totF += freqs[i][j]
59
                totscore += Math.abs(indices[i][j])
60
        }
61
        
62
        if (useSum) {
63
                if (totscore >= MAX) add = false
64
                else add = true
65
        }
66
        
67
        if (add) {
68
                selected << rownames[i]
69
                writer.print rownames[i]
70
                writer.print "\t$totF"
71
                for (int j = 0; j < colnames.size() ; j++) {
72
                        writer.print "\t"+freqs[i][j]
73
                        writer.print "\t"+indices[i][j]
74
                }
75
                writer.println ""
76
        }
77
}
78
println selected
79
println "Saved in $outfile"
80
writer.close()