Fixed TargetBigramTest to work with new configuration. Compiles but does not 
pass yet.


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

Branch: refs/heads/7_confsystem
Commit: 14ede56c1bc51c4b92a02349c53daae735fc3ffb
Parents: 0ede005
Author: Michael A. Hedderich <michael-al...@users.noreply.github.com>
Authored: Mon Sep 19 10:10:20 2016 +0200
Committer: Michael A. Hedderich <michael-al...@users.noreply.github.com>
Committed: Mon Sep 19 10:10:20 2016 +0200

----------------------------------------------------------------------
 .../apache/joshua/decoder/cky/TargetBigram.java | 37 +++++++++++---------
 1 file changed, 21 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/14ede56c/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TargetBigram.java
----------------------------------------------------------------------
diff --git 
a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TargetBigram.java 
b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TargetBigram.java
index 30e6d1a..add96ef 100644
--- a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TargetBigram.java
+++ b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/TargetBigram.java
@@ -18,14 +18,16 @@
  */
 package org.apache.joshua.decoder.cky;
 
+import static com.typesafe.config.ConfigFactory.parseString;
 import static org.apache.joshua.decoder.cky.TestUtil.translate;
 import static org.testng.Assert.assertEquals;
 
 import org.apache.joshua.decoder.Decoder;
-import org.apache.joshua.decoder.JoshuaConfiguration;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
+import com.typesafe.config.Config;
+
 public class TargetBigram {
 
   private static final String INPUT = "this is a test";
@@ -34,36 +36,39 @@ public class TargetBigram {
   private static final String GOLD_THRESHOLD10 = "this is a test ||| 
tm_glue_0=4.000 TargetBigram_<s>_UNK=1.000 TargetBigram_UNK_</s>=1.000 
TargetBigram_UNK_is=1.000 TargetBigram_a_UNK=1.000 TargetBigram_is_a=1.000 ||| 
0.000";
 
   private static final String VOCAB_PATH = 
"src/test/resources/decoder/target-bigram/vocab";
+  private static final String CONF_TOPN2 = "output_format = %s ||| %f ||| %c 
\n feature_functions = [ { class = TargetBigram, vocab = "
+      + VOCAB_PATH + ", top-n = 2 } ]";
+  private static final String CONF_TOPN3_THRESHOLD20 = "output_format = %s ||| 
%f ||| %c \n feature_functions = [ { class = TargetBigram, vocab = "
+      + VOCAB_PATH + ", top-n = 3, threshold = 20 } ]";
+  private static final String CONF_THRESHOLD10 = "output_format = %s ||| %f 
||| %c \n feature_functions = [ { class = TargetBigram, vocab = "
+      + VOCAB_PATH + ", threshold = 10 } ]";
 
-  private JoshuaConfiguration joshuaConfig;
   private Decoder decoder;
 
   @Test
-  public void givenInput_whenNotUsingSourceAnnotations_thenOutputCorrect() 
throws Exception {
-    setUp("TargetBigram -vocab " + VOCAB_PATH + " -top-n 2");
-    String output = translate(INPUT, decoder, joshuaConfig);
+  public void 
givenInput_whenDecodingWithTargetBigramAndTopN2_thenOutputCorrect() {
+    setUp(CONF_TOPN2);
+    String output = translate(INPUT, decoder);
     assertEquals(output.trim(), GOLD_TOPN2);
   }
 
   @Test
-  public void givenInput_whenUsingSourceAnnotations_thenOutputCorrect() throws 
Exception {
-    setUp("TargetBigram -vocab " + VOCAB_PATH + " -top-n 3 -threshold 20");
-    String output = translate(INPUT, decoder, joshuaConfig);
+  public void 
givenInput_whenDecodingWithTargetBigramAndTopN3Threshold20_thenOutputCorrect() {
+    setUp(CONF_TOPN3_THRESHOLD20);
+    String output = translate(INPUT, decoder);
     assertEquals(output.trim(), GOLD_TOPN3_THRESHOLD20);
   }
 
   @Test
-  public void givenInput_whenUsingSourceAnnotations_thenOutputCorrect2() 
throws Exception {
-    setUp("TargetBigram -vocab " + VOCAB_PATH + " -threshold 10");
-    String output = translate(INPUT, decoder, joshuaConfig);
+  public void 
givenInput_whenDecodingWithTargetBigramThreshold10_thenOutputCorrect2() {
+    setUp(CONF_THRESHOLD10);
+    String output = translate(INPUT, decoder);
     assertEquals(output.trim(), GOLD_THRESHOLD10);
   }
 
-  public void setUp(String featureFunction) throws Exception {
-    joshuaConfig = new JoshuaConfiguration();
-    joshuaConfig.features.add(featureFunction);
-    joshuaConfig.outputFormat = "%s ||| %f ||| %c";
-    decoder = new Decoder(joshuaConfig);
+  public void setUp(String configuration) {
+    Config config = 
parseString(configuration).withFallback(Decoder.getDefaultFlags());
+    decoder = new Decoder(config);
   }
 
   @AfterMethod

Reply via email to