diff --git a/src/main/java/pl/waw/ipipan/zil/core/bartek/main/Main.java b/src/main/java/pl/waw/ipipan/zil/core/bartek/main/Main.java index b25419b..33654c6 100755 --- a/src/main/java/pl/waw/ipipan/zil/core/bartek/main/Main.java +++ b/src/main/java/pl/waw/ipipan/zil/core/bartek/main/Main.java @@ -25,15 +25,31 @@ public class Main { private static final Logger logger = LoggerFactory.getLogger(Main.class); - private static Decoder decoder; + private Decoder decoder; - static { + public Main() { InputStream decoderStream = Main.class.getResourceAsStream(Constants.DECODER_PATH_PREFIX + Constants.DEFAULT_DECODER_NAME); decoder = Serializer.loadDecoderFromStream(decoderStream); } - - private Main() { + + public Main(String decoderPath) { + try { + if (decoderPath.endsWith(".xml")) { + decoder = Serializer.loadDecoderFromFile(new File(decoderPath)); + } else { + InputStream decoderStream = new FileInputStream(new File(decoderPath)); + decoder = Serializer.loadDecoderFromStream(decoderStream); + if (decoder == null) + throw new IOException(); + } + } catch (IOException e) { + logger.error("Error loading decoder/rules from path: " + decoderPath); + return; + } catch (Exception e) { + logger.error("Error loading rules from path: " + decoderPath); + return; + } } public static void main(String[] args) throws TEIException { @@ -54,24 +70,12 @@ public class Main { return; } - try { - if (args.length == 3) { - if (args[2].endsWith(".xml")) { - decoder = Serializer.loadDecoderFromFile(new File(args[2])); - } else { - InputStream decoderStream = new FileInputStream(new File(args[2])); - decoder = Serializer.loadDecoderFromStream(decoderStream); - if (decoder == null) - throw new IOException(); - } - } - } catch (IOException e) { - logger.error("Error loading decoder/rules from path: " + args[2]); - return; - } catch (Exception e) { - logger.error("Error loading rules from path: " + args[2]); - return; - } + Main bartek; + if (args.length == 3) { + bartek = new Main(args[2]); + } else { + bartek = new Main(); + } logger.info("Starting annotation of texts in dir:" + inputDir); int errors = 0, ok = 0; @@ -79,7 +83,7 @@ public class Main { try { File targetDir = createTargetTextDir(inputDir, outputDir, teiDir); TEICorpusText teiText = TeiLoader.readTeiText(teiDir); - annotateTeiText(teiText); + bartek.annotateTeiText(teiText); TeiSaver.saveTeiText(teiText, targetDir, Constants.GZIP_OUTPUT); ok++; @@ -113,7 +117,7 @@ public class Main { return targetDir; } - public static void annotateThriftText(TText thriftText) throws MultiserviceException { + public void annotateThriftText(TText thriftText) throws MultiserviceException { Text text = ThriftLoader.loadTextFromThrift(thriftText); try { Method.annotateText(text, decoder); @@ -123,7 +127,7 @@ public class Main { ThriftSaver.updateThriftText(text, thriftText); } - public static void annotateTeiText(TEICorpusText ct) throws TEIException { + public void annotateTeiText(TEICorpusText ct) throws TEIException { if (!ct.getAnnotationLayers().contains(AnnotationLayer.MENTIONS)) throw new TEIException("No mentions to cluster!"); Text text = TeiLoader.loadTextFromTei(ct); diff --git a/src/test/java/pl/waw/ipipan/zil/core/bartek/MainTest.java b/src/test/java/pl/waw/ipipan/zil/core/bartek/MainTest.java index b7023b6..163e040 100755 --- a/src/test/java/pl/waw/ipipan/zil/core/bartek/MainTest.java +++ b/src/test/java/pl/waw/ipipan/zil/core/bartek/MainTest.java @@ -22,7 +22,16 @@ public class MainTest { @Test public final void testCustomModel() throws IOException { String[] args = { MainTest.class.getResource("/example_corpus_tei/").getFile(), - results.newFolder().getAbsolutePath(), "bart1" }; + results.newFolder().getAbsolutePath(), + MainTest.class.getResource("/models/bart5").getFile()}; + Main.main(args); + } + + @Test + public final void testSieveDecoder() throws IOException { + String[] args = { MainTest.class.getResource("/example_corpus_tei/").getFile(), + results.newFolder().getAbsolutePath(), + MainTest.class.getResource("/configs/bart-S2-pl.xml").getPath()}; Main.main(args); } } diff --git a/src/test/resources/configs/example_config.xml b/src/test/resources/configs/example_config.xml index 7d8b867..aadbebb 100755 --- a/src/test/resources/configs/example_config.xml +++ b/src/test/resources/configs/example_config.xml @@ -30,7 +30,7 @@ <extractor class="combined.FE_AdjSent_AnaPron_AdjMen" /> <extractor class="pair.FE_Abbrev2" /> </extractors> - <writer class="WEKAInstanceWriter" targetPath="/home/me2/Desktop/data.arff" /> + <writer class="WEKAInstanceWriter" targetPath="./data.arff" /> <classifier class="weka.classifiers.trees.J48" type="weka" options="" /> <decoder class="SoonDecoder" />