Statistics
| Revision:

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

History | View | Annotate | Download (1.4 kB)

1 986 mdecorde
package org.txm.scripts.importer.xtz
2 321 mdecorde
3 321 mdecorde
import java.io.File;
4 321 mdecorde
5 1000 mdecorde
import org.txm.importer.xmltxm.Annotate
6 1000 mdecorde
import org.txm.importer.xtz.*
7 1000 mdecorde
import org.txm.Toolbox
8 1000 mdecorde
import org.txm.core.engines.*
9 1137 mdecorde
10 321 mdecorde
/**
11 321 mdecorde
 * Wraps current Annotate class into the import workflow
12 321 mdecorde
 *
13 321 mdecorde
 * @author mdecorde
14 321 mdecorde
 *
15 321 mdecorde
 */
16 321 mdecorde
class TTAnnotater extends Annotater {
17 321 mdecorde
18 321 mdecorde
        public TTAnnotater(ImportModule module) {
19 321 mdecorde
                super(module);
20 321 mdecorde
        }
21 321 mdecorde
22 321 mdecorde
        @Override
23 321 mdecorde
        public void process() {
24 321 mdecorde
25 321 mdecorde
                //String model = module.getParameters().get(ImportKeys.TTMODEL);
26 1137 mdecorde
                boolean cleanDirectories = module.getProject().getCleanAfterBuild();
27 321 mdecorde
28 1137 mdecorde
                String corpusname = module.getProject().getName();
29 1137 mdecorde
                String lang = module.getProject().getLang();
30 321 mdecorde
31 927 mdecorde
                def engine = Toolbox.getEngineManager(EngineType.ANNOTATION).getEngine("TreeTagger")
32 321 mdecorde
                if (module.isMultiThread()) {
33 927 mdecorde
                        def hash = [:]
34 927 mdecorde
                        for (File txmFile : inputDirectory.listFiles()) {
35 927 mdecorde
                                hash[txmFile.getName()] = lang;
36 927 mdecorde
                        }
37 1000 mdecorde
                        if (engine.processDirectory(inputDirectory, module.getBinaryDirectory(), ["langs":hash])) {
38 927 mdecorde
                                isSuccessFul = true;
39 927 mdecorde
                        }
40 321 mdecorde
                } else {
41 1000 mdecorde
                        if (engine.processDirectory(inputDirectory, module.getBinaryDirectory(), ["lang":lang])) {
42 927 mdecorde
                                isSuccessFul = true;
43 927 mdecorde
                        }
44 321 mdecorde
                }
45 321 mdecorde
46 1137 mdecorde
                if (cleanDirectories) {
47 321 mdecorde
                        new File(module.getBinaryDirectory(), "treetagger").deleteDir()
48 321 mdecorde
                        new File(module.getBinaryDirectory(), "annotations").deleteDir()
49 321 mdecorde
                }
50 321 mdecorde
51 321 mdecorde
                if (!isSuccessFul) reason = "TreeTagger annotation failed."
52 321 mdecorde
        }
53 321 mdecorde
54 321 mdecorde
        @Override
55 321 mdecorde
        public void cancel() {
56 927 mdecorde
                //a.setCancelNow();
57 321 mdecorde
        }
58 321 mdecorde
}