Statistics
| Revision:

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

History | View | Annotate | Download (1.9 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.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.annotation.urs.*
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
def analecCorpus = URSCorpora.getCorpus(corpus);
39

    
40
int n = 1;
41
def relations = analecCorpus.getRelations(relation_type)
42
for (Relation relation : relations) {
43
        
44
        def unit1 = relation.getElt1();
45
        def unit2 = relation.getElt2();
46
        def props = relation.getProps()
47
        
48
        if (unit1 instanceof Unite && unit2 instanceof Unite) {
49
                int[] pos1 = null
50
                if (unit1.getDeb() == unit1.getFin()) pos1 = [unit1.getDeb()]
51
                else pos1 = (unit1.getDeb()..unit1.getFin())
52
                def form1 = StringUtils.join(CQI.cpos2Str(word.getQualifiedName(), pos1), " ")
53
                
54
                int[] pos2 = null
55
                if (unit2.getDeb() == unit2.getFin()) pos2 = [unit2.getDeb()]
56
                else pos2 = (unit2.getDeb()..unit2.getFin())
57
                def form2 = StringUtils.join(CQI.cpos2Str(word.getQualifiedName(), pos2), " ")
58
                
59
                println "$n - $props : $form1 -> $form2"
60
        } else {
61
                println "$n - $props"
62
        }
63
        n++
64
}