Statistics
| Revision:

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

History | View | Annotate | Download (5.7 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

    
10
import groovy.transform.Field
11

    
12
import org.txm.*
13
import org.txm.rcp.swt.widget.parameters.*
14
import org.txm.annotation.urs.*
15
import org.txm.searchengine.cqp.corpus.*
16
import org.apache.commons.lang.StringUtils;
17

    
18
// BEGINNING OF PARAMETERS
19

    
20
@Field @Option(name="tsvFile",usage="", widget="FileSave", required=true, def="result.tsv")
21
File tsvFile
22
@Field @Option(name="default_schema_type",usage="", widget="String", required=true, def="CHAINE")
23
String default_schema_type
24
@Field @Option(name="default_minimum_schema_size", usage="", widget="Integer", required=true, def="3")
25
int default_minimum_schema_size
26
@Field @Option(name="default_schema_property_name",usage="", widget="String", required=false, def="")
27
String default_schema_property_name
28
@Field @Option(name="default_schema_property_value",usage="", widget="String", required=false, def=".*")
29
String default_schema_property_value
30
@Field @Option(name="schema_property_display_name",usage="", widget="String", required=false, def="REF")
31
String schema_property_display_name
32
@Field @Option(name="default_unit_type",usage="", widget="String", required=false, def="MENTION")
33
String default_unit_type
34
@Field @Option(name="default_unit_property_name", usage="", widget="String", required=false, def="")
35
String default_unit_property_name
36
@Field @Option(name="default_unit_property_value", usage="", widget="String", required=false, def=".*")
37
String default_unit_property_value
38
@Field @Option(name="default_word_property", usage="", widget="String", required=false, def="word")
39
String default_word_property
40
@Field @Option(name="default_pos_property", usage="", widget="String", required=false, def="CATEGORIE")
41
String default_pos_property
42

    
43
if (!ParametersDialog.open(this)) return;
44
// END OF PARAMETERS
45

    
46
println "Corpora selections: "+corpusViewSelections
47

    
48
table = [] // contains all table lines
49
mesures = []
50

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

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

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

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

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

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