Statistics
| Revision:

root / tmp / org.txm.analec.rcp / src / org / txm / macro / urs / AllMesuresMacro.groovy @ 1217

History | View | Annotate | Download (5.8 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
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
// BEGINNING OF PARAMETERS
17

    
18
@Field @Option(name="tsvFile",usage="", widget="FileSave", required=true, def="result.tsv")
19
File tsvFile
20
@Field @Option(name="default_schema_type",usage="", widget="String", required=true, def="Coréférence")
21
String default_schema_type
22
@Field @Option(name="default_minimum_schema_size", usage="", widget="Integer", required=true, def="3")
23
int default_minimum_schema_size
24
@Field @Option(name="default_schema_property_name",usage="", widget="String", required=false, def="")
25
String default_schema_property_name
26
@Field @Option(name="default_schema_property_value",usage="", widget="String", required=false, def=".*")
27
String default_schema_property_value
28
@Field @Option(name="schema_display_property_name",usage="", widget="String", required=false, def="Nom du référent")
29
String schema_display_property_name
30
@Field @Option(name="default_unit_type",usage="", widget="String", required=false, def="Maillon")
31
String default_unit_type
32
@Field @Option(name="default_unit_property_name", usage="", widget="String", required=false, def="")
33
String default_unit_property_name
34
@Field @Option(name="default_unit_property_value", usage="", widget="String", required=false, def=".*")
35
String default_unit_property_value
36
@Field @Option(name="default_word_property", usage="", widget="StringArray", metaVar="word        lemma        frlemma        frolemma #forme#", required=false, def="word")
37
String default_word_property
38
@Field @Option(name="default_pos_property", usage="", widget="StringArray", metaVar="Catégorie        pos        fropos        frpos", required=false, def="Catégorie")
39
String default_pos_property
40

    
41
if (!ParametersDialog.open(this)) return;
42
// END OF PARAMETERS
43

    
44
println "Corpora selections: "+corpusViewSelections
45

    
46
table = [] // contains all table lines
47
mesures = []
48

    
49
for (def corpus : corpusViewSelections) { // for each corpus selected in the corpora view
50
        if (!(corpus instanceof MainCorpus)) continue; // check if the corpus is a maincorpus
51
        def line = [] ; table << line // create and add a new table line
52
        line << corpus.getName() // add the corpus name in the first column
53
        
54
        println "*** Computing mesures for $corpus" // each macro return a "result" and a "data"
55

    
56
        params = [
57
                "unit_type":default_unit_type,
58
                "unit_property_name":"",
59
                "unit_property_value":"",
60
        ]
61
        returnedValue = execMesure(DensiteReferentielleMacro, line, corpus, params)
62
        line << returnedValue["result"]
63
        
64
        params = [
65
                "schema_type":default_schema_type,
66
                "minimum_schema_size":default_minimum_schema_size,
67
                "schema_property_name":"",
68
                "schema_property_value":"",
69
                "unit_type":default_unit_type,
70
                "unit_property_name":"",
71
                "unit_property_value":"",
72
        ]
73
        returnedValue = execMesure(LongueurMoyenneMacro, line, corpus, params)
74
        line << returnedValue["result"]
75
        
76
        params = [
77
                "schema_type":default_schema_type,
78
                "minimum_schema_size":default_minimum_schema_size,
79
                "schema_property_name":"",
80
                "schema_property_value":"",
81
                "unit_type":default_unit_type,
82
                "unit_property_name":"",
83
                "unit_property_value":"",
84
        ]
85
        returnedValue = execMesure(NombreDeChainesMacro, line, corpus, params)
86
        line << returnedValue["result"]
87
        
88
        params = [
89
                "schema_type":default_schema_type,
90
                "minimum_schema_size":default_minimum_schema_size,
91
                "schema_property_name":"",
92
                "schema_property_value":"",
93
                "schema_display_property_name":schema_display_property_name,
94
                "unit_type":default_unit_type,
95
                "unit_property_name":"Catégorie",
96
                "unit_property_value":"GN Défini|GN Démonstratif|Nom Propre",
97
                "word_property":default_word_property,
98
        ]
99
        returnedValue = execMesure(CoefficientStabiliteMacro, line, corpus, params)
100
        line << returnedValue["result"]
101
        
102
        params = [
103
                "schema_type":default_schema_type,
104
                "minimum_schema_size":default_minimum_schema_size,
105
                "schema_property_name":"",
106
                "schema_property_value":"",
107
                "unit_type":default_unit_type,
108
                "unit_property_name":"",
109
                "unit_property_value":"",
110
        ]
111
        returnedValue = execMesure(DistanceInterMaillonnaireMacro, line, corpus, params)
112
        line << returnedValue["result"]
113

    
114
        params = [
115
                "schema_type":default_schema_type,
116
                "minimum_schema_size":default_minimum_schema_size,
117
                "schema_property_name":"",
118
                "schema_property_value":"",
119
                "unit_type":default_unit_type,
120
                "unit_property_name":"",
121
                "unit_property_value":"",
122
                "word_property":default_pos_property,
123
        ]
124
        returnedValue = execMesure(NatureDuPremierMaillonMacro, line, corpus, params)
125
        line << returnedValue["data"]
126
        
127
        params = [
128
                "schema_type":default_schema_type,
129
                "minimum_schema_size":default_minimum_schema_size,
130
                "schema_property_name":"",
131
                "schema_property_value":"",
132
                "schema_display_property_name":schema_display_property_name,
133
                "unit_type":default_unit_type,
134
                "unit_property_name":"",
135
                "unit_property_value":"",
136
                "word_property":default_pos_property,
137
        ]
138
        returnedValue = execMesure(CategorieGrammaticaleMacro, line, corpus, params)
139
        line << returnedValue["data"]
140
}
141

    
142
// WRITE RESULTS IN THE TSV FILE
143
tsvFile.withWriter("UTF-8") { writer ->
144
        writer.println "\t"+mesures.join("\t")
145
        table.each { line -> writer.println line.join("\t")        }
146
}
147

    
148
println "Done. Results are saved in ${tsvFile.getAbsolutePath()} file."
149

    
150
// UTILITY FUNCTIONS
151
def execMesure(def mesure, def line, def corpus, def params) {
152
        def m = mesure.getSimpleName().substring(0, mesure.getSimpleName().indexOf("Macro"))
153
        mesures << m
154
        println "***** ${mesures.size()}- $m with parameters: $params"
155
        def r = gse.run(mesure, ["args":params, "corpusViewSelection":corpus, "monitor":monitor])
156
        if (r == null) throw new Exception("Null result");
157
        return r;
158
}