Statistics
| Revision:

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

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.analec.misc
7

    
8
import org.apache.commons.lang.StringUtils;
9
import org.apache.tools.ant.types.resources.selectors.InstanceOf;
10
import org.kohsuke.args4j.*
11

    
12
import groovy.transform.Field
13

    
14
import org.txm.Toolbox;
15
import org.txm.rcp.swt.widget.parameters.*
16
import org.txm.analec.*
17
import org.txm.searchengine.cqp.AbstractCqiClient;
18
import org.txm.searchengine.cqp.corpus.*
19

    
20
import visuAnalec.donnees.Structure;
21
import visuAnalec.elements.Relation
22
import visuAnalec.elements.Unite;
23

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

    
29
// BEGINNING OF PARAMETERS
30
@Field @Option(name="relation_type",usage="", widget="String", required=true, def="ANAPHORE")
31
String relation_type
32

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

    
35
MainCorpus corpus = corpusViewSelection
36
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
37
def word = corpus.getWordProperty()
38
visuAnalec.donnees.Corpus analecCorpus = AnalecCorpora.getCorpus(corpus);
39

    
40
int n = 1;
41
def relations = null
42
if (relation_type.length() > 0) {
43
        relations = []
44
        for (String type : analecCorpus.getStructure().getTypes(Relation.class))
45
                relations.addAll(analecCorpus.getRelations(type))
46
} else {
47
        relations = analecCorpus.getToutesRelations()
48
}
49

    
50
for (Relation relation : relations) {
51
        def unit1 = relation.getElt1();
52
        def unit2 = relation.getElt2();
53
        def props = relation.getProps()
54
        if (unit1 instanceof Unite && unit2 instanceof Unite) {
55
                int[] pos1 = null
56
                if (unit1.getDeb() == unit1.getFin()) pos1 = [unit1.getDeb()]
57
                else pos1 = (unit1.getDeb()..unit1.getFin())
58
                def form1 = StringUtils.join(CQI.cpos2Str(word.getQualifiedName(), pos1), " ")
59
                
60
                int[] pos2 = null
61
                if (unit2.getDeb() == unit2.getFin()) pos2 = [unit2.getDeb()]
62
                else pos2 = (unit2.getDeb()..unit2.getFin())
63
                def form2 = StringUtils.join(CQI.cpos2Str(word.getQualifiedName(), pos2), " ")
64
                
65
                println "$n - $props : $form1 -> $form2"
66
        } else {
67
                println "$n - $props"
68
        }
69
        n++
70
}