Statistics
| Revision:

root / tmp / org.txm.analec.rcp / src / org / txm / macro / urs / exploit / mesures1 / StabilityScoreMacro.groovy @ 1962

History | View | Annotate | Download (3.3 kB)

1
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
2
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3
// @author mdecorde
4
// @author sheiden
5
// STANDARD DECLARATIONS
6
package org.txm.macro.urs.exploit.mesures1
7

    
8
import org.kohsuke.args4j.*
9
import groovy.transform.Field
10
import org.txm.*
11
import org.txm.rcp.swt.widget.parameters.*
12
import org.txm.annotation.urs.*
13
import org.txm.searchengine.cqp.corpus.*
14
import org.apache.commons.lang.StringUtils;
15

    
16
@Field @Option(name="schema_ursql", usage="TYPE@PROP=REGEX", widget="String", required=true, def="CHAINE")
17
String schema_ursql
18

    
19
@Field @Option(name="minimum_schema_size", usage="minimal schema size", widget="Integer", required=true, def="3")
20
int minimum_schema_size
21

    
22
@Field @Option(name="schema_display_property_name",usage="", widget="String", required=false, def="REF")
23
String schema_display_property_name
24

    
25
@Field @Option(name="unit_ursql", usage="TYPE@PROP=REGEX", widget="String", required=false, def="MENTION")
26
String unit_ursql
27

    
28
@Field @Option(name="word_property", usage="", widget="String", required=false, def="word")
29
String word_property
30

    
31
if (!(corpusViewSelection instanceof CQPCorpus)) {
32
        println "Corpora selection is not a Corpus"
33
        return;
34
}
35

    
36
// Open the parameters input dialog box
37
if (!ParametersDialog.open(this)) return;
38
// END OF PARAMETERS
39

    
40
def corpus = corpusViewSelection
41
def analecCorpus = URSCorpora.getCorpus(corpus)
42

    
43
if (!AnalecUtils.isPropertyDefined(Schema.class, analecCorpus, schema_ursql)) {
44
        println "** The $schema_ursql schema URSQL cannot be computed in the corpus."
45
        return;
46
}
47

    
48
if (!AnalecUtils.isPropertyDefined(Unite.class, analecCorpus, unit_ursql)) {
49
        println "** $unit_ursql unit URSQL cannot be computed in the corpus."
50
        return;
51
}
52

    
53
def CQI = CQPSearchEngine.getCqiClient()
54

    
55
def prop = corpus.getProperty(word_property)
56

    
57
def schemas = AnalecUtils.selectSchemasInCorpus(debug, analecCorpus, corpus, schema_ursql, minimum_schema_size, 999999);
58
allFormesSet = new HashSet();
59
nUnitesGrandTotal = 0;
60
def coefs = []
61
int n = 1
62
for (def schema : schemas) {
63
        def formesSet = new HashSet(); // contient toutes les formes du CR courant
64
        nUnitesTotal = 0;
65
        
66
        def allUnites = schema.getUnitesSousjacentesNonTriees()
67

    
68
        def units = AnalecUtils.filterElements(false, allUnites, unit_ursql)
69

    
70
        for (def unit : units) {
71
        
72
                String forme =  null;
73
                if (prop == null) { // word_property is the analec unit property to use
74
                        forme = unit.getProp(word_property)
75
                } else {
76
                        int[] pos = null;
77
                        if (unit.getDeb() == unit.getFin()) pos = [unit.getDeb()]
78
                        else pos = unit.getDeb()..unit.getFin()
79
                                
80
                        forme = StringUtils.join(CQI.cpos2Str(prop.getQualifiedName(), pos), " ") // ids is enough
81
                }
82
                
83
                formesSet.add(forme)
84
                
85
                nUnitesTotal++
86
        }
87
        if (formesSet.size() == 0) {
88
                coef = -1
89
        } else {
90
                coef = (nUnitesTotal/formesSet.size())
91
        }
92
        coefs << coef
93
        nUnitesGrandTotal += nUnitesTotal;
94
        allFormesSet.addAll(formesSet)
95
        
96
        if (schema_display_property_name != null) {
97
                print schema.getProp(schema_display_property_name)
98
        } else {
99
                print schema_ursql+"-"+n+" : "
100
        }
101
        
102
        println " ($nUnites units) : $nUnitesTotal selected units / ${formesSet.size()} forms = $coef"
103
        n++
104
}
105

    
106
return ["result":coefs, "data":["nUnitesTotal":nUnitesGrandTotal, "allFormesSet":allFormesSet], "coef":(nUnitesGrandTotal/allFormesSet.size())]