Statistics
| Revision:

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

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

    
23
@Field @Option(name="default_schema_ursql", usage="TYPE@PROP=REGEX", widget="String", required=true, def="CHAINE")
24
String default_schema_ursql
25

    
26
@Field @Option(name="default_minimum_schema_size", usage="", widget="Integer", required=true, def="3")
27
int default_minimum_schema_size
28

    
29

    
30
@Field @Option(name="schema_property_display_name",usage="", widget="String", required=false, def="REF")
31
String schema_property_display_name
32

    
33
@Field @Option(name="default_unit_ursql", usage="TYPE@PROP=REGEX", widget="String", required=false, def="MENTION")
34
String default_unit_ursql
35

    
36
@Field @Option(name="default_word_property", usage="", widget="String", required=false, def="word")
37
String default_word_property
38
@Field @Option(name="default_pos_property", usage="", widget="String", required=false, def="CATEGORIE")
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.getID() // 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_ursql":default_unit_ursql,
58
        ]
59
        returnedValue = execMesure(ReferentialDensityMacro, line, corpus, params)
60
        line << returnedValue["result"]
61
        
62
        params = [
63
                "schema_ursql":default_schema_ursql,
64
                "minimum_schema_size":default_minimum_schema_size,
65
                "unit_ursql":default_unit_ursql,
66
        ]
67
        returnedValue = execMesure(MeanDistanceMacro, line, corpus, params)
68
        line << returnedValue["result"]
69
        
70
        params = [
71
                "schema_ursql":default_schema_ursql,
72
                "minimum_schema_size":default_minimum_schema_size,
73
                "unit_ursql":default_unit_ursql,
74
        ]
75
        returnedValue = execMesure(NumberOfSchemaMacro, line, corpus, params)
76
        line << returnedValue["result"]
77
        
78
        params = [
79
                "schema_ursql":default_schema_ursql,
80
                "minimum_schema_size":default_minimum_schema_size,
81
                "schema_property_display_name":schema_property_display_name,
82
                "unit_ursql":default_unit_ursql+"@CATEGORIE=GN Défini|GN Démonstratif|Nom Propre",
83
                "word_property":default_word_property,
84
        ]
85
        returnedValue = execMesure(StabilityScoreMacro, line, corpus, params)
86
        line << returnedValue["result"]
87
        
88
        params = [
89
                "schema_ursql":default_schema_ursql,
90
                "minimum_schema_size":default_minimum_schema_size,
91
                "unit_ursql":default_unit_ursql,
92
        ]
93
        returnedValue = execMesure(InterDistanceMacro, line, corpus, params)
94
        line << returnedValue["result"]
95

    
96
        params = [
97
                "schema_ursql":default_schema_ursql,
98
                "minimum_schema_size":default_minimum_schema_size,
99
                "unit_ursql":default_unit_ursql,
100
                "word_property":default_pos_property,
101
        ]
102
        returnedValue = execMesure(NatureOfTheFirstUnitMacro, line, corpus, params)
103
        line << returnedValue["data"]
104
        
105
        params = [
106
                "schema_ursql":default_schema_ursql,
107
                "minimum_schema_size":default_minimum_schema_size,
108
                "schema_property_display_name":schema_property_display_name,
109
                "unit_ursql":default_unit_ursql,
110
                "word_property":default_pos_property,
111
        ]
112
        returnedValue = execMesure(GrammaticalCategoryMacro, line, corpus, params)
113
        line << returnedValue["data"]
114
}
115

    
116
// WRITE RESULTS IN THE TSV FILE
117
tsvFile.withWriter("UTF-8") { writer ->
118
        writer.println "\t"+mesures.join("\t")
119
        table.each { line -> writer.println line.join("\t")        }
120
}
121

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

    
124
// UTILITY FUNCTIONS
125
def execMesure(def mesure, def line, def corpus, def params) {
126
        def m = mesure.getSimpleName().substring(0, mesure.getSimpleName().indexOf("Macro"))
127
        mesures << m
128
        println "***** ${mesures.size()}- $m with parameters: $params"
129
        def r = gse.run(mesure, ["args":params, "corpusViewSelection":corpus, "monitor":monitor])
130
        if (r == null) throw new Exception("Null result");
131
        return r;
132
}