fixed constrained decoding test I'm having some difficulty debugging errors when, for example, the config file location is given incorrectly and therefore isn't loaded. This seems to happen silently without any informative error. Just mentioning this to be sure it's on the docket.
Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/8f47187e Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/8f47187e Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/8f47187e Branch: refs/heads/7_confsystem Commit: 8f47187e4a5d8d4ea5940165b88eec1d7615610b Parents: fbe6c5f Author: Matt Post <p...@cs.jhu.edu> Authored: Sat Sep 17 23:24:57 2016 +0200 Committer: Matt Post <p...@cs.jhu.edu> Committed: Sat Sep 17 23:24:57 2016 +0200 ---------------------------------------------------------------------- .../joshua/decoder/cky/ConstrainedTest.java | 84 ++++++++++---------- .../resources/decoder/constrained/gold.scores | 27 ------- .../test/resources/decoder/constrained/input.bn | 8 -- .../resources/decoder/constrained/joshua.config | 45 ----------- .../resources/decoder/constrained/output.bleu | 0 .../resources/decoder/constrained/output.gold | 30 ------- .../test/resources/decoder/constrained/test.sh | 30 ------- .../test/resources/decoder/constrained/weights | 22 ----- 8 files changed, 40 insertions(+), 206 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/8f47187e/joshua-core/src/test/java/org/apache/joshua/decoder/cky/ConstrainedTest.java ---------------------------------------------------------------------- diff --git a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/ConstrainedTest.java b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/ConstrainedTest.java index 7a2a7b4..70f4108 100644 --- a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/ConstrainedTest.java +++ b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/ConstrainedTest.java @@ -1,23 +1,20 @@ /* - * 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 + * 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 + * 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. + * 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 com.typesafe.config.ConfigFactory.parseResources; import static org.apache.joshua.decoder.cky.TestUtil.decodeList; import static org.apache.joshua.decoder.cky.TestUtil.loadStringsFromFile; import static org.testng.Assert.assertEquals; @@ -29,36 +26,35 @@ import org.apache.joshua.util.io.KenLmTestUtil; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; -public class ConstrainedTest { - - private JoshuaConfiguration joshuaConfig; - private Decoder decoder; - - @AfterMethod - public void tearDown() throws Exception { - if(decoder != null) { - decoder.cleanUp(); - decoder = null; - } - } +import com.typesafe.config.Config; - @Test - public void givenInput_whenConstrainedDecoding_thenScoreAndTranslationCorrect() throws Exception { - // Given - List<String> inputStrings = loadStringsFromFile("src/test/resources/decoder/constrained/input.bn"); - - // When - configureDecoder("src/test/resources/decoder/constrained/joshua.config"); - List<String> decodedStrings = decodeList(inputStrings, decoder, joshuaConfig); +public class ConstrainedTest { - // Then - List<String> goldStrings = loadStringsFromFile("src/test/resources/decoder/constrained/output.gold"); - assertEquals(decodedStrings, goldStrings); - } - - public void configureDecoder(String pathToConfig) throws Exception { - joshuaConfig = new JoshuaConfiguration(); - joshuaConfig.readConfigFile(pathToConfig); - KenLmTestUtil.Guard(() -> decoder = new Decoder(joshuaConfig)); - } + private Decoder decoder; + + @AfterMethod + public void tearDown() throws Exception { + if (decoder != null) { + decoder.cleanUp(); + decoder = null; + } + } + + @Test + public void givenInput_whenConstrainedDecoding_thenScoreAndTranslationCorrect() throws Exception { + // Given + List<String> inputStrings = loadStringsFromFile(this.getClass().getResource("ConstrainedTest.in").getFile()); + + // When + Config config = parseResources(this.getClass(), "ConstrainedTest.conf") + .withFallback(Decoder.getDefaultFlags()); + decoder = new Decoder(config); + + List<String> decodedStrings = decodeList(inputStrings, decoder); + + // Then + List<String> goldStrings = loadStringsFromFile(this.getClass().getResource("ConstrainedTest.gold").getFile()); + + assertEquals(decodedStrings, goldStrings); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/8f47187e/joshua-core/src/test/resources/decoder/constrained/gold.scores ---------------------------------------------------------------------- diff --git a/joshua-core/src/test/resources/decoder/constrained/gold.scores b/joshua-core/src/test/resources/decoder/constrained/gold.scores deleted file mode 100644 index 4b90eb1..0000000 --- a/joshua-core/src/test/resources/decoder/constrained/gold.scores +++ /dev/null @@ -1,27 +0,0 @@ - mathematics so science language . ||| -10.471 - mathematics is science language . ||| -10.543 - mathematics that science language . ||| -11.587 - science mathematics that language . ||| -12.065 - mathematics so that the science language . ||| -12.259 - mathematics hence science language . ||| -12.352 - mathematics that is science language . ||| -12.590 - mathematics , science language . ||| -12.619 - mathematics that is why science language . ||| -12.751 - mathematics in science language . ||| -12.755 - mathematics is science language . ||| -10.543 - rabindranath born in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -226.523 - rabindranath 's birth in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -227.201 - rabindranath was born in kolkata a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -227.217 - rabindranath was born in a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -227.417 - rabindranath born in kolkata is one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -227.707 - rabindranath was born in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -228.000 - rabindranath was born in kolkata in a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -228.133 - rabindranath was born in kolkata one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -228.160 - rabindranath born in kolkata a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -228.266 - rabindranath 's birth in kolkata is one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -228.386 - rabindranath was born in a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -226.302 - rabindranath born in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -226.523 - rabindranath born in kolkata is one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -227.707 - rabindranath born in in kolkata is one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -232.123 - rabindranath was born in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -227.643 - rabindranath born in kolkata was one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family ||| -229.108 http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/8f47187e/joshua-core/src/test/resources/decoder/constrained/input.bn ---------------------------------------------------------------------- diff --git a/joshua-core/src/test/resources/decoder/constrained/input.bn b/joshua-core/src/test/resources/decoder/constrained/input.bn deleted file mode 100644 index 291bca0..0000000 --- a/joshua-core/src/test/resources/decoder/constrained/input.bn +++ /dev/null @@ -1,8 +0,0 @@ -à¦à¦£à¦¿à¦¤ তাঠবিà¦à§à¦à¦¾à¦¨à§à¦° à¦à¦¾à¦·à¦¾ । -à¦à¦£à¦¿à¦¤ তাঠবিà¦à§à¦à¦¾à¦¨à§à¦° à¦à¦¾à¦·à¦¾ । ||| mathematics is science language . -রবà§à¦¨à§à¦¦à§à¦°à¦¨à¦¾à¦¥à§à¦° à¦à¦¨à§à¦® হয়à§à¦à¦¿à¦² à¦à¦²à¦à¦¾à¦¤à¦¾à¦° à¦à¦ পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ পরিবারৠ। -রবà§à¦¨à§à¦¦à§à¦°à¦¨à¦¾à¦¥à§à¦° à¦à¦¨à§à¦® হয়à§à¦à¦¿à¦² à¦à¦²à¦à¦¾à¦¤à¦¾à¦° à¦à¦ পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ পরিবারৠ। ||| rabindranath was born in a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family -রবà§à¦¨à§à¦¦à§à¦°à¦¨à¦¾à¦¥à§à¦° à¦à¦¨à§à¦® হয়à§à¦à¦¿à¦² à¦à¦²à¦à¦¾à¦¤à¦¾à¦° à¦à¦ পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ পরিবারৠ। ||| rabindranath born in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family -রবà§à¦¨à§à¦¦à§à¦°à¦¨à¦¾à¦¥à§à¦° à¦à¦¨à§à¦® হয়à§à¦à¦¿à¦² à¦à¦²à¦à¦¾à¦¤à¦¾à¦° à¦à¦ পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ পরিবারৠ। ||| rabindranath born in kolkata is one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family -রবà§à¦¨à§à¦¦à§à¦°à¦¨à¦¾à¦¥à§à¦° à¦à¦¨à§à¦® হয়à§à¦à¦¿à¦² à¦à¦²à¦à¦¾à¦¤à¦¾à¦° à¦à¦ পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ পরিবারৠ। ||| rabindranath was born in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family -রবà§à¦¨à§à¦¦à§à¦°à¦¨à¦¾à¦¥à§à¦° à¦à¦¨à§à¦® হয়à§à¦à¦¿à¦² à¦à¦²à¦à¦¾à¦¤à¦¾à¦° à¦à¦ পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ পরিবারৠ। ||| rabindranath born in kolkata was one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/8f47187e/joshua-core/src/test/resources/decoder/constrained/joshua.config ---------------------------------------------------------------------- diff --git a/joshua-core/src/test/resources/decoder/constrained/joshua.config b/joshua-core/src/test/resources/decoder/constrained/joshua.config deleted file mode 100644 index 8871cbb..0000000 --- a/joshua-core/src/test/resources/decoder/constrained/joshua.config +++ /dev/null @@ -1,45 +0,0 @@ -lm = kenlm 5 false false 100 src/test/resources/decoder/constrained/lm.gz - -tm = thrax pt 12 src/test/resources/decoder/constrained/grammar.gz -tm = thrax glue -1 src/test/resources/decoder/constrained/glue-grammar - -mark_oovs = false - -default-non-terminal = X -goalSymbol = GOAL - -#pruning config -pop-limit = 100 - -output-format = %c %s - -#nbest config -use_unique_nbest = true -top_n = 10 - -feature-function = WordPenalty -feature-function = OOVPenalty - - -lm_0 1.2373676802179452 - -pt_0 2.4497429277910214 -pt_1 -0.7224581556224123 -pt_2 0.31689069155153504 -pt_3 -0.33861043967238036 -pt_4 -0.03553113401320236 -pt_5 -0.19138972284064748 -pt_6 -0.3417994095521415 -pt_7 0.9936312455671283 -pt_8 -0.9070737587091975 -pt_9 -0.8202511858619419 -pt_10 -0.2593091306160006 -pt_11 -0.25597137004462134 -pt_12 -0.3538894647790496 -pt_13 0.36212061186692646 -pt_14 0.32923261148678096 -pt_15 -0.5524863522177359 -pt_16 -0.23451595442127693 -glue_0 -1 -WordPenalty -3.6942747832593694 -OOVPenalty 1.0 http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/8f47187e/joshua-core/src/test/resources/decoder/constrained/output.bleu ---------------------------------------------------------------------- diff --git a/joshua-core/src/test/resources/decoder/constrained/output.bleu b/joshua-core/src/test/resources/decoder/constrained/output.bleu deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/8f47187e/joshua-core/src/test/resources/decoder/constrained/output.gold ---------------------------------------------------------------------- diff --git a/joshua-core/src/test/resources/decoder/constrained/output.gold b/joshua-core/src/test/resources/decoder/constrained/output.gold deleted file mode 100644 index a48d5cb..0000000 --- a/joshua-core/src/test/resources/decoder/constrained/output.gold +++ /dev/null @@ -1,30 +0,0 @@ --10.471 mathematics so science language . --10.543 mathematics is science language . --11.587 mathematics that science language . --12.065 science mathematics that language . --12.259 mathematics so that the science language . --12.352 mathematics hence science language . --12.590 mathematics that is science language . --12.619 mathematics , science language . --12.751 mathematics that is why science language . --12.755 mathematics in science language . --10.543 mathematics is science language . --226.302 rabindranath was born in a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --226.523 rabindranath born in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --226.884 rabindranath was born in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --227.201 rabindranath 's birth in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --227.217 rabindranath was born in kolkata a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --227.707 rabindranath born in kolkata is one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --227.982 rabindranath was born in the a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --228.069 rabindranath was born in kolkata is one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --228.133 rabindranath was born in kolkata in a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --228.160 rabindranath was born in kolkata one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --226.302 rabindranath was born in a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --226.523 rabindranath born in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --230.920 rabindranath born in in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --227.707 rabindranath born in kolkata is one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --232.123 rabindranath born in in kolkata is one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --226.884 rabindranath was born in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --231.320 rabindranath was born kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --232.836 rabindranath was born in in kolkata is a পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family --229.108 rabindranath born in kolkata was one পিরালৠবà§à¦°à¦¾à¦¹à§à¦®à¦£ in the family http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/8f47187e/joshua-core/src/test/resources/decoder/constrained/test.sh ---------------------------------------------------------------------- diff --git a/joshua-core/src/test/resources/decoder/constrained/test.sh b/joshua-core/src/test/resources/decoder/constrained/test.sh deleted file mode 100755 index b21e2ff..0000000 --- a/joshua-core/src/test/resources/decoder/constrained/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.bn | $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 http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/8f47187e/joshua-core/src/test/resources/decoder/constrained/weights ---------------------------------------------------------------------- diff --git a/joshua-core/src/test/resources/decoder/constrained/weights b/joshua-core/src/test/resources/decoder/constrained/weights deleted file mode 100644 index c4e32e7..0000000 --- a/joshua-core/src/test/resources/decoder/constrained/weights +++ /dev/null @@ -1,22 +0,0 @@ -lm_0 1.2373676802179452 - -tm_pt_0 -2.4497429277910214 -tm_pt_1 0.7224581556224123 -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 -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_glue_0 1 -WordPenalty -3.6942747832593694 -OOVPenalty -100.0