Statistics
| Revision:

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

History | View | Annotate | Download (2.3 kB)

1
package org.txm.macroproto;
2
import org.txm.Toolbox
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.*
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
@Field @Option(name="seuil", usage="score limit", widget="Integer", required=false, def="2.0")
22
def seuil;// = 1.0
23

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

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

    
30
if (NombreDeMots <= 0) {
31
        println "Error: le nombre de mots est insuffisant."
32
        return
33
}
34
println "seuil $seuil"
35
println "NombreDeMots $NombreDeMots"
36

    
37

    
38
def specif = corpusViewSelection
39
def indices = specif.getSpecificitesIndex()
40
def rownames = specif.getTypeNames();
41
def colnames = specif.getPartShortNames() ;
42

    
43
def result = new HashSet<String>();
44

    
45
// for each specif column find the N first indices
46
for (int i = 0; i < colnames.size() ; i++) {
47
        
48
        // get indices
49
        def idx = []
50
        for (int i2 = 0 ; i2 < rownames.length ; i2++) {
51
                idx << [indices[i2][i], rownames[i2]];
52
        }
53
        
54
        // sort indices
55
//        idx = idx.sort(true, new Comparator() {
56
//                int compare(def o1, def o2) {
57
//                        if (o1 == o2) return 0;
58
//                        return o1[0] - o2[0]
59
//                }
60
//        });
61
//        
62
//        idx = idx.reverse();
63
        
64
        def idxsorted = [];
65
        for (def o : idx) {
66
                //if (idxsorted.size() > 0)
67
                for (int i4 = 0 ; i4 < idxsorted.size() ; i4++) {
68
                        if (idxsorted[i4][0] < o[0]) {
69
                                idxsorted.add(i4, o)
70
                                break;
71
                        }
72
                }
73
                idxsorted << o
74
        }
75
        idx = idxsorted
76
        
77
        //println idx
78
        // get N first indices
79
        int N = 0
80
        for (def i3 : idx) {
81
                result.add(i3[1]) // add index in result
82
                N++
83
                if (N >= NombreDeMots) break;
84
                if (i3[0] < seuil) break;
85
        }
86
        println "Selection de $N dans "+colnames[i]
87
}
88

    
89
println "Fin de la sélection des spécificités : "+result.size()
90
StringBuffer buffer = new StringBuffer();
91
for (def s : result.sort()) {
92
        buffer.append("|"+s.replace(".", "\\.").replace("|", "\\|"))
93
}
94
println buffer.toString().substring(1)