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/15 13:31:29 UTC

[03/13] incubator-joshua git commit: Moved regression test decoder/tree-output to unit test. Regenerated gold output and cleaned up the directory.

Moved regression test decoder/tree-output to unit test. Regenerated gold output and cleaned up the directory.


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

Branch: refs/heads/master
Commit: 99b475b3ffe08f2bfcc8105e906293dbd9d1c12f
Parents: 17ecec1
Author: Michael A. Hedderich <mi...@users.noreply.github.com>
Authored: Thu Sep 15 13:00:38 2016 +0200
Committer: Michael A. Hedderich <mi...@users.noreply.github.com>
Committed: Thu Sep 15 14:21:05 2016 +0200

----------------------------------------------------------------------
 .../joshua/decoder/cky/TreeOutputTest.java      | 65 ++++++++++++++++++++
 .../decoder/tree-output/fragment-map.txt        |  2 -
 .../resources/decoder/tree-output/joshua.config |  8 +--
 .../resources/decoder/tree-output/output.gold   | 10 +--
 src/test/resources/decoder/tree-output/test.sh  | 30 ---------
 5 files changed, 74 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/99b475b3/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.java b/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.java
new file mode 100644
index 0000000..f5e1005
--- /dev/null
+++ b/src/test/java/org/apache/joshua/decoder/cky/TreeOutputTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+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 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 TreeOutputTest {
+  private JoshuaConfiguration joshuaConfig;
+  private Decoder decoder;
+
+  @AfterMethod
+  public void tearDown() throws Exception {
+    if (decoder != null) {
+      decoder.cleanUp();
+      decoder = null;
+    }
+  }
+
+  @Test
+  public void givenInput_whenDecodingWithTreeOutput_thenOutputCorrect() throws Exception {
+    // Given
+    List<String> inputStrings = loadStringsFromFile("src/test/resources/decoder/tree-output/input");
+
+    // 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);
+  }
+
+  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/99b475b3/src/test/resources/decoder/tree-output/fragment-map.txt
----------------------------------------------------------------------
diff --git a/src/test/resources/decoder/tree-output/fragment-map.txt b/src/test/resources/decoder/tree-output/fragment-map.txt
deleted file mode 100644
index daed866..0000000
--- a/src/test/resources/decoder/tree-output/fragment-map.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-(S (NP (PRP "I")) (VP (VB "am"))) ||| I AM
-

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/99b475b3/src/test/resources/decoder/tree-output/joshua.config
----------------------------------------------------------------------
diff --git a/src/test/resources/decoder/tree-output/joshua.config b/src/test/resources/decoder/tree-output/joshua.config
index d68192d..7375cad 100644
--- a/src/test/resources/decoder/tree-output/joshua.config
+++ b/src/test/resources/decoder/tree-output/joshua.config
@@ -1,7 +1,7 @@
-lm = kenlm 5 false false 100 lm.gz
+lm = kenlm 5 false false 100 src/test/resources/decoder/tree-output/lm.gz
 
-tm = thrax pt 12 grammar.gz
-tm = thrax glue -1 glue-grammar
+tm = thrax pt 12 src/test/resources/decoder/tree-output/grammar.gz
+tm = thrax glue -1 src/test/resources/decoder/tree-output/glue-grammar
 
 mark_oovs = false
 
@@ -11,7 +11,7 @@ goalSymbol = GOAL
 #pruning config
 pop-limit = 100
 
-output-format = %i %t
+output-format = %t
 
 #nbest config
 use_unique_nbest = true

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/99b475b3/src/test/resources/decoder/tree-output/output.gold
----------------------------------------------------------------------
diff --git a/src/test/resources/decoder/tree-output/output.gold b/src/test/resources/decoder/tree-output/output.gold
index 68a1610..abbeb79 100644
--- a/src/test/resources/decoder/tree-output/output.gold
+++ b/src/test/resources/decoder/tree-output/output.gold
@@ -1,5 +1,5 @@
-0 (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>)
-1 ()
-2 (GOAL{0-3} (GOAL{0-2} (GOAL{0-1} <s>) (D{1-2} baz)) </s>)
-3 (GOAL{0-4} (GOAL{0-3} (GOAL{0-1} <s>) (S{1-3} I AM)) </s>)
-4 (GOAL{0-4} <s> (NP\DT{1-3} right (NN{2-3} xslot)) </s>)
+(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/99b475b3/src/test/resources/decoder/tree-output/test.sh
----------------------------------------------------------------------
diff --git a/src/test/resources/decoder/tree-output/test.sh b/src/test/resources/decoder/tree-output/test.sh
deleted file mode 100755
index ea2d126..0000000
--- a/src/test/resources/decoder/tree-output/test.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-set -u
-
-cat input | $JOSHUA/bin/joshua-decoder -m 1g -threads 1 -c joshua.config > output 2> log
-
-# Compare
-diff -u output output.gold > diff
-
-if [ $? -eq 0 ]; then
-	rm -f diff log output output.scores
-	exit 0
-else
-	exit 1
-fi