Statistics
| Revision:

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

History | View | Annotate | Download (2.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.urs
7

    
8
import org.apache.commons.lang.StringUtils;
9
import org.kohsuke.args4j.*
10
import groovy.transform.Field
11
import org.txm.Toolbox;
12
import org.txm.rcp.swt.widget.parameters.*
13
import org.txm.annotation.urs.*
14
import org.txm.searchengine.cqp.AbstractCqiClient;
15
import org.txm.searchengine.cqp.corpus.*
16
import visuAnalec.donnees.Structure;
17
import visuAnalec.elements.Unite;
18

    
19
if (!(corpusViewSelection instanceof MainCorpus)) {
20
        println "Corpora selection is not a Corpus"
21
        return;
22
}
23

    
24
// BEGINNING OF PARAMETERS
25
@Field @Option(name="unit_type",usage="", widget="String", required=true, def="MENTION")
26
String unit_type
27

    
28
@Field @Option(name="unit_property_name1", usage="", widget="String", required=false, def="CATEGORIE")
29
String unit_property_name1
30

    
31
@Field @Option(name="unit_property_name2", usage="", widget="String", required=false, def="CATEGORIE_ORIG")
32
String unit_property_name2
33

    
34
if (!ParametersDialog.open(this)) return;
35

    
36
int n = 1;
37
int nDiff = 0;
38
MainCorpus corpus = corpusViewSelection
39
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
40
def word = corpus.getWordProperty()
41
def analecCorpus = URSCorpora.getCorpus(corpus);
42

    
43
def units = analecCorpus.getUnites(unit_type)
44
units.sort() { a, b -> a.getDeb() <=> b.getDeb() ?: a.getFin() <=> b.getFin() }
45
for (Unite unit : units) {
46
        int[] pos = null
47
        if (unit.getDeb() == unit.getFin()) pos = [unit.getDeb()]
48
        else pos = (unit.getDeb()..unit.getFin())
49
        def form = StringUtils.join(CQI.cpos2Str(word.getQualifiedName(), pos), " ")
50
        def props = unit.getProps()
51
        def v1 = props.get(unit_property_name1);
52
        def v2 = props.get(unit_property_name2);
53
        
54
        if (v1 != v2) {
55
                println "$n - ${unit.getDeb()} -> ${unit.getFin()} - $props : $form"
56
                nDiff++
57
        }
58
        n++
59
}
60

    
61
if (nDiff == 0) println "$unit_property_name1 and $unit_property_name2 have the same values."
62
else println "$unit_property_name1 and $unit_property_name2 have $nDiff/$n different values."