Statistics
| Revision:

root / tmp / org.txm.analec.rcp / src / org / txm / macro / analec / edit / UnitsAnnotateMacro.groovy @ 1094

History | View | Annotate | Download (4.1 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.analec.edit
7

    
8
import org.apache.commons.lang.StringUtils
9
import org.kohsuke.args4j.*
10

    
11
import groovy.transform.Field
12

    
13
import org.txm.Toolbox
14
import org.txm.macro.analec.AnalecUtils;
15
import org.txm.rcp.swt.widget.parameters.*
16
import org.txm.analec.*
17
import org.txm.searchengine.cqp.AbstractCqiClient
18
import org.txm.searchengine.cqp.corpus.*
19

    
20
import visuAnalec.donnees.Structure
21
import visuAnalec.elements.*
22
import visuAnalec.vue.Vue
23

    
24
def scriptName = this.class.getSimpleName()
25

    
26
def selection = []
27
for (def s : corpusViewSelections) {
28
        if (s instanceof CQPCorpus) selection << s
29
        else if (s instanceof Partition) selection.addAll(s.getParts())
30
}
31

    
32
if (selection.size() == 0) {
33
        println "** $scriptName: please select a Corpus or a Partition in the Corpus view: "+corpusViewSelections
34
        return false
35
}
36

    
37
// BEGINNING OF PARAMETERS
38
@Field @Option(name="schema_ursql", usage="TYPE@PROP=VALUE", widget="String", required=true, def="CHAINE")
39
                String schema_ursql
40
@Field @Option(name="minimum_schema_size", usage="Minimum size needed to consider a schema", widget="Integer", required=true, def="3")
41
                int minimum_schema_size
42
@Field @Option(name="unit_ursql", usage="TYPE@PROP=VALUE", widget="String", required=false, def="MENTION")
43
                String unit_ursql
44
@Field @Option(name="limit_cql", usage="CQL to build structure limits", widget="Query", required=true, def="<div> [] expand to div")
45
                limit_cql
46
@Field @Option(name="strict_inclusion", usage="Units must be strictly included into corpus matches", widget="Boolean", required=true, def="true")
47
                boolean strict_inclusion
48
@Field @Option(name="limit_distance", usage="Unit distance to structure limit (0 = no selection, 1 = first after limit, -1 = last before limit, etc.)", widget="Integer", required=true, def="0")
49
                int limit_distance
50

    
51
@Field @Option(name="unit_property_to_set", usage="PROP", widget="String", required=false, def="TESTPROP")
52
                String unit_property_to_set
53
@Field @Option(name="unit_property_value_to_set", usage="VALUE", widget="String", required=false, def="TESTVALUE")
54
                String unit_property_value_to_set
55
@Field @Option(name="debug", usage="Show internal variable content", widget="StringArray", metaVar="OFF        ON        ALL        REALLY ALL", required=true, def="OFF")
56
                debug
57
if (!ParametersDialog.open(this)) return
58
        if (debug == "OFF") debug = 0; else if (debug == "ON") debug = 1; else if (debug == "ALL") debug = 2 else if (debug == "REALLY ALL") debug = 3
59

    
60
def CQI = CQPSearchEngine.getCqiClient()
61

    
62
if (unit_property_to_set.length() == 0) {
63
        println "unit_property_to_set not set: aborting."
64
}
65

    
66
//corpus = corpusViewSelection
67
def allResults = [:]
68
def errors = new HashSet()
69
for (def corpus : selection) {
70
        println "Annotate $corpus..."
71
        MainCorpus mainCorpus = corpus.getMainCorpus()
72

    
73
        def word = mainCorpus.getWordProperty()
74
        def analecCorpus = AnalecCorpora.getCorpus(mainCorpus.getName())
75
        Vue analecView = AnalecCorpora.getVue(mainCorpus.getName())
76
        Structure structure = analecCorpus.getStructure()
77

    
78
        AnalecUtils.defineProperty(Unite.class, analecCorpus, unit_ursql, unit_property_to_set)
79
        analecView.initVueParDefaut()
80

    
81
        def selectedUnits = AnalecUtils.selectUnitsInSchema(debug, analecCorpus, corpus, schema_ursql, minimum_schema_size, Integer.MAX_VALUE,
82
                        unit_ursql, limit_cql, strict_inclusion, limit_distance);
83
        println " "+selectedUnits.size()+" units to annotate..."
84
        def n = 0
85
        def nerrors = 0
86
        for (Unite unit : selectedUnits) {
87
                
88
                if (!analecView.setValeurChamp(unit, unit_property_to_set, unit_property_value_to_set)) {
89
                        errors << ""+unit.getDeb()+"->"+unit.getFin()
90
                        nerrors++
91
                } else {
92
                        n++
93
                }
94
        }
95
        
96
        mainCorpus.setIsModified(true)
97
        allResults[corpus] = selectedUnits
98
        println " $n valeurs affectées à $corpus"
99
        println " $nerrors erreurs lors de l'annotation de $corpus"
100
}
101
if (errors.size() > 0) {
102
        println " Errors while annotating $unit_property_to_set=$unit_property_value_to_set"
103
        println errors.join("\n")
104
}
105
return allResults