Statistics
| Revision:

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

History | View | Annotate | Download (4.3 kB)

1 671 mdecorde
// Copyright © 2016 ENS de Lyon, CNRS, University of Franche-Comté
2 671 mdecorde
// Licensed under the terms of the GNU General Public License (http://www.gnu.org/licenses)
3 671 mdecorde
// @author mdecorde
4 671 mdecorde
// @author sheiden
5 671 mdecorde
// STANDARD DECLARATIONS
6 1217 mdecorde
package org.txm.macro.urs.edit
7 671 mdecorde
8 671 mdecorde
import org.apache.commons.lang.StringUtils
9 671 mdecorde
import org.kohsuke.args4j.*
10 671 mdecorde
11 671 mdecorde
import groovy.transform.Field
12 671 mdecorde
13 671 mdecorde
import org.txm.Toolbox
14 671 mdecorde
import org.txm.rcp.swt.widget.parameters.*
15 1217 mdecorde
import org.txm.annotation.urs.*
16 1217 mdecorde
import org.txm.macro.urs.AnalecUtils
17 671 mdecorde
import org.txm.searchengine.cqp.AbstractCqiClient
18 671 mdecorde
import org.txm.searchengine.cqp.corpus.*
19 1973 mdecorde
import org.txm.searchengine.cqp.corpus.query.CQLQuery
20 671 mdecorde
21 1973 mdecorde
import visuAnalec.donnees.Corpus
22 671 mdecorde
import visuAnalec.donnees.Structure
23 671 mdecorde
import visuAnalec.elements.*
24 671 mdecorde
import visuAnalec.vue.Vue
25 671 mdecorde
26 671 mdecorde
def scriptName = this.class.getSimpleName()
27 671 mdecorde
28 671 mdecorde
def selection = []
29 671 mdecorde
for (def s : corpusViewSelections) {
30 1094 mdecorde
        if (s instanceof CQPCorpus) selection << s
31 671 mdecorde
        else if (s instanceof Partition) selection.addAll(s.getParts())
32 671 mdecorde
}
33 671 mdecorde
34 671 mdecorde
if (selection.size() == 0) {
35 671 mdecorde
        println "** $scriptName: please select a Corpus or a Partition in the Corpus view: "+corpusViewSelections
36 671 mdecorde
        return false
37 671 mdecorde
}
38 671 mdecorde
39 671 mdecorde
// BEGINNING OF PARAMETERS
40 671 mdecorde
@Field @Option(name="schema_ursql", usage="TYPE@PROP=VALUE", widget="String", required=true, def="CHAINE")
41 671 mdecorde
                String schema_ursql
42 671 mdecorde
@Field @Option(name="minimum_schema_size", usage="Minimum size needed to consider a schema", widget="Integer", required=true, def="3")
43 671 mdecorde
                int minimum_schema_size
44 671 mdecorde
@Field @Option(name="unit_ursql", usage="TYPE@PROP=VALUE", widget="String", required=false, def="MENTION")
45 671 mdecorde
                String unit_ursql
46 1973 mdecorde
@Field @Option(name="limit_distance_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")
47 1973 mdecorde
                int limit_distance_in_schema
48 671 mdecorde
@Field @Option(name="limit_cql", usage="CQL to build structure limits", widget="Query", required=true, def="<div> [] expand to div")
49 671 mdecorde
                limit_cql
50 671 mdecorde
@Field @Option(name="strict_inclusion", usage="Units must be strictly included into corpus matches", widget="Boolean", required=true, def="true")
51 671 mdecorde
                boolean strict_inclusion
52 671 mdecorde
@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")
53 671 mdecorde
                int limit_distance
54 671 mdecorde
55 671 mdecorde
@Field @Option(name="unit_property_to_set", usage="PROP", widget="String", required=false, def="TESTPROP")
56 671 mdecorde
                String unit_property_to_set
57 671 mdecorde
@Field @Option(name="unit_property_value_to_set", usage="VALUE", widget="String", required=false, def="TESTVALUE")
58 671 mdecorde
                String unit_property_value_to_set
59 671 mdecorde
@Field @Option(name="debug", usage="Show internal variable content", widget="StringArray", metaVar="OFF        ON        ALL        REALLY ALL", required=true, def="OFF")
60 671 mdecorde
                debug
61 671 mdecorde
if (!ParametersDialog.open(this)) return
62 671 mdecorde
        if (debug == "OFF") debug = 0; else if (debug == "ON") debug = 1; else if (debug == "ALL") debug = 2 else if (debug == "REALLY ALL") debug = 3
63 671 mdecorde
64 671 mdecorde
if (unit_property_to_set.length() == 0) {
65 671 mdecorde
        println "unit_property_to_set not set: aborting."
66 671 mdecorde
}
67 671 mdecorde
68 671 mdecorde
//corpus = corpusViewSelection
69 671 mdecorde
def allResults = [:]
70 671 mdecorde
def errors = new HashSet()
71 671 mdecorde
for (def corpus : selection) {
72 671 mdecorde
        println "Annotate $corpus..."
73 671 mdecorde
74 1973 mdecorde
        def word = corpus.getWordProperty()
75 1973 mdecorde
        def analecCorpus = URSCorpora.getCorpus(corpus)
76 1973 mdecorde
        Vue analecView = URSCorpora.getVue(corpus)
77 671 mdecorde
        Structure structure = analecCorpus.getStructure()
78 671 mdecorde
79 671 mdecorde
        AnalecUtils.defineProperty(Unite.class, analecCorpus, unit_ursql, unit_property_to_set)
80 671 mdecorde
        analecView.initVueParDefaut()
81 671 mdecorde
82 671 mdecorde
        def selectedUnits = AnalecUtils.selectUnitsInSchema(debug, analecCorpus, corpus, schema_ursql, minimum_schema_size, Integer.MAX_VALUE,
83 1973 mdecorde
                        unit_ursql, limit_distance_in_schema, limit_cql, strict_inclusion, limit_distance);
84 1973 mdecorde
85 671 mdecorde
        println " "+selectedUnits.size()+" units to annotate..."
86 671 mdecorde
        def n = 0
87 671 mdecorde
        def nerrors = 0
88 671 mdecorde
        for (Unite unit : selectedUnits) {
89 671 mdecorde
90 671 mdecorde
                if (!analecView.setValeurChamp(unit, unit_property_to_set, unit_property_value_to_set)) {
91 671 mdecorde
                        errors << ""+unit.getDeb()+"->"+unit.getFin()
92 671 mdecorde
                        nerrors++
93 671 mdecorde
                } else {
94 671 mdecorde
                        n++
95 671 mdecorde
                }
96 671 mdecorde
        }
97 671 mdecorde
98 1973 mdecorde
        corpus.getMainCorpus().setIsModified(true)
99 671 mdecorde
        allResults[corpus] = selectedUnits
100 671 mdecorde
        println " $n valeurs affectées à $corpus"
101 671 mdecorde
        println " $nerrors erreurs lors de l'annotation de $corpus"
102 671 mdecorde
}
103 671 mdecorde
if (errors.size() > 0) {
104 671 mdecorde
        println " Errors while annotating $unit_property_to_set=$unit_property_value_to_set"
105 671 mdecorde
        println errors.join("\n")
106 671 mdecorde
}
107 671 mdecorde
return allResults