Statistics
| Revision:

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

History | View | Annotate | Download (2.2 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.Specificities
8
import org.kohsuke.args4j.*
9
import groovy.transform.Field
10
import org.txm.rcp.swt.widget.parameters.*
11

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

    
17
@Field @Option(name="seuil", usage="score limit", widget="Integer", required=false, def="2.0")
18
def seuil;// = 1.0
19

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

    
23
// END OF PARAMETERS
24
if (!ParametersDialog.open(this)) return;
25

    
26
if (NombreDeMots <= 0) {
27
        println "Error: le nombre de mots est insuffisant."
28
        return
29
}
30
println "seuil $seuil"
31
println "NombreDeMots $NombreDeMots"
32

    
33

    
34
def specif = corpusViewSelection
35
def indices = specif.getSpecificitesIndex()
36
def rownames = specif.getTypeNames();
37
def colnames = specif.getPartShortNames() ;
38

    
39
def result = new HashSet<String>();
40

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

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