Commit e4ea34894fd6aeecd864aac594965c9e52d39fcf
1 parent
215c5fa1
Change Main class
Showing
3 changed files
with
40 additions
and
27 deletions
src/main/java/pl/waw/ipipan/zil/core/bartek/main/Main.java
@@ -25,15 +25,31 @@ public class Main { | @@ -25,15 +25,31 @@ public class Main { | ||
25 | 25 | ||
26 | private static final Logger logger = LoggerFactory.getLogger(Main.class); | 26 | private static final Logger logger = LoggerFactory.getLogger(Main.class); |
27 | 27 | ||
28 | - private static Decoder decoder; | 28 | + private Decoder decoder; |
29 | 29 | ||
30 | - static { | 30 | + public Main() { |
31 | InputStream decoderStream = Main.class.getResourceAsStream(Constants.DECODER_PATH_PREFIX | 31 | InputStream decoderStream = Main.class.getResourceAsStream(Constants.DECODER_PATH_PREFIX |
32 | + Constants.DEFAULT_DECODER_NAME); | 32 | + Constants.DEFAULT_DECODER_NAME); |
33 | decoder = Serializer.loadDecoderFromStream(decoderStream); | 33 | decoder = Serializer.loadDecoderFromStream(decoderStream); |
34 | } | 34 | } |
35 | - | ||
36 | - private Main() { | 35 | + |
36 | + public Main(String decoderPath) { | ||
37 | + try { | ||
38 | + if (decoderPath.endsWith(".xml")) { | ||
39 | + decoder = Serializer.loadDecoderFromFile(new File(decoderPath)); | ||
40 | + } else { | ||
41 | + InputStream decoderStream = new FileInputStream(new File(decoderPath)); | ||
42 | + decoder = Serializer.loadDecoderFromStream(decoderStream); | ||
43 | + if (decoder == null) | ||
44 | + throw new IOException(); | ||
45 | + } | ||
46 | + } catch (IOException e) { | ||
47 | + logger.error("Error loading decoder/rules from path: " + decoderPath); | ||
48 | + return; | ||
49 | + } catch (Exception e) { | ||
50 | + logger.error("Error loading rules from path: " + decoderPath); | ||
51 | + return; | ||
52 | + } | ||
37 | } | 53 | } |
38 | 54 | ||
39 | public static void main(String[] args) throws TEIException { | 55 | public static void main(String[] args) throws TEIException { |
@@ -54,24 +70,12 @@ public class Main { | @@ -54,24 +70,12 @@ public class Main { | ||
54 | return; | 70 | return; |
55 | } | 71 | } |
56 | 72 | ||
57 | - try { | ||
58 | - if (args.length == 3) { | ||
59 | - if (args[2].endsWith(".xml")) { | ||
60 | - decoder = Serializer.loadDecoderFromFile(new File(args[2])); | ||
61 | - } else { | ||
62 | - InputStream decoderStream = new FileInputStream(new File(args[2])); | ||
63 | - decoder = Serializer.loadDecoderFromStream(decoderStream); | ||
64 | - if (decoder == null) | ||
65 | - throw new IOException(); | ||
66 | - } | ||
67 | - } | ||
68 | - } catch (IOException e) { | ||
69 | - logger.error("Error loading decoder/rules from path: " + args[2]); | ||
70 | - return; | ||
71 | - } catch (Exception e) { | ||
72 | - logger.error("Error loading rules from path: " + args[2]); | ||
73 | - return; | ||
74 | - } | 73 | + Main bartek; |
74 | + if (args.length == 3) { | ||
75 | + bartek = new Main(args[2]); | ||
76 | + } else { | ||
77 | + bartek = new Main(); | ||
78 | + } | ||
75 | 79 | ||
76 | logger.info("Starting annotation of texts in dir:" + inputDir); | 80 | logger.info("Starting annotation of texts in dir:" + inputDir); |
77 | int errors = 0, ok = 0; | 81 | int errors = 0, ok = 0; |
@@ -79,7 +83,7 @@ public class Main { | @@ -79,7 +83,7 @@ public class Main { | ||
79 | try { | 83 | try { |
80 | File targetDir = createTargetTextDir(inputDir, outputDir, teiDir); | 84 | File targetDir = createTargetTextDir(inputDir, outputDir, teiDir); |
81 | TEICorpusText teiText = TeiLoader.readTeiText(teiDir); | 85 | TEICorpusText teiText = TeiLoader.readTeiText(teiDir); |
82 | - annotateTeiText(teiText); | 86 | + bartek.annotateTeiText(teiText); |
83 | TeiSaver.saveTeiText(teiText, targetDir, Constants.GZIP_OUTPUT); | 87 | TeiSaver.saveTeiText(teiText, targetDir, Constants.GZIP_OUTPUT); |
84 | ok++; | 88 | ok++; |
85 | 89 | ||
@@ -113,7 +117,7 @@ public class Main { | @@ -113,7 +117,7 @@ public class Main { | ||
113 | return targetDir; | 117 | return targetDir; |
114 | } | 118 | } |
115 | 119 | ||
116 | - public static void annotateThriftText(TText thriftText) throws MultiserviceException { | 120 | + public void annotateThriftText(TText thriftText) throws MultiserviceException { |
117 | Text text = ThriftLoader.loadTextFromThrift(thriftText); | 121 | Text text = ThriftLoader.loadTextFromThrift(thriftText); |
118 | try { | 122 | try { |
119 | Method.annotateText(text, decoder); | 123 | Method.annotateText(text, decoder); |
@@ -123,7 +127,7 @@ public class Main { | @@ -123,7 +127,7 @@ public class Main { | ||
123 | ThriftSaver.updateThriftText(text, thriftText); | 127 | ThriftSaver.updateThriftText(text, thriftText); |
124 | } | 128 | } |
125 | 129 | ||
126 | - public static void annotateTeiText(TEICorpusText ct) throws TEIException { | 130 | + public void annotateTeiText(TEICorpusText ct) throws TEIException { |
127 | if (!ct.getAnnotationLayers().contains(AnnotationLayer.MENTIONS)) | 131 | if (!ct.getAnnotationLayers().contains(AnnotationLayer.MENTIONS)) |
128 | throw new TEIException("No mentions to cluster!"); | 132 | throw new TEIException("No mentions to cluster!"); |
129 | Text text = TeiLoader.loadTextFromTei(ct); | 133 | Text text = TeiLoader.loadTextFromTei(ct); |
src/test/java/pl/waw/ipipan/zil/core/bartek/MainTest.java
@@ -22,7 +22,16 @@ public class MainTest { | @@ -22,7 +22,16 @@ public class MainTest { | ||
22 | @Test | 22 | @Test |
23 | public final void testCustomModel() throws IOException { | 23 | public final void testCustomModel() throws IOException { |
24 | String[] args = { MainTest.class.getResource("/example_corpus_tei/").getFile(), | 24 | String[] args = { MainTest.class.getResource("/example_corpus_tei/").getFile(), |
25 | - results.newFolder().getAbsolutePath(), "bart1" }; | 25 | + results.newFolder().getAbsolutePath(), |
26 | + MainTest.class.getResource("/models/bart5").getFile()}; | ||
27 | + Main.main(args); | ||
28 | + } | ||
29 | + | ||
30 | + @Test | ||
31 | + public final void testSieveDecoder() throws IOException { | ||
32 | + String[] args = { MainTest.class.getResource("/example_corpus_tei/").getFile(), | ||
33 | + results.newFolder().getAbsolutePath(), | ||
34 | + MainTest.class.getResource("/configs/bart-S2-pl.xml").getPath()}; | ||
26 | Main.main(args); | 35 | Main.main(args); |
27 | } | 36 | } |
28 | } | 37 | } |
src/test/resources/configs/example_config.xml
@@ -30,7 +30,7 @@ | @@ -30,7 +30,7 @@ | ||
30 | <extractor class="combined.FE_AdjSent_AnaPron_AdjMen" /> | 30 | <extractor class="combined.FE_AdjSent_AnaPron_AdjMen" /> |
31 | <extractor class="pair.FE_Abbrev2" /> | 31 | <extractor class="pair.FE_Abbrev2" /> |
32 | </extractors> | 32 | </extractors> |
33 | - <writer class="WEKAInstanceWriter" targetPath="/home/me2/Desktop/data.arff" /> | 33 | + <writer class="WEKAInstanceWriter" targetPath="./data.arff" /> |
34 | <classifier class="weka.classifiers.trees.J48" type="weka" | 34 | <classifier class="weka.classifiers.trees.J48" type="weka" |
35 | options="" /> | 35 | options="" /> |
36 | <decoder class="SoonDecoder" /> | 36 | <decoder class="SoonDecoder" /> |