Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / annotation / CQLList2WordAnnotationsMacro.groovy @ 2715

History | View | Annotate | Download (2.6 kB)

1

    
2
package org.txm.macro.annotation
3

    
4
// STANDARD DECLARATIONS
5
import org.txm.rcpapplication.swt.widget.parameters.*
6
import org.txm.searchengine.cqp.corpus.*
7
import org.txm.rcp.views.corpora.CorporaView
8
import org.txm.annotation.kr.core.KRAnnotationEngine
9
import org.txm.annotation.kr.core.repository.*
10

    
11
def scriptName = this.class.getSimpleName()
12

    
13
if (!(corpusViewSelection instanceof CQPCorpus)) {
14
        println "** $scriptName: please select a Corpus in the Corpus view."
15
        return 0
16
}
17

    
18
@Field @Option(name="queries_file", usage="The CQL query to select tokens", widget="File", required=true, def="queries.tsv")
19
File queries_file
20

    
21
@Field @Option(name="property", usage="The annotation type", widget="String", required=true, def="type")
22
String property
23

    
24
// Open the parameters input dialog box
25
if (!ParametersDialog.open(this)) return
26

    
27
int total = 0;
28

    
29
queries_file.eachLine("UTF-8") { line ->
30
        String[] split = line.split("\t", 2)
31
        if (!line.startsWith("#") && split.length == 2 && split[0].length() > 0 && split[1].length() >= 0) {
32
                
33
                def hash = ["args":
34
                         ["query":split[1], "property":property, "annotation_value":split[0]],
35
                         "corpusViewSelection":corpusViewSelection
36
                ]
37
                int n = gse.run(CQL2AnnotationsMacro, hash)
38
                total += n
39
        } else {
40
                println "## ignoring "+line
41
        }
42
}
43

    
44
println "$queries_file created $total annotations"
45

    
46
return total
47
package org.txm.macro.annotation
48

    
49
// STANDARD DECLARATIONS
50
import org.txm.rcpapplication.swt.widget.parameters.*
51
import org.txm.searchengine.cqp.corpus.*
52
import org.txm.rcp.views.corpora.CorporaView
53
import org.txm.annotation.kr.core.KRAnnotationEngine
54
import org.txm.annotation.kr.core.repository.*
55

    
56
def scriptName = this.class.getSimpleName()
57

    
58
if (!(corpusViewSelection instanceof CQPCorpus)) {
59
        println "** $scriptName: please select a Corpus in the Corpus view."
60
        return 0
61
}
62

    
63
@Field @Option(name="queries_file", usage="The CQL query to select tokens", widget="File", required=true, def="queries.tsv")
64
File queries_file
65

    
66
@Field @Option(name="property", usage="The property to annotate", widget="String", required=true, def="type")
67
String property
68

    
69
// Open the parameters input dialog box
70
if (!ParametersDialog.open(this)) return
71

    
72
int total = 0;
73

    
74
queries_file.eachLine("UTF-8") { line ->
75
        String[] split = line.split("\t", 2)
76
        if (!line.startsWith("#") && split.length == 2 && split[0].length() > 0 && split[1].length() >= 0) {
77
                
78
                def params = [
79
                        "query":split[1], "property":property, "value":split[0]
80
                        ]
81
                
82
                int n = gse.runMacro(CQL2AnnotationsMacro, params)
83
                total += n
84
        } else {
85
                println "## ignoring "+line
86
        }
87
}
88

    
89
println "$queries_file created $total annotations"
90

    
91
return total