Fixed NAryTest 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/28f48103
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/28f48103
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/28f48103

Branch: refs/heads/7_confsystem
Commit: 28f48103f7ea7c9e8ad53b549f376fe38170c576
Parents: c23af30
Author: Michael A. Hedderich <michael-al...@users.noreply.github.com>
Authored: Sun Sep 18 18:25:00 2016 +0200
Committer: Michael A. Hedderich <michael-al...@users.noreply.github.com>
Committed: Sun Sep 18 18:25:00 2016 +0200

----------------------------------------------------------------------
 .../org/apache/joshua/decoder/cky/NAryTest.conf | 24 ++++++++++
 .../org/apache/joshua/decoder/cky/NAryTest.gold |  2 +
 .../org/apache/joshua/decoder/cky/NAryTest.in   |  2 +
 .../org/apache/joshua/decoder/cky/NAryTest.java | 49 ++++----------------
 4 files changed, 38 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/28f48103/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.conf
----------------------------------------------------------------------
diff --git 
a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.conf 
b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.conf
new file mode 100644
index 0000000..2fe9529
--- /dev/null
+++ b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.conf
@@ -0,0 +1,24 @@
+mark_oovs = true
+default_non_terminal = X
+goalSymbol = GOAL
+pop_limit = 100
+use_unique_nbest = true
+use_tree_nbest = false
+add_combined_cost = true
+top_n = 1
+output_format = %c %s
+weights_file = src/test/resources/decoder/n-ary/weights
+
+feature_functions = [
+  { class = LanguageModel, lm_type = kenlm, lm_order = 5, lm_file = 
src/test/resources/decoder/n-ary/lm.gz }
+  { class = WordPenalty }
+  { class = OOVPenalty }
+]
+
+grammars = [
+  { class = TextGrammar, owner = phrase, span_limit = 20, path = 
src/test/resources/decoder/n-ary/grammar }
+  { class = TextGrammar, owner = glue, span_limit = -1, path = 
src/test/resources/decoder/n-ary/glue-grammar }
+]
+
+weights = {
+}

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/28f48103/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.gold
----------------------------------------------------------------------
diff --git 
a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.gold 
b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.gold
new file mode 100644
index 0000000..742b98c
--- /dev/null
+++ b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.gold
@@ -0,0 +1,2 @@
+-11.503 Goats eat cheese
+-4.414 i will go home

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/28f48103/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.in
----------------------------------------------------------------------
diff --git 
a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.in 
b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.in
new file mode 100644
index 0000000..86437df
--- /dev/null
+++ b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.in
@@ -0,0 +1,2 @@
+CHEESE GOATS EAT
+3 1 4 2

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/28f48103/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.java
----------------------------------------------------------------------
diff --git 
a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.java 
b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.java
index 6a2071a..5c5b4bf 100644
--- a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.java
+++ b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/NAryTest.java
@@ -18,38 +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;
-
-/*
- * 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 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 NAryTest {
-  private JoshuaConfiguration joshuaConfig;
   private Decoder decoder;
 
   @AfterMethod
@@ -62,21 +41,13 @@ public class NAryTest {
 
   @Test
   public void givenInput_whenNAryDecoding_thenScoreAndTranslationCorrect() 
throws Exception {
-    // Given
-    List<String> inputStrings = 
loadStringsFromFile("src/test/resources/decoder/n-ary/input.txt");
+    String inputPath = this.getClass().getResource("NAryTest.in").getFile();
+    String goldPath = this.getClass().getResource("NAryTest.gold").getFile();
+    Config config = parseResources(this.getClass(), "NAryTest.conf")
+        .withFallback(Decoder.getDefaultFlags());
+    KenLmTestUtil.Guard(() -> decoder = new Decoder(config));
 
-    // 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);
+    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