Statistics
| Revision:

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

History | View | Annotate | Download (4.4 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.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.rcp.swt.widget.parameters.*
15
import org.txm.annotation.urs.*
16
import org.txm.macro.urs.AnalecUtils
17
import org.txm.searchengine.cqp.AbstractCqiClient
18
import org.txm.searchengine.cqp.corpus.*
19
import org.txm.searchengine.cqp.corpus.query.CQLQuery
20

    
21
import visuAnalec.donnees.Corpus
22
import visuAnalec.donnees.Structure
23
import visuAnalec.elements.*
24
import visuAnalec.vue.Vue
25

    
26
def scriptName = this.class.getSimpleName()
27

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

    
34
if (selection.size() == 0) {
35
        println "** $scriptName: please select a Corpus or a Partition in the Corpus view: "+corpusViewSelections
36
        return false
37
} else {
38
        for (def c : selection) c.compute(false)
39
}
40

    
41
// BEGINNING OF PARAMETERS
42
@Field @Option(name="schema_ursql", usage="TYPE@PROP=VALUE", widget="String", required=true, def="CHAINE")
43
                String schema_ursql
44
@Field @Option(name="minimum_schema_size", usage="Minimum size needed to consider a schema", widget="Integer", required=true, def="3")
45
                int minimum_schema_size
46
@Field @Option(name="maximum_schema_size", usage="Maximum size needed to consider a schema", widget="Integer", required=true, def="9999999")
47
                int maximum_schema_size
48
@Field @Option(name="unit_ursql", usage="TYPE@PROP=VALUE", widget="String", required=false, def="MENTION")
49
                String unit_ursql
50
@Field @Option(name="position_in_schema", usage="Unit distance in schema (0 = no selection, 1 = first after limit, -1 = last before limit, etc.)", widget="Integer", required=true, def="0")
51
                int position_in_schema
52
@Field @Option(name="cql_limit", usage="CQL to build structure limits", widget="Query", required=false, def="<div> [] expand to div")
53
                cql_limit
54
@Field @Option(name="strict_inclusion", usage="Units must be strictly included into corpus matches", widget="Boolean", required=true, def="true")
55
                boolean strict_inclusion
56
@Field @Option(name="position_in_matches", usage="Unit distance to structure limit (0 = no selection, 1 = first after limit, -1 = last before limit, etc.)", widget="Integer", required=true, def="0")
57
                int position_in_matches
58
@Field @Option(name="property_name", usage="PROP", widget="String", required=false, def="TESTPROP")
59
                String property_name
60
@Field @Option(name="property_value", usage="VALUE", widget="String", required=false, def="TESTVALUE")
61
                String property_value
62
@Field @Option(name="debug", usage="Show internal variable content", widget="StringArray", metaVar="OFF        ON        ALL        REALLY ALL", required=true, def="OFF")
63
                debug
64
if (!ParametersDialog.open(this)) return
65
        if (debug == "OFF") debug = 0; else if (debug == "ON") debug = 1; else if (debug == "ALL") debug = 2 else if (debug == "REALLY ALL") debug = 3
66

    
67
if (property_name.length() == 0) {
68
        println "property_name not set: aborting."
69
}
70

    
71
//corpus = corpusViewSelection
72
def allResults = [:]
73
def errors = new HashSet()
74
for (def corpus : selection) {
75
        println "Annotating $corpus..."
76

    
77
        def word = corpus.getWordProperty()
78
        def analecCorpus = URSCorpora.getCorpus(corpus)
79
        Vue analecView = URSCorpora.getVue(corpus)
80
        Structure structure = analecCorpus.getStructure()
81

    
82
        AnalecUtils.defineProperty(Unite.class, analecCorpus, unit_ursql, property_name)
83
        analecView.initVueParDefaut()
84

    
85
        def selectedUnits = AnalecUtils.selectUnitsInSchema(debug, analecCorpus, corpus, schema_ursql, minimum_schema_size, maximum_schema_size,
86
                        unit_ursql, position_in_schema, cql_limit, strict_inclusion, position_in_matches);
87
                
88
        println " "+selectedUnits.size()+" units to annotate..."
89
        def n = 0
90
        def nerrors = 0
91
        for (Unite unit : selectedUnits) {
92
                
93
                if (!analecView.setValeurChamp(unit, property_name, property_value)) {
94
                        errors << ""+unit.getDeb()+"->"+unit.getFin()
95
                        nerrors++
96
                } else {
97
                        n++
98
                }
99
        }
100
        
101
        corpus.getMainCorpus().setIsModified(true)
102
        allResults[corpus] = selectedUnits
103
        println " $n valeurs affectées à $corpus"
104
        println " $nerrors erreurs lors de l'annotation de $corpus"
105
}
106
if (errors.size() > 0) {
107
        println " Errors while annotating $property_name=$property_value"
108
        println errors.join("\n")
109
}
110
return allResults