Statistics
| Revision:

root / tmp / org.txm.analec.rcp / src / org / txm / macro / urs / edit / AjoutDefinitudeMacro.groovy @ 1217

History | View | Annotate | Download (4.2 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.searchengine.cqp.AbstractCqiClient;
17
import org.txm.searchengine.cqp.corpus.*
18

    
19
import visuAnalec.Message.StructureEvent;
20
import visuAnalec.Message.TypeModifStructure;
21
import visuAnalec.donnees.Structure;
22
import visuAnalec.elements.Unite;
23
import visuAnalec.vue.Vue
24

    
25
if (!(corpusViewSelection instanceof MainCorpus)) {
26
        println "Corpora selection is not a Corpus"
27
        return;
28
}
29

    
30
// BEGINNING OF PARAMETERS
31
@Field @Option(name="unit_type",usage="", widget="String", required=true, def="Maillon")
32
String unit_type
33
@Field @Option(name="reset",usage="", widget="Boolean", required=true, def="true")
34
boolean reset
35

    
36
if (!ParametersDialog.open(this)) return;
37

    
38
MainCorpus corpus = corpusViewSelection
39
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
40
def word = corpus.getWordProperty()
41
def analecCorpus = URSCorpora.getCorpus(corpus);
42
Structure structure = analecCorpus.getStructure()
43
if (!structure.getUnites().contains(unit_type)) { // check if the structure contains the unit_type units
44
        println "Error: corpus structure does not contains unit with name=$unit_type"
45
        return
46
}
47
def props = structure.getUniteProperties(unit_type)
48

    
49
String DEFINITUDE = "DEFINITUDE"
50
if (!props.contains(DEFINITUDE)) { // update the structure if needed
51
        analecCorpus.ajouterProp(Unite.class, unit_type, DEFINITUDE);
52
        analecCorpus.ajouterVal(Unite.class, unit_type, DEFINITUDE, "DEFINI");
53
        analecCorpus.ajouterVal(Unite.class, unit_type, DEFINITUDE, "INDEFINI");
54
        analecCorpus.ajouterVal(Unite.class, unit_type, DEFINITUDE, "DEMONSTRATIF");
55
        analecCorpus.ajouterVal(Unite.class, unit_type, DEFINITUDE, "AMBIGU");
56
        analecCorpus.ajouterVal(Unite.class, unit_type, DEFINITUDE, "NONE");
57
}
58

    
59
int nIgnored = 0 // number of ignored units
60
int nModified = 0 // number of modified units
61
int nDefini = 0 // number of "DEFINI" units
62
int nIndefini = 0 // number of "InDEFINI" units
63
int nDemonstratif = 0 // number of "DEMONSTRATIF" units
64
int nAmbigu = 0 // number of "AMBIGU" units
65
int nNone = 0 // number of "NONE" units
66

    
67
def units = analecCorpus.getUnites(unit_type)
68
units = units.sort() { a, b -> a.getDeb() <=> b.getDeb() ?: a.getFin() <=> b.getFin() }
69
for (Unite unit : units) { // process all units
70
        
71
        def prop = unit.getProp(DEFINITUDE);
72
        
73
        int[] pos = null
74
        if (unit.getDeb() == unit.getFin()) pos = [unit.getDeb()]
75
        else pos = (unit.getDeb()..unit.getFin())
76
        def form = StringUtils.join(CQI.cpos2Str(word.getQualifiedName(), pos), " ")
77
        
78
        if (reset || prop == null || prop.length() == 0 || prop.equals("NONE")) {
79
                // petits ajouts à faire ? : |(ses\s.+)|(Ses\s.+)|(son\s.+)|(Son\s.+)|(sa\s.+)|(Sa\s.+)|(leurs?\s.+)|(Leurs?\s.+)|(tous\s.+)|(Tous\s.+)|(toutes\s.+)|(Toutes\s.+)
80
                if (form =~ /^(le\s.+)|(Les\s.+)|(Le\s.+)|(la\s.+)|(La\s.+)|(l'.+)|(L'.+)|(les\s.+)|(au\s.+)|(Au\s.+)|(aux\s.+)|(Aux\s.+)|(du\s.+)|(Du\s.+)/) {
81
                        unit.getProps().put(DEFINITUDE, "DEFINI")
82
                        nDefini++
83
                } else if (form =~ /^(un\s.+)|(une\s.+)|(Un\s.+)|(Une\s.+)|(Chaque\s.+)|(chaque\s.+)|(Certains\s.+)|(Certaines\s.+)|(certains\s.+)|(certaines\s.+)|(aucun\s.+)|(aucune\s.+)|(Aucun\s.+)|(Aucunes\s.+)|(Autre\s.+)|(Autre\s.+)|(autres\s.+)|(autre\s.+)|(quelque\s.+)|(quelques\s.+)|(Quelque\s.+)|(Quelques\s.+)/) {
84
                        unit.getProps().put(DEFINITUDE, "INDEFINI")
85
                        nIndefini++
86
                } else if (form =~ /^(ce\s.+)|(cette\s.+)|(Cette\s.+)|(cet\s.+)|(ces\s.+)|(Ce\s.+)|(Cet\s.+)|(Ces\s.+)/) {
87
                        unit.getProps().put(DEFINITUDE, "DEMONSTRATIF")
88
                        nDemonstratif++
89
                } else if (form =~ /^(des\s.+)|(de\s.+)|(Des\s.+)|(De\s.+)/) {
90
                        unit.getProps().put(DEFINITUDE, "AMBIGU")
91
                        nAmbigu++
92
                } else {
93
                        unit.getProps().put(DEFINITUDE, "NONE")
94
                        nNone++;
95
                }
96
                nModified++
97
                
98
        } else {
99
                // nothing to do
100
                nIgnored++
101
        }
102
}
103

    
104
println "nIgnored=$nIgnored"
105
println "nModified=$nModified"
106
println " nDefini=$nDefini"
107
println " nIndefini=$nIndefini"
108
println " nDemonstratif=$nDemonstratif"
109
println " nAmbigu=$nAmbigu"
110
println " nNone=$nNone"