Statistics
| Revision:

root / tmp / org.txm.analec.rcp / src / org / txm / macro / analec / misc / CompUnitPropertiesMacro.groovy @ 1166

History | View | Annotate | Download (2.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.analec.misc
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.analec.*
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="print_diff",usage="", widget="Boolean", required=true, def="true")
29
boolean print_diff
30

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

    
34
@Field @Option(name="unit_property_name2", usage="", widget="String", required=false, def="CATEGORIE_ORIG")
35
String unit_property_name2
36

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

    
39
int n = 1;
40
int nDiff = 0;
41
MainCorpus corpus = corpusViewSelection
42
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
43
def word = corpus.getWordProperty()
44
def analecCorpus = AnalecCorpora.getCorpus(corpus);
45

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

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