Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / importer / xtz / TTAnnotater.groovy @ 1000

History | View | Annotate | Download (1.5 kB)

1
package org.txm.scripts.importer.xtz
2

    
3
import java.io.File;
4

    
5
import org.txm.importer.xmltxm.Annotate
6
import org.txm.importer.xtz.*
7
import org.txm.Toolbox
8
import org.txm.core.engines.*
9
/**
10
 * Wraps current Annotate class into the import workflow
11
 * 
12
 * @author mdecorde
13
 *
14
 */
15
class TTAnnotater extends Annotater {
16

    
17
        public TTAnnotater(ImportModule module) {
18
                super(module);
19
        }
20

    
21
        @Override
22
        public void process() {
23

    
24
                //String model = module.getParameters().get(ImportKeys.TTMODEL);
25
                String cleanDirectories = module.getParameters().getKeyValueParameters().get(ImportKeys.CLEAN);
26
                
27
                String corpusname = module.getParameters().getCorpusName();
28
                def corpusElem = module.getParameters().getCorpora().get(corpusname);
29
                String lang = corpusElem.getAttribute("lang");
30

    
31
                def engine = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger")
32
                if (module.isMultiThread()) {
33
                        def hash = [:]
34
                        for (File txmFile : inputDirectory.listFiles()) {
35
                                hash[txmFile.getName()] = lang;
36
                        }
37
                        if (engine.processDirectory(inputDirectory, module.getBinaryDirectory(), ["langs":hash])) {
38
                                isSuccessFul = true;
39
                        }
40
                } else {
41
                        if (engine.processDirectory(inputDirectory, module.getBinaryDirectory(), ["lang":lang])) {
42
                                isSuccessFul = true;
43
                        }
44
                }
45
                
46
                if ("true".equals(cleanDirectories)) {
47
                        new File(module.getBinaryDirectory(), "treetagger").deleteDir()
48
                        new File(module.getBinaryDirectory(), "annotations").deleteDir()
49
                }
50
                
51
                if (!isSuccessFul) reason = "TreeTagger annotation failed."
52
        }
53

    
54
        @Override
55
        public void cancel() {
56
                //a.setCancelNow();
57
        }
58
}