Statistics
| Revision:

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

History | View | Annotate | Download (2.2 kB)

1
package org.txm.macroproto;
2
import org.txm.*
3
import org.txm.functions.ca.*
4
import org.txm.searchengine.cqp.clientExceptions.*
5
import org.txm.searchengine.cqp.corpus.*
6
import org.txm.searchengine.cqp.corpus.query.*
7
import org.txm.stat.StatException
8
import org.txm.stat.data.*
9
import org.txm.stat.engine.r.*
10
import org.txm.functions.specificities.*
11
import org.kohsuke.args4j.*
12
import groovy.transform.Field
13
import org.txm.rcpapplication.swt.widget.parameters.*
14

    
15
//TODO: temporary uncommented
16
//if (!(corpusViewSelection instanceof SpecificitesResult)) {
17
//        println "Selection if not a Specificites Result"
18
//        return;
19
//}
20

    
21
// PARAMETERS
22
@Field @Option(name="outfile", usage="CSV result file ", widget="File", required=true, def="result.csv")
23
def outfile;// = new File("/home/mdecorde/Bureau/test.csv")
24

    
25
@Field @Option(name="MAX", usage="score limit", widget="Integer", required=false, def="1")
26
def MAX;// = 1.0
27

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

    
31
// END OF PARAMETERS
32
if (!ParametersDialog.open(this)) return;
33

    
34
if (suseSum == null || suseSum.length() == 0) suseSum = "n"
35
boolean useSum = suseSum.toLowerCase().charAt(0) == "y"
36
println "useSum $useSum"
37

    
38
def writer = outfile.newWriter("UTF-8")
39
def specif = corpusViewSelection
40
def indices = specif.getSpecificitesIndex()
41
def freqs = specif.getFrequency()
42
def rownames = specif.getTypeNames();
43
def colnames = specif.getPartShortNames() ;
44

    
45
def selected = []
46

    
47
writer.print "unit"
48
writer.print "\tF"
49
for (int j = 0; j < colnames.size() ; j++) {
50
        writer.print "\t"+colnames[j]
51
        writer.print "\tscore"
52
}
53
writer.println ""
54

    
55
for (int i = 0; i < rownames.length ; i++) {
56
        boolean add = true
57
        def totF = 0;
58
        def totscore = 0.0
59

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