Statistics
| Revision:

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

History | View | Annotate | Download (1.8 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.utils.JobHandler
8
import org.txm.rcp.views.corpora.CorporaView
9
import org.eclipse.core.runtime.Status
10
import org.txm.annotation.kr.core.KRAnnotationEngine
11
import org.txm.annotation.kr.core.repository.*
12
import org.txm.annotation.kr.rcp.commands.SaveAnnotations
13
import org.txm.annotation.kr.rcp.concordance.WordAnnotationToolbar
14

    
15
def scriptName = this.class.getSimpleName()
16

    
17
if (!(corpusViewSelection instanceof CQPCorpus)) {
18
        println "** $scriptName: please select a Corpus in the Corpus view."
19
        return 0
20
}
21

    
22
CQPCorpus corpus = corpusViewSelection
23
MainCorpus mcorpus = corpus.getMainCorpus();
24

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

    
28
@Field @Option(name="annotation_type", usage="The annotation type", widget="String", required=true, def="type")
29
String annotation_type
30

    
31
// Open the parameters input dialog box
32
if (!ParametersDialog.open(this)) return
33

    
34
int total = 0;
35

    
36

    
37
        def hash = ["args":        ["queries_file":queries_file, "annotation_type":annotation_type],
38
                "corpusViewSelection":corpusViewSelection, "gse":gse
39
   ]
40
int n = gse.run(CQLList2AnnotationsMacro, hash)
41

    
42
if (n > 0) {
43
        println "Saving annotations..."
44
        monitor.syncExec(new Runnable() {
45
                public void run() {
46
                        def saveJob = SaveAnnotations.save(mcorpus);
47
                        if (saveJob == null || saveJob.getResult() == Status.CANCEL_STATUS) {
48
                                // update editor corpus
49
                                System.out.println("Fail to save annotations of the corpus."); //$NON-NLS-1$
50
                                return;
51
                        } else {
52
                                return; // something was saved
53
                        }
54
                }
55
        });
56
} else {
57
        println "No annotation to save."
58
        return false
59
}