You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@joshua.apache.org by mj...@apache.org on 2016/09/14 18:22:49 UTC

[21/29] incubator-joshua git commit: Moved regression test decoder/n-ary to unit test. Cleaned up the corresponding directory and regenerated gold output.

Moved regression test decoder/n-ary to unit test. Cleaned up the corresponding directory and regenerated gold output.


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

Branch: refs/heads/7
Commit: d51169a09dd9ec26f60617d663857c6a9f3f5a5f
Parents: 4c5285e
Author: Michael A. Hedderich <mi...@users.noreply.github.com>
Authored: Wed Sep 14 19:20:00 2016 +0200
Committer: Michael A. Hedderich <mi...@users.noreply.github.com>
Committed: Wed Sep 14 19:20:00 2016 +0200

----------------------------------------------------------------------
 .../org/apache/joshua/decoder/cky/NAryTest.java | 64 ++++++++++++++++++++
 src/test/resources/decoder/n-ary/gold.scores    |  2 -
 src/test/resources/decoder/n-ary/joshua.config  | 10 +--
 src/test/resources/decoder/n-ary/output.bleu    |  0
 src/test/resources/decoder/n-ary/output.gold    |  4 +-
 5 files changed, 72 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d51169a0/src/test/java/org/apache/joshua/decoder/cky/NAryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/decoder/cky/NAryTest.java b/src/test/java/org/apache/joshua/decoder/cky/NAryTest.java
new file mode 100644
index 0000000..31a347a
--- /dev/null
+++ b/src/test/java/org/apache/joshua/decoder/cky/NAryTest.java
@@ -0,0 +1,64 @@
+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;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import java.util.List;
+
+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;
+
+public class NAryTest {
+  private JoshuaConfiguration joshuaConfig;
+  private Decoder decoder;
+
+  @AfterMethod
+  public void tearDown() throws Exception {
+    if (decoder != null) {
+      decoder.cleanUp();
+      decoder = null;
+    }
+  }
+
+  @Test
+  public void givenInput_whenNAryDecoding_thenScoreAndTranslationCorrect() throws Exception {
+    // Given
+    List<String> inputStrings = loadStringsFromFile("src/test/resources/decoder/n-ary/input.txt");
+
+    // When
+    configureDecoder("src/test/resources/decoder/n-ary/joshua.config");
+    List<String> decodedStrings = decodeList(inputStrings, decoder, joshuaConfig);
+
+    // Then
+    List<String> goldStrings = loadStringsFromFile("src/test/resources/decoder/n-ary/output.gold");
+    assertEquals(decodedStrings, goldStrings);
+  }
+
+  public void configureDecoder(String pathToConfig) throws Exception {
+    joshuaConfig = new JoshuaConfiguration();
+    joshuaConfig.readConfigFile(pathToConfig);
+    KenLmTestUtil.Guard(() -> decoder = new Decoder(joshuaConfig, ""));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d51169a0/src/test/resources/decoder/n-ary/gold.scores
----------------------------------------------------------------------
diff --git a/src/test/resources/decoder/n-ary/gold.scores b/src/test/resources/decoder/n-ary/gold.scores
deleted file mode 100644
index ba1ee94..0000000
--- a/src/test/resources/decoder/n-ary/gold.scores
+++ /dev/null
@@ -1,2 +0,0 @@
- Goats eat cheese  |||  -11.503
- i will go home  |||  -4.414

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d51169a0/src/test/resources/decoder/n-ary/joshua.config
----------------------------------------------------------------------
diff --git a/src/test/resources/decoder/n-ary/joshua.config b/src/test/resources/decoder/n-ary/joshua.config
index c2b2b48..1710c50 100644
--- a/src/test/resources/decoder/n-ary/joshua.config
+++ b/src/test/resources/decoder/n-ary/joshua.config
@@ -1,7 +1,7 @@
-lm = kenlm 5 false false 100 lm.gz
+lm = kenlm 5 false false 100 src/test/resources/decoder/n-ary/lm.gz
 
-tm = thrax phrase 20 grammar
-tm = thrax glue -1 glue-grammar
+tm = thrax phrase 20 src/test/resources/decoder/n-ary/grammar
+tm = thrax glue -1 src/test/resources/decoder/n-ary/glue-grammar
 
 mark_oovs = true
 
@@ -17,6 +17,8 @@ use_tree_nbest = false
 add_combined_cost = true
 top_n = 1
 
-weights-file = weights
+output-format = %c %s
+
+weights-file = src/test/resources/decoder/n-ary/weights
 feature-function = WordPenalty
 feature-function = OOVPenalty

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d51169a0/src/test/resources/decoder/n-ary/output.bleu
----------------------------------------------------------------------
diff --git a/src/test/resources/decoder/n-ary/output.bleu b/src/test/resources/decoder/n-ary/output.bleu
deleted file mode 100644
index e69de29..0000000

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/d51169a0/src/test/resources/decoder/n-ary/output.gold
----------------------------------------------------------------------
diff --git a/src/test/resources/decoder/n-ary/output.gold b/src/test/resources/decoder/n-ary/output.gold
index e2c051b..742b98c 100644
--- a/src/test/resources/decoder/n-ary/output.gold
+++ b/src/test/resources/decoder/n-ary/output.gold
@@ -1,2 +1,2 @@
-0 ||| Goats eat cheese ||| WordPenalty=-2.171 lm_0=-16.587 tm_glue_0=1.000 ||| -11.503
-1 ||| i will go home ||| WordPenalty=-2.606 lm_0=-12.155 tm_glue_0=1.000 ||| -4.414
+-11.503 Goats eat cheese
+-4.414 i will go home