Statistics
| Revision:

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

History | View | Annotate | Download (1.3 kB)

1
package org.txm.importer.xtz
2

    
3
import java.io.File;
4

    
5
import org.txm.scripts.teitxm.Annotate
6

    
7

    
8
/**
9
 * Wraps current Annotate class into the import workflow
10
 * 
11
 * @author mdecorde
12
 *
13
 */
14
class TTAnnotater extends Annotater {
15

    
16
        Annotate a;
17
        
18
        public TTAnnotater(ImportModule module) {
19
                super(module);
20
        }
21

    
22
        @Override
23
        public void process() {
24

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

    
32
                def hash = [:]
33
                for (File txmFile : inputDirectory.listFiles()) {
34
                        hash[txmFile.getName()] = lang;
35
                }
36
                
37
                a = new Annotate()
38
                if (module.isMultiThread()) {
39
                        isSuccessFul = a.run(module.getBinaryDirectory(), inputDirectory, hash);
40
                } else {
41
                        isSuccessFul = a.run(module.getBinaryDirectory(), inputDirectory, lang+".par");
42
                }
43
                
44
                if ("true".equals(cleanDirectories)) {
45
                        new File(module.getBinaryDirectory(), "treetagger").deleteDir()
46
                        new File(module.getBinaryDirectory(), "annotations").deleteDir()
47
                }
48
                
49
                if (!isSuccessFul) reason = "TreeTagger annotation failed."
50
        }
51

    
52
        @Override
53
        public void cancel() {
54
                a.setCancelNow();
55
        }
56
}