Fixed TreeOutputTest to work with new configuration.

Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/3b70a978
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/3b70a978
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/3b70a978

Branch: refs/heads/7_confsystem
Commit: 3b70a978462fc98d3b6336c6498f339391900879
Parents: a7e2adf
Author: Michael A. Hedderich <michael-al...@users.noreply.github.com>
Authored: Sun Sep 18 19:14:12 2016 +0200
Committer: Michael A. Hedderich <michael-al...@users.noreply.github.com>
Committed: Sun Sep 18 19:14:12 2016 +0200

----------------------------------------------------------------------
 .../joshua/decoder/cky/TreeOutputTest.conf      | 42 ++++++++++++++++++++
 .../joshua/decoder/cky/TreeOutputTest.gold      |  5 +++
 .../apache/joshua/decoder/cky/TreeOutputTest.in |  5 +++
 .../joshua/decoder/cky/TreeOutputTest.java      | 32 +++++----------
 4 files changed, 62 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/3b70a978/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.conf
----------------------------------------------------------------------
diff --git 
a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.conf 
b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.conf
new file mode 100644
index 0000000..e5cd475
--- /dev/null
+++ 
b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.conf
@@ -0,0 +1,42 @@
+mark_oovs = false
+default_non_terminal = X
+goalSymbol = GOAL
+pop_limit = 100
+output_format = %t
+use_unique_nbest = true
+top_n = 1
+
+feature_functions = [
+  { class = LanguageModel, lm_type = kenlm, lm_order = 5, lm_file = 
src/test/resources/decoder/tree-output/lm.gz }
+  { class = WordPenalty }
+  { class = OOVPenalty }
+]
+
+grammars = [
+  { class = TextGrammar, owner = pt, span_limit = 12, path = 
src/test/resources/decoder/tree-output/grammar.gz }
+  { class = TextGrammar, owner = glue, span_limit = -1, path = 
src/test/resources/decoder/tree-output/glue-grammar }
+]
+
+weights = {
+  OOVPenalty = 1.0
+  WordPenalty = -3.6942747832593694
+  lm_0 = 1.2373676802179452
+  tm_glue_0 = 1
+  tm_pt_0 = -2.4497429277910214
+  tm_pt_1 = 0.7224581556224123
+  tm_pt_10 = 0.2593091306160006
+  tm_pt_11 = 0.25597137004462134
+  tm_pt_12 = 0.3538894647790496
+  tm_pt_13 = -0.36212061186692646
+  tm_pt_14 = -0.32923261148678096
+  tm_pt_15 = 0.5524863522177359
+  tm_pt_16 = 0.23451595442127693
+  tm_pt_2 = -0.31689069155153504
+  tm_pt_3 = 0.33861043967238036
+  tm_pt_4 = 0.03553113401320236
+  tm_pt_5 = 0.19138972284064748
+  tm_pt_6 = 0.3417994095521415
+  tm_pt_7 = -0.9936312455671283
+  tm_pt_8 = 0.9070737587091975
+  tm_pt_9 = 0.8202511858619419
+}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/3b70a978/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.gold
----------------------------------------------------------------------
diff --git 
a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.gold 
b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.gold
new file mode 100644
index 0000000..abbeb79
--- /dev/null
+++ 
b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.gold
@@ -0,0 +1,5 @@
+(GOAL{0-5} (GOAL{0-4} (GOAL{0-3} (GOAL{0-1} <s>) (A{1-3} (B{1-2} foo) (C{2-3} 
bar))) (D{3-4} baz)) </s>)
+()
+(GOAL{0-3} (GOAL{0-2} (GOAL{0-1} <s>) (D{1-2} baz)) </s>)
+(GOAL{0-4} (GOAL{0-3} (GOAL{0-1} <s>) (S{1-3} I AM)) </s>)
+(GOAL{0-4} <s> (NP\DT{1-3} right (NN{2-3} xslot)) </s>)

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/3b70a978/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.in
----------------------------------------------------------------------
diff --git 
a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.in 
b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.in
new file mode 100644
index 0000000..a5a18b4
--- /dev/null
+++ b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.in
@@ -0,0 +1,5 @@
+foo bar baz
+an unparseable sentence
+baz
+yo soy
+purchase xslot

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/3b70a978/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.java
----------------------------------------------------------------------
diff --git 
a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.java 
b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.java
index 578790d..0efb3c1 100644
--- 
a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.java
+++ 
b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.java
@@ -18,20 +18,17 @@
  */
 package org.apache.joshua.decoder.cky;
 
-import static org.apache.joshua.decoder.cky.TestUtil.decodeList;
-import static org.apache.joshua.decoder.cky.TestUtil.loadStringsFromFile;
-import static org.testng.Assert.assertEquals;
-
-import java.util.List;
+import static com.typesafe.config.ConfigFactory.parseResources;
+import static 
org.apache.joshua.decoder.cky.TestUtil.decodeAndAssertDecodedOutputEqualsGold;
 
 import org.apache.joshua.decoder.Decoder;
-import org.apache.joshua.decoder.JoshuaConfiguration;
 import org.apache.joshua.util.io.KenLmTestUtil;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
+import com.typesafe.config.Config;
+
 public class TreeOutputTest {
-  private JoshuaConfiguration joshuaConfig;
   private Decoder decoder;
 
   @AfterMethod
@@ -44,22 +41,13 @@ public class TreeOutputTest {
 
   @Test
   public void givenInput_whenDecodingWithTreeOutput_thenOutputCorrect() throws 
Exception {
-    // Given
-    List<String> inputStrings = 
loadStringsFromFile("src/test/resources/decoder/tree-output/input");
+    String inputPath = 
this.getClass().getResource("TreeOutputTest.in").getFile();
+    String goldPath = 
this.getClass().getResource("TreeOutputTest.gold").getFile();
+    Config config = parseResources(this.getClass(), "TreeOutputTest.conf")
+        .withFallback(Decoder.getDefaultFlags());
+    KenLmTestUtil.Guard(() -> decoder = new Decoder(config));
 
-    // When
-    configureDecoder("src/test/resources/decoder/tree-output/joshua.config");
-    List<String> decodedStrings = decodeList(inputStrings, decoder, 
joshuaConfig);
-
-    // Then
-    List<String> goldStrings = loadStringsFromFile(
-        "src/test/resources/decoder/tree-output/output.gold");
-    assertEquals(decodedStrings, goldStrings);
+    decodeAndAssertDecodedOutputEqualsGold(inputPath, decoder, goldPath);
   }
 
-  public void configureDecoder(String pathToConfig) throws Exception {
-    joshuaConfig = new JoshuaConfiguration();
-    joshuaConfig.readConfigFile(pathToConfig);
-    KenLmTestUtil.Guard(() -> decoder = new Decoder(joshuaConfig));
-  }
 }

Reply via email to