You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@joshua.apache.org by le...@apache.org on 2016/05/16 06:27:13 UTC
[57/66] incubator-joshua git commit: JOSHUA-252 Make it possible to
use Maven to build Joshua
JOSHUA-252 Make it possible to use Maven to build Joshua
Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/f401535f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/f401535f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/f401535f
Branch: refs/heads/JOSHUA-252
Commit: f401535f5b50487c5c6e1f17c954904e32e5d2fb
Parents: 89e2275
Author: Lewis John McGibbney <le...@gmail.com>
Authored: Sat May 14 01:44:43 2016 -0700
Committer: Lewis John McGibbney <le...@gmail.com>
Committed: Sat May 14 01:44:43 2016 -0700
----------------------------------------------------------------------
lib/.gitignore | 13 --
lib/BerkeleyParser.jar | Bin 3092739 -> 0 bytes
lib/LICENSES/LICENSE-jung.txt | 45 ----
lib/LICENSES/LICENSE-pmd.txt | 36 ---
lib/README | 26 ---
lib/berkeleyaligner.jar | Bin 1202003 -> 0 bytes
lib/eng_sm6.gr | Bin 22243222 -> 0 bytes
lib/fastutil.jar | Bin 13943025 -> 0 bytes
lib/ghkm-modified.jar | Bin 3883068 -> 0 bytes
lib/ivy.xml | 17 --
lib/ivysettings.xml | 18 --
lib/jacana-xy.jar | Bin 19949544 -> 0 bytes
pom.xml | 14 +-
.../joshua/decoder/phrase/CoverageTest.java | 140 ------------
.../apache/joshua/corpus/VocabularyTest.java | 135 ++++++++++++
.../decoder/ff/lm/LanguageModelFFTest.java | 94 ++++++++
.../LMBerkeleySentenceProbablityTest.java | 47 ++++
.../lm/berkeley_lm/LMGrammarBerkeleyTest.java | 80 +++++++
.../kbest_extraction/KBestExtractionTest.java | 80 +++++++
.../joshua/decoder/phrase/CoverageTest.java | 140 ++++++++++++
.../ConstrainedPhraseDecodingTest.java | 77 +++++++
.../phrase/decode/PhraseDecodingTest.java | 77 +++++++
.../apache/joshua/system/AlignmentMapTest.java | 72 ++++++
.../org/apache/joshua/system/KenLmTest.java | 95 ++++++++
.../system/MultithreadedTranslationTests.java | 140 ++++++++++++
.../joshua/system/StructuredOutputTest.java | 121 +++++++++++
.../system/StructuredTranslationTest.java | 217 +++++++++++++++++++
.../org/apache/joshua/util/FormatUtilsTest.java | 78 +++++++
tst/joshua/corpus/VocabularyTest.java | 118 ----------
.../decoder/ff/lm/LanguageModelFFTest.java | 94 --------
.../LMBerkeleySentenceProbablityTest.java | 29 ---
.../lm/berkeley_lm/LMGrammarBerkeleyTest.java | 62 ------
.../kbest_extraction/KBestExtractionTest.java | 80 -------
.../ConstrainedPhraseDecodingTest.java | 77 -------
.../phrase/decode/PhraseDecodingTest.java | 77 -------
tst/joshua/system/AlignmentMapTest.java | 72 ------
tst/joshua/system/KenLmTest.java | 95 --------
.../system/MultithreadedTranslationTests.java | 141 ------------
tst/joshua/system/StructuredOutputTest.java | 121 -----------
.../system/StructuredTranslationTest.java | 217 -------------------
tst/joshua/util/FormatUtilsTest.java | 78 -------
41 files changed, 1461 insertions(+), 1562 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/lib/.gitignore
----------------------------------------------------------------------
diff --git a/lib/.gitignore b/lib/.gitignore
deleted file mode 100644
index 767c106..0000000
--- a/lib/.gitignore
+++ /dev/null
@@ -1,13 +0,0 @@
-*
-cache/
-!.gitignore
-!BerkeleyParser.jar
-!LICENSES
-!README
-!berkeleyaligner.jar
-!berkeleylm.jar
-!collections-generic-4.01.jar
-!eng_sm6.gr
-!ivy.xml
-!ivysettings.xml
-!jacana-xy.jar
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/lib/BerkeleyParser.jar
----------------------------------------------------------------------
diff --git a/lib/BerkeleyParser.jar b/lib/BerkeleyParser.jar
deleted file mode 100644
index 6a66023..0000000
Binary files a/lib/BerkeleyParser.jar and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/lib/LICENSES/LICENSE-jung.txt
----------------------------------------------------------------------
diff --git a/lib/LICENSES/LICENSE-jung.txt b/lib/LICENSES/LICENSE-jung.txt
deleted file mode 100644
index 78f7ffa..0000000
--- a/lib/LICENSES/LICENSE-jung.txt
+++ /dev/null
@@ -1,45 +0,0 @@
-According to http://jung.sourceforge.net/faq.html, "JUNG is licensed
-and made freely available under the Berkeley Software Distribution
-(BSD) license." This is confirmed by http://sourceforge.net/projects/jung.
-However no license file is made available either on the website or
-in any of the sources that can be downloaded.
-
-Therefore we assume this definition from
-http://www.opensource.org/licenses/bsd-license.php; this should be
-replaced by an actual license once one becomes available.
-
-
- JUNG is licensed under a "BSD-style" license:
-
-Copyright (c) 2003--2009, JUNG Framework Development Team
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
-* Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
-* Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
-
-* Neither the name of the Java Universal Network/Graph Framework
- nor the names of its contributors may be used to endorse or promote
- products derived from this software without specific prior written
- permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/lib/LICENSES/LICENSE-pmd.txt
----------------------------------------------------------------------
diff --git a/lib/LICENSES/LICENSE-pmd.txt b/lib/LICENSES/LICENSE-pmd.txt
deleted file mode 100644
index 4323694..0000000
--- a/lib/LICENSES/LICENSE-pmd.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-This licence is copied from http://pmd.sourceforge.net/license.html
-
-
- PMD is licensed under a "BSD-style" license:
-
-Copyright (c) 2002-2009, InfoEther, Inc
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
-notice, this list of conditions and the following disclaimer in the
-documentation and/or other materials provided with the distribution.
- * The end-user documentation included with the redistribution, if
-any, must include the following acknowledgement:
- "This product includes software developed in part by support from
-the Defense Advanced Research Project Agency (DARPA)"
- * Neither the name of InfoEther, LLC nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/lib/README
----------------------------------------------------------------------
diff --git a/lib/README b/lib/README
deleted file mode 100644
index 588e75a..0000000
--- a/lib/README
+++ /dev/null
@@ -1,26 +0,0 @@
-This file contains a listing of which packages in Joshua require
-which jar files.
-
-
-The "pmd" Ant task (not actually Joshua code) requires:
-* pmd-4.2.5.jar
-* jaxen-1.1.1.jar
-* asm-3.1.jar
-
-
-The "test" Ant task (not actually Joshua code) requires:
-* testng-5.8-jdk15.jar
-
-
-The joshua.ui.alignment_visualizer.* and joshua.ui.tree_visualizer.*
-code requires:
-* jung-api-2.0.jar
-* jung-graph-impl-2.0.jar
-* jung-algorithms-2.0.jar
-* jung-visualization-2.0.jar
-* collections-generic-4.01.jar
-
-
-The joshua.subsample.* code requires:
-* commons-cli-2.0-SNAPSHOT.jar
-(But we hope to remove this dependency in the future.)
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/lib/berkeleyaligner.jar
----------------------------------------------------------------------
diff --git a/lib/berkeleyaligner.jar b/lib/berkeleyaligner.jar
deleted file mode 100644
index 63c4e96..0000000
Binary files a/lib/berkeleyaligner.jar and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/lib/eng_sm6.gr
----------------------------------------------------------------------
diff --git a/lib/eng_sm6.gr b/lib/eng_sm6.gr
deleted file mode 100644
index 4aa1036..0000000
Binary files a/lib/eng_sm6.gr and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/lib/fastutil.jar
----------------------------------------------------------------------
diff --git a/lib/fastutil.jar b/lib/fastutil.jar
deleted file mode 100644
index 5e4700d..0000000
Binary files a/lib/fastutil.jar and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/lib/ghkm-modified.jar
----------------------------------------------------------------------
diff --git a/lib/ghkm-modified.jar b/lib/ghkm-modified.jar
deleted file mode 100644
index f59fec4..0000000
Binary files a/lib/ghkm-modified.jar and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/lib/ivy.xml
----------------------------------------------------------------------
diff --git a/lib/ivy.xml b/lib/ivy.xml
deleted file mode 100644
index d41595d..0000000
--- a/lib/ivy.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<ivy-module version="2.0">
- <info organisation="joshua" module="joshua"/>
- <dependencies>
- <dependency org="net.sourceforge.ant-doxygen" name="ant-doxygen" rev="1.6.1" />
- <dependency org="net.sf.jung" name="jung-algorithms" rev="2.0"/>
- <dependency org="net.sf.jung" name="jung-api" rev="2.0"/>
- <dependency org="net.sf.jung" name="jung-graph-impl" rev="2.0"/>
- <dependency org="net.sf.jung" name="jung-visualization" rev="2.0"/>
- <dependency org="org.apache.commons" name="commons-cli" rev="1.2"/>
- <dependency org="org.testng" name="testng" rev="6.7"/>
- <dependency org="junit" name="junit" rev="4.10" />
- <dependency org="net.sourceforge.collections" name="collections-generic" rev="4.01"/>
- <dependency org="args4j" name="args4j" rev="2.0.29" />
- <dependency org="com.google.code.gson" name="gson" rev="2.5"/>
- <dependency org="com.google.guava" name="guava" rev="19.0"/>
- </dependencies>
-</ivy-module>
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/lib/ivysettings.xml
----------------------------------------------------------------------
diff --git a/lib/ivysettings.xml b/lib/ivysettings.xml
deleted file mode 100644
index a6fd635..0000000
--- a/lib/ivysettings.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0"?>
-<ivysettings >
- <settings defaultResolver="1" />
- <resolvers>
- <chain name="1" returnFirst="true" dual="true">
- <filesystem name="filesystem">
- <ivy pattern="${ivy.settings.dir}/cache/[organisation]/[module]/ivys/ivy-[revision].xml"/>
- <artifact pattern="${ivy.settings.dir}/[artifact]-[revision].[ext]"/>
- </filesystem>
- <ibiblio name="central" m2compatible="true"/>
- <ibiblio name="tools.gbif.org" m2compatible="true" root="http://tools.gbif.org/maven/repository/" />
- <packager name="roundup" buildRoot="${JOSHUA}/lib/packager/build" resourceCache="${JOSHUA}/lib/cache">
- <ivy pattern="http://ivyroundup.googlecode.com/svn/trunk/repo/modules/[organisation]/[module]/[revision]/ivy.xml"/>
- <artifact pattern="http://ivyroundup.googlecode.com/svn/trunk/repo/modules/[organisation]/[module]/[revision]/packager.xml"/>
- </packager>
- </chain>
- </resolvers>
-</ivysettings>
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/lib/jacana-xy.jar
----------------------------------------------------------------------
diff --git a/lib/jacana-xy.jar b/lib/jacana-xy.jar
deleted file mode 100644
index 00e0ff6..0000000
Binary files a/lib/jacana-xy.jar and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 73d1449..b309eb1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -154,12 +154,6 @@
<optional>true</optional>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.10</version>
- <optional>true</optional>
- </dependency>
- <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
@@ -174,5 +168,13 @@
<artifactId>args4j</artifactId>
<version>2.0.29</version>
</dependency>
+
+ <!-- Test Dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/main/java/org/apache/joshua/decoder/phrase/CoverageTest.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/phrase/CoverageTest.java b/src/main/java/org/apache/joshua/decoder/phrase/CoverageTest.java
deleted file mode 100644
index 7526b1f..0000000
--- a/src/main/java/org/apache/joshua/decoder/phrase/CoverageTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * 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.phrase;
-
-import static org.junit.Assert.*;
-
-import java.util.BitSet;
-
-import org.junit.Test;
-
-public class CoverageTest {
-
- @Test
- public void testSet() {
- Coverage cov = new Coverage();
- cov.set(1,2);
- cov.set(3,4);
- cov.set(2,3);
- cov.set(0,1);
-
- assertFalse(cov.compatible(0, 1));
- assertFalse(cov.compatible(0, 5));
- assertTrue(cov.compatible(4, 6));
-
- assertEquals(cov.toString(), "4 ..........");
- }
-
- @Test
- public void testPattern() {
- Coverage cov = new Coverage();
- cov.set(5,6);
- cov.set(0,4);
- BitSet bits = cov.pattern(4, 5);
- BitSet answerBits = new BitSet();
- answerBits.set(0);
- assertEquals(bits, answerBits);
- }
-
- @Test
- public void testCopyConstructor() {
- Coverage a = new Coverage();
- a.set(2,3);
- Coverage b = new Coverage(a);
- b.set(4,5);
-
- assertFalse(a.toString().equals(b.toString()));
- }
-
- @Test
- public void testCompatible() {
- Coverage a = new Coverage();
- a.set(10, 14);
-
- assertTrue(a.compatible(14, 16));
- assertTrue(a.compatible(6, 10));
- assertTrue(a.compatible(1, 10));
- assertTrue(a.compatible(1, 9));
- assertFalse(a.compatible(9, 11));
- assertFalse(a.compatible(13, 15));
- assertFalse(a.compatible(9, 15));
- assertFalse(a.compatible(9, 14));
- assertFalse(a.compatible(10, 15));
-
- a.set(0,9);
-
- for (int width = 1; width <= 3; width++) {
- for (int i = 0; i < 20; i++) {
- int j = i + width;
- if ((i == 9 && j == 10) || i >= 14)
- assertTrue(a.compatible(i,j));
- else {
-// System.err.println(String.format("%d,%d -> %s %s", i, j, a.compatible(i,j), a));
- assertFalse(a.compatible(i,j));
- }
- }
- }
- }
-
- @Test
- public void testFirstZero() {
- Coverage cov = new Coverage();
- cov.set(2, 5);
- assertEquals(cov.firstZero(), 0);
- cov.set(8,10);
- assertEquals(cov.firstZero(), 0);
- cov.set(0, 2);
- assertEquals(cov.firstZero(), 5);
- cov.set(5, 7);
- assertEquals(cov.firstZero(), 7);
- cov.set(7,8);
- assertEquals(cov.firstZero(), 10);
- }
-
- @Test
- public void testOpenings() {
- Coverage cov = new Coverage();
- cov.set(0, 2);
- cov.set(8, 10);
-
- for (int i = 2; i < 7; i++) {
- assertEquals(cov.leftOpening(i), 2);
- assertEquals(cov.rightOpening(i, 17), 8);
- assertEquals(cov.rightOpening(i, 7), 7);
- }
- }
-
- @Test
- public void testEquals() {
- Coverage cov = new Coverage();
- cov.set(9, 11);
- Coverage cov2 = new Coverage();
- cov2.set(9,10);
- cov2.set(10,11);
- assertEquals(cov, cov2);
- }
-
- @Test
- public void testToString() {
- Coverage cov = new Coverage();
- cov.set(0, 40);
- cov.set(44, 49);
- assertEquals(cov.toString(), "40 ....xxxxx.");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/corpus/VocabularyTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/corpus/VocabularyTest.java b/src/test/java/org/apache/joshua/corpus/VocabularyTest.java
new file mode 100644
index 0000000..ad03378
--- /dev/null
+++ b/src/test/java/org/apache/joshua/corpus/VocabularyTest.java
@@ -0,0 +1,135 @@
+/*
+ * 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.corpus;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class VocabularyTest {
+ private static final String WORD1 = "word1";
+ private static final String WORD2 = "word2";
+ private static final String NON_TERMINAL = "[X]";
+ private static final String GOAL = "[GOAL]";
+
+ @Before
+ public void init() {
+ Vocabulary.clear();
+ }
+
+ @After
+ public void deinit() {
+ Vocabulary.clear();
+ }
+
+ @Test
+ public void givenVocabulary_whenEmpty_thenOnlyContainsUnknownWord() {
+ assertTrue(Vocabulary.hasId(Vocabulary.UNKNOWN_ID));
+ assertFalse(Vocabulary.hasId(1));
+ assertFalse(Vocabulary.hasId(-1));
+ assertEquals(Vocabulary.UNKNOWN_WORD, Vocabulary.word(Vocabulary.UNKNOWN_ID));
+ assertEquals(1, Vocabulary.size());
+ }
+
+ @Test
+ public void givenVocabulary_whenNewWord_thenMappingIsAdded() {
+ final int FIRST_WORD_ID = 1;
+ assertFalse(Vocabulary.hasId(FIRST_WORD_ID));
+ assertEquals(FIRST_WORD_ID, Vocabulary.id(WORD1));
+ //should return same id after second call:
+ assertEquals(FIRST_WORD_ID, Vocabulary.id(WORD1));
+ assertTrue(Vocabulary.hasId(FIRST_WORD_ID));
+ assertEquals(WORD1, Vocabulary.word(FIRST_WORD_ID));
+ assertEquals(2, Vocabulary.size());
+ }
+
+ @Test
+ public void givenVocabulary_whenCheckingStringInBracketsOrNegativeNumber_thenIsNonTerminal() {
+ //non-terminals
+ assertTrue(Vocabulary.nt(NON_TERMINAL));
+ //terminals
+ assertFalse(Vocabulary.nt(WORD1));
+ assertFalse(Vocabulary.nt("[]"));
+ assertFalse(Vocabulary.nt("["));
+ assertFalse(Vocabulary.nt("]"));
+ assertFalse(Vocabulary.nt(""));
+
+ //negative numbers indicate non-terminals
+ assertTrue(Vocabulary.nt(-1));
+ assertTrue(Vocabulary.nt(-5));
+
+ //positive numbers indicate terminals:
+ assertFalse(Vocabulary.nt(0));
+ assertFalse(Vocabulary.nt(5));
+
+
+ }
+
+ @Test
+ public void givenVocabulary_whenNonTerminal_thenReturnsStrictlyPositiveNonTerminalIndices() {
+ final int FIRST_NON_TERMINAL_INDEX = 1;
+ assertTrue(Vocabulary.id(NON_TERMINAL) < 0);
+ assertTrue(Vocabulary.hasId(FIRST_NON_TERMINAL_INDEX));
+ assertTrue(Vocabulary.hasId(-FIRST_NON_TERMINAL_INDEX));
+
+ assertTrue(Vocabulary.id("") > 0);
+ assertTrue(Vocabulary.id(WORD1) > 0);
+
+ final int SECOND_NON_TERMINAL_INDEX = 4;
+ assertTrue(Vocabulary.id(GOAL) < 0);
+ assertTrue(Vocabulary.hasId(SECOND_NON_TERMINAL_INDEX));
+ assertTrue(Vocabulary.hasId(-SECOND_NON_TERMINAL_INDEX));
+
+ assertTrue(Vocabulary.id(WORD2) > 0);
+ }
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+
+ @Test
+ public void givenVocabulary_whenWritenAndReading_thenVocabularyStaysTheSame() throws IOException {
+ File vocabFile = folder.newFile();
+
+ int id1 = Vocabulary.id(WORD1);
+ int id2 = Vocabulary.id(NON_TERMINAL);
+ int id3 = Vocabulary.id(WORD2);
+
+ Vocabulary.write(vocabFile.getAbsolutePath());
+
+ Vocabulary.clear();
+
+ Vocabulary.read(vocabFile);
+
+ assertEquals(4, Vocabulary.size()); //unknown word + 3 other words
+ assertTrue(Vocabulary.hasId(id1));
+ assertTrue(Vocabulary.hasId(id2));
+ assertTrue(Vocabulary.hasId(id3));
+ assertEquals(id1, Vocabulary.id(WORD1));
+ assertEquals(id2, Vocabulary.id(NON_TERMINAL));
+ assertEquals(id3, Vocabulary.id(WORD2));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/decoder/ff/lm/LanguageModelFFTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/decoder/ff/lm/LanguageModelFFTest.java b/src/test/java/org/apache/joshua/decoder/ff/lm/LanguageModelFFTest.java
new file mode 100644
index 0000000..da8218b
--- /dev/null
+++ b/src/test/java/org/apache/joshua/decoder/ff/lm/LanguageModelFFTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.ff.lm;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.joshua.corpus.Vocabulary;
+import org.apache.joshua.decoder.Decoder;
+import org.apache.joshua.decoder.JoshuaConfiguration;
+import org.apache.joshua.decoder.ff.FeatureVector;
+import org.apache.joshua.decoder.ff.state_maintenance.NgramDPState;
+
+public class LanguageModelFFTest {
+
+ private static final float WEIGHT = 0.5f;
+
+ private LanguageModelFF ff;
+
+ @Before
+ public void setUp() {
+ Decoder.resetGlobalState();
+
+ FeatureVector weights = new FeatureVector();
+ weights.set("lm_0", WEIGHT);
+ String[] args = {"-lm_type", "berkeleylm", "-lm_order", "2", "-lm_file", "./joshua/test/lm/berkeley/lm"};
+
+ JoshuaConfiguration config = new JoshuaConfiguration();
+ ff = new LanguageModelFF(weights, args, config);
+ }
+
+ @After
+ public void tearDown() {
+ Decoder.resetGlobalState();
+ }
+
+ @Test
+ public void givenNonStartSymbol_whenEstimateFutureCost_thenMultipleWeightAndLogProbabilty() {
+ int[] left = {3};
+ NgramDPState currentState = new NgramDPState(left, new int[left.length]);
+
+ float score = ff.languageModel.sentenceLogProbability(left, 2, 1);
+ assertEquals(-99.0f, score, 0.0);
+
+ float cost = ff.estimateFutureCost(null, currentState, null);
+ assertEquals(score * WEIGHT, cost, 0.0);
+ }
+
+ @Test
+ public void givenOnlyStartSymbol_whenEstimateFutureCost_thenZeroResult() {
+ int startSymbolId = Vocabulary.id(Vocabulary.START_SYM);
+ int[] left = {startSymbolId};
+ NgramDPState currentState = new NgramDPState(left, new int[left.length]);
+
+ float score = ff.languageModel.sentenceLogProbability(left, 2, 2);
+ assertEquals(0.0f, score, 0.0);
+
+ float cost = ff.estimateFutureCost(null, currentState, null);
+ assertEquals(score * WEIGHT, cost, 0.0);
+ }
+
+ @Test
+ public void givenStartAndOneMoreSymbol_whenEstimateFutureCost_thenMultipleWeightAndLogProbabilty() {
+ int startSymbolId = Vocabulary.id(Vocabulary.START_SYM);
+ assertNotEquals(startSymbolId, 3);
+ int[] left = {startSymbolId, 3};
+ NgramDPState currentState = new NgramDPState(left, new int[left.length]);
+
+ float score = ff.languageModel.sentenceLogProbability(left, 2, 2);
+ assertEquals(-100.752754f, score, 0.0f);
+
+ float cost = ff.estimateFutureCost(null, currentState, null);
+ assertEquals(score * WEIGHT, cost, 0.0f);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMBerkeleySentenceProbablityTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMBerkeleySentenceProbablityTest.java b/src/test/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMBerkeleySentenceProbablityTest.java
new file mode 100644
index 0000000..bcc1039
--- /dev/null
+++ b/src/test/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMBerkeleySentenceProbablityTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.ff.lm.berkeley_lm;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import edu.berkeley.nlp.lm.ArrayEncodedNgramLanguageModel;
+
+public class LMBerkeleySentenceProbablityTest {
+
+ @Test
+ public void verifySentenceLogProbability() {
+ LMGrammarBerkeley grammar = new LMGrammarBerkeley(2, "resources/berkeley_lm/lm");
+ grammar.registerWord("the", 2);
+ grammar.registerWord("chat-rooms", 3);
+ grammar.registerWord("<unk>", 0);
+
+ ArrayEncodedNgramLanguageModel<String> lm = grammar.getLM();
+ float expected =
+ lm.getLogProb(new int[] {}, 0, 0)
+ + lm.getLogProb(new int[] {0}, 0, 1)
+ + lm.getLogProb(new int[] {0, 2}, 0, 2)
+ + lm.getLogProb(new int[] {2, 3}, 0, 2)
+ + lm.getLogProb(new int[] {3, 0}, 0, 2);
+
+ float result = grammar.sentenceLogProbability(new int[] {0, 2, 3, 0}, 2, 0);
+ assertEquals(expected, result, 0.0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMGrammarBerkeleyTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMGrammarBerkeleyTest.java b/src/test/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMGrammarBerkeleyTest.java
new file mode 100644
index 0000000..2c4b859
--- /dev/null
+++ b/src/test/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMGrammarBerkeleyTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.ff.lm.berkeley_lm;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+import org.apache.joshua.decoder.Decoder;
+import org.apache.joshua.decoder.JoshuaConfiguration;
+import org.apache.joshua.decoder.Translation;
+import org.apache.joshua.decoder.segment_file.Sentence;
+
+/**
+ * Replacement for test/lm/berkeley/test.sh regression test
+ */
+@RunWith(Parameterized.class)
+public class LMGrammarBerkeleyTest {
+
+ private static final String INPUT = "the chat-rooms";
+ private static final String[] OPTIONS = "-v 0 -output-format %f".split(" ");
+
+ private JoshuaConfiguration joshuaConfig;
+ private Decoder decoder;
+
+ @Parameters
+ public static List<String> lmFiles() {
+ return Arrays.asList("resources/berkeley_lm/lm",
+ "resources/berkeley_lm/lm.gz",
+ "resources/berkeley_lm/lm.berkeleylm",
+ "resources/berkeley_lm/lm.berkeleylm.gz");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ decoder.cleanUp();
+ }
+
+ @Parameter
+ public String lmFile;
+
+ @Test
+ public void verifyLM() {
+ joshuaConfig = new JoshuaConfiguration();
+ joshuaConfig.processCommandLineOptions(OPTIONS);
+ joshuaConfig.features.add("feature_function = LanguageModel -lm_type berkeleylm -lm_order 2 -lm_file " + lmFile);
+ decoder = new Decoder(joshuaConfig, null);
+ String translation = decode(INPUT).toString();
+ assertEquals(lmFile, "tm_glue_0=2.000 lm_0=-7.153\n", translation);
+ }
+
+ private Translation decode(String input) {
+ final Sentence sentence = new Sentence(input, 0, joshuaConfig);
+ return decoder.decode(sentence);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/decoder/kbest_extraction/KBestExtractionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/decoder/kbest_extraction/KBestExtractionTest.java b/src/test/java/org/apache/joshua/decoder/kbest_extraction/KBestExtractionTest.java
new file mode 100644
index 0000000..c2cb031
--- /dev/null
+++ b/src/test/java/org/apache/joshua/decoder/kbest_extraction/KBestExtractionTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.kbest_extraction;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.joshua.corpus.Vocabulary;
+import org.apache.joshua.decoder.Decoder;
+import org.apache.joshua.decoder.JoshuaConfiguration;
+import org.apache.joshua.decoder.Translation;
+import org.apache.joshua.decoder.segment_file.Sentence;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.google.common.base.Charsets.UTF_8;
+import static java.nio.file.Files.readAllBytes;
+import static org.apache.joshua.decoder.ff.FeatureVector.DENSE_FEATURE_NAMES;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Reimplements the kbest extraction regression test
+ * TODO (fhieber): this test strangely only works with StateMinimizing KenLM.
+ * This is to be investigated
+ */
+public class KBestExtractionTest {
+
+ private static final String CONFIG = "resources/kbest_extraction/joshua.config";
+ private static final String INPUT = "a b c d e";
+ private static final Path GOLD_PATH = Paths.get("resources/kbest_extraction/output.scores.gold");
+
+ private JoshuaConfiguration joshuaConfig = null;
+ private Decoder decoder = null;
+
+ @Before
+ public void setUp() throws Exception {
+ joshuaConfig = new JoshuaConfiguration();
+ joshuaConfig.readConfigFile(CONFIG);
+ joshuaConfig.outputFormat = "%i ||| %s ||| %c";
+ decoder = new Decoder(joshuaConfig, "");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ decoder.cleanUp();
+ decoder = null;
+ }
+
+ @Test
+ public void givenInput_whenKbestExtraction_thenOutputIsAsExpected() throws IOException {
+ final String translation = decode(INPUT).toString();
+ final String gold = new String(readAllBytes(GOLD_PATH), UTF_8);
+ assertEquals(gold, translation);
+ }
+
+ private Translation decode(String input) {
+ final Sentence sentence = new Sentence(input, 0, joshuaConfig);
+ return decoder.decode(sentence);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/decoder/phrase/CoverageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/decoder/phrase/CoverageTest.java b/src/test/java/org/apache/joshua/decoder/phrase/CoverageTest.java
new file mode 100644
index 0000000..7526b1f
--- /dev/null
+++ b/src/test/java/org/apache/joshua/decoder/phrase/CoverageTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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.phrase;
+
+import static org.junit.Assert.*;
+
+import java.util.BitSet;
+
+import org.junit.Test;
+
+public class CoverageTest {
+
+ @Test
+ public void testSet() {
+ Coverage cov = new Coverage();
+ cov.set(1,2);
+ cov.set(3,4);
+ cov.set(2,3);
+ cov.set(0,1);
+
+ assertFalse(cov.compatible(0, 1));
+ assertFalse(cov.compatible(0, 5));
+ assertTrue(cov.compatible(4, 6));
+
+ assertEquals(cov.toString(), "4 ..........");
+ }
+
+ @Test
+ public void testPattern() {
+ Coverage cov = new Coverage();
+ cov.set(5,6);
+ cov.set(0,4);
+ BitSet bits = cov.pattern(4, 5);
+ BitSet answerBits = new BitSet();
+ answerBits.set(0);
+ assertEquals(bits, answerBits);
+ }
+
+ @Test
+ public void testCopyConstructor() {
+ Coverage a = new Coverage();
+ a.set(2,3);
+ Coverage b = new Coverage(a);
+ b.set(4,5);
+
+ assertFalse(a.toString().equals(b.toString()));
+ }
+
+ @Test
+ public void testCompatible() {
+ Coverage a = new Coverage();
+ a.set(10, 14);
+
+ assertTrue(a.compatible(14, 16));
+ assertTrue(a.compatible(6, 10));
+ assertTrue(a.compatible(1, 10));
+ assertTrue(a.compatible(1, 9));
+ assertFalse(a.compatible(9, 11));
+ assertFalse(a.compatible(13, 15));
+ assertFalse(a.compatible(9, 15));
+ assertFalse(a.compatible(9, 14));
+ assertFalse(a.compatible(10, 15));
+
+ a.set(0,9);
+
+ for (int width = 1; width <= 3; width++) {
+ for (int i = 0; i < 20; i++) {
+ int j = i + width;
+ if ((i == 9 && j == 10) || i >= 14)
+ assertTrue(a.compatible(i,j));
+ else {
+// System.err.println(String.format("%d,%d -> %s %s", i, j, a.compatible(i,j), a));
+ assertFalse(a.compatible(i,j));
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testFirstZero() {
+ Coverage cov = new Coverage();
+ cov.set(2, 5);
+ assertEquals(cov.firstZero(), 0);
+ cov.set(8,10);
+ assertEquals(cov.firstZero(), 0);
+ cov.set(0, 2);
+ assertEquals(cov.firstZero(), 5);
+ cov.set(5, 7);
+ assertEquals(cov.firstZero(), 7);
+ cov.set(7,8);
+ assertEquals(cov.firstZero(), 10);
+ }
+
+ @Test
+ public void testOpenings() {
+ Coverage cov = new Coverage();
+ cov.set(0, 2);
+ cov.set(8, 10);
+
+ for (int i = 2; i < 7; i++) {
+ assertEquals(cov.leftOpening(i), 2);
+ assertEquals(cov.rightOpening(i, 17), 8);
+ assertEquals(cov.rightOpening(i, 7), 7);
+ }
+ }
+
+ @Test
+ public void testEquals() {
+ Coverage cov = new Coverage();
+ cov.set(9, 11);
+ Coverage cov2 = new Coverage();
+ cov2.set(9,10);
+ cov2.set(10,11);
+ assertEquals(cov, cov2);
+ }
+
+ @Test
+ public void testToString() {
+ Coverage cov = new Coverage();
+ cov.set(0, 40);
+ cov.set(44, 49);
+ assertEquals(cov.toString(), "40 ....xxxxx.");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/decoder/phrase/constrained/ConstrainedPhraseDecodingTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/decoder/phrase/constrained/ConstrainedPhraseDecodingTest.java b/src/test/java/org/apache/joshua/decoder/phrase/constrained/ConstrainedPhraseDecodingTest.java
new file mode 100644
index 0000000..4612b44
--- /dev/null
+++ b/src/test/java/org/apache/joshua/decoder/phrase/constrained/ConstrainedPhraseDecodingTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.phrase.constrained;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.joshua.corpus.Vocabulary;
+import org.apache.joshua.decoder.Decoder;
+import org.apache.joshua.decoder.JoshuaConfiguration;
+import org.apache.joshua.decoder.Translation;
+import org.apache.joshua.decoder.segment_file.Sentence;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.google.common.base.Charsets.UTF_8;
+import static java.nio.file.Files.readAllBytes;
+import static org.apache.joshua.decoder.ff.FeatureVector.DENSE_FEATURE_NAMES;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Reimplements the constrained phrase decoding test
+ */
+public class ConstrainedPhraseDecodingTest {
+
+ private static final String CONFIG = "resources/phrase_decoder/constrained.config";
+ private static final String INPUT = "una estrategia republicana para obstaculizar la reelecci�n de Obama ||| President Obama to hinder a strategy for Republican re @-@ election";
+ private static final Path GOLD_PATH = Paths.get("resources/phrase_decoder/constrained.output.gold");
+
+ private JoshuaConfiguration joshuaConfig = null;
+ private Decoder decoder = null;
+
+ @Before
+ public void setUp() throws Exception {
+ joshuaConfig = new JoshuaConfiguration();
+ joshuaConfig.readConfigFile(CONFIG);
+ decoder = new Decoder(joshuaConfig, "");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ decoder.cleanUp();
+ decoder = null;
+ }
+
+ @Test
+ public void givenInput_whenConstrainedPhraseDecoding_thenOutputIsAsExpected() throws IOException {
+ final String translation = decode(INPUT).toString();
+ final String gold = new String(readAllBytes(GOLD_PATH), UTF_8);
+ assertEquals(gold, translation);
+ }
+
+ private Translation decode(String input) {
+ final Sentence sentence = new Sentence(input, 0, joshuaConfig);
+ return decoder.decode(sentence);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/decoder/phrase/decode/PhraseDecodingTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/decoder/phrase/decode/PhraseDecodingTest.java b/src/test/java/org/apache/joshua/decoder/phrase/decode/PhraseDecodingTest.java
new file mode 100644
index 0000000..12891ee
--- /dev/null
+++ b/src/test/java/org/apache/joshua/decoder/phrase/decode/PhraseDecodingTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.phrase.decode;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.joshua.corpus.Vocabulary;
+import org.apache.joshua.decoder.Decoder;
+import org.apache.joshua.decoder.JoshuaConfiguration;
+import org.apache.joshua.decoder.Translation;
+import org.apache.joshua.decoder.segment_file.Sentence;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static com.google.common.base.Charsets.UTF_8;
+import static java.nio.file.Files.readAllBytes;
+import static org.apache.joshua.decoder.ff.FeatureVector.DENSE_FEATURE_NAMES;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Reimplements the constrained phrase decoding test
+ */
+public class PhraseDecodingTest {
+
+ private static final String CONFIG = "resources/phrase_decoder/config";
+ private static final String INPUT = "una estrategia republicana para obstaculizar la reelecci�n de Obama";
+ private static final Path GOLD_PATH = Paths.get("resources/phrase_decoder/output.gold");
+
+ private JoshuaConfiguration joshuaConfig = null;
+ private Decoder decoder = null;
+
+ @Before
+ public void setUp() throws Exception {
+ joshuaConfig = new JoshuaConfiguration();
+ joshuaConfig.readConfigFile(CONFIG);
+ decoder = new Decoder(joshuaConfig, "");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ decoder.cleanUp();
+ decoder = null;
+ }
+
+ @Test
+ public void givenInput_whenPhraseDecoding_thenOutputIsAsExpected() throws IOException {
+ final String translation = decode(INPUT).toString();
+ final String gold = new String(readAllBytes(GOLD_PATH), UTF_8);
+ assertEquals(gold, translation);
+ }
+
+ private Translation decode(String input) {
+ final Sentence sentence = new Sentence(input, 0, joshuaConfig);
+ return decoder.decode(sentence);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/system/AlignmentMapTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/system/AlignmentMapTest.java b/src/test/java/org/apache/joshua/system/AlignmentMapTest.java
new file mode 100644
index 0000000..eba732a
--- /dev/null
+++ b/src/test/java/org/apache/joshua/system/AlignmentMapTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.system;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.joshua.corpus.Vocabulary;
+import org.apache.joshua.decoder.ff.tm.Rule;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class AlignmentMapTest {
+
+ private Rule rule1 = null;
+ private Rule rule2 = null;
+ private static Map<Integer, List<Integer>> expectedAlignmentMap = null;
+ private static final int[] expectedNonTerminalPositions = {2,5};
+
+ @Before
+ public void setUp() throws Exception {
+ Vocabulary.clear();
+ int[] sourceRhs = {Vocabulary.id("A1"),Vocabulary.id("A2"),-1,Vocabulary.id("B"),Vocabulary.id("C"),-2};
+ int[] targetRhs = {Vocabulary.id("c"),Vocabulary.id("b1"),-1,Vocabulary.id("b2"),-4,Vocabulary.id("a")};
+ int arity = 2; // 2 non terminals
+ String alignment = "0-5 1-5 3-1 3-3 4-0";
+ expectedAlignmentMap = new HashMap<Integer, List<Integer>>();
+ expectedAlignmentMap.put(0, Arrays.asList(4));
+ expectedAlignmentMap.put(5, Arrays.asList(0,1));
+ expectedAlignmentMap.put(1, Arrays.asList(3));
+ expectedAlignmentMap.put(3, Arrays.asList(3));
+ rule1 = new Rule(-1, sourceRhs, targetRhs, "", arity, alignment);
+ rule2 = new Rule(-1, sourceRhs, targetRhs, "", arity, null); // rule with no alignment
+ }
+
+ @Test
+ public void test() {
+ // test regular rule with arity 2
+ Map<Integer, List<Integer>> alignmentMap1 = rule1.getAlignmentMap();
+ assertEquals(expectedAlignmentMap, alignmentMap1);
+ int[] nonTerminalPositions1 = rule1.getNonTerminalSourcePositions();
+ assertArrayEquals(expectedNonTerminalPositions, nonTerminalPositions1);
+
+ // test rule with no alignment
+ Map<Integer, List<Integer>> alignmentMap2 = rule2.getAlignmentMap();
+ assertTrue(alignmentMap2.isEmpty());
+ int[] nonTerminalPositions2 = rule2.getNonTerminalSourcePositions();
+ assertArrayEquals(expectedNonTerminalPositions, nonTerminalPositions2);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/system/KenLmTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/system/KenLmTest.java b/src/test/java/org/apache/joshua/system/KenLmTest.java
new file mode 100644
index 0000000..6c05a58
--- /dev/null
+++ b/src/test/java/org/apache/joshua/system/KenLmTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.system;
+
+import static org.apache.joshua.corpus.Vocabulary.registerLanguageModel;
+import static org.apache.joshua.corpus.Vocabulary.unregisterLanguageModels;
+import static org.junit.Assert.*;
+import org.apache.joshua.corpus.Vocabulary;
+import org.apache.joshua.decoder.Decoder;
+import org.apache.joshua.decoder.JoshuaConfiguration;
+import org.apache.joshua.decoder.ff.lm.KenLM;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * KenLM JNI interface tests.
+ * Loads libken.{so,dylib}.
+ * If run in Eclipse, add -Djava.library.path=build/lib to JVM arguments
+ * of the run configuration.
+ */
+public class KenLmTest {
+
+ private static final String LANGUAGE_MODEL_PATH = "resources/kenlm/oilers.kenlm";
+
+ @Test
+ public void givenKenLm_whenQueryingForNgramProbability_thenProbIsCorrect() {
+ // GIVEN
+ KenLM kenLm = new KenLM(3, LANGUAGE_MODEL_PATH);
+ int[] words = Vocabulary.addAll("Wayne Gretzky");
+ registerLanguageModel(kenLm);
+
+ // WHEN
+ float probability = kenLm.prob(words);
+
+ // THEN
+ assertEquals("Found the wrong probability for 2-gram \"Wayne Gretzky\"", -0.99f, probability,
+ Float.MIN_VALUE);
+ }
+
+ @Test
+ public void givenKenLm_whenQueryingForNgramProbability_thenIdAndStringMethodsReturnTheSame() {
+ // GIVEN
+ KenLM kenLm = new KenLM(LANGUAGE_MODEL_PATH);
+ registerLanguageModel(kenLm);
+ String sentence = "Wayne Gretzky";
+ String[] words = sentence.split("\\s+");
+ int[] ids = Vocabulary.addAll(sentence);
+
+ // WHEN
+ float prob_string = kenLm.prob(words);
+ float prob_id = kenLm.prob(ids);
+
+ // THEN
+ assertEquals("ngram probabilities differ for word and id based n-gram query", prob_string, prob_id,
+ Float.MIN_VALUE);
+
+ }
+
+ @Test
+ public void givenKenLm_whenIsKnownWord_thenReturnValuesAreCorrect() {
+ KenLM kenLm = new KenLM(LANGUAGE_MODEL_PATH);
+ assertTrue(kenLm.isKnownWord("Wayne"));
+ assertFalse(kenLm.isKnownWord("Wayne2222"));
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ Vocabulary.clear();
+ unregisterLanguageModels();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ Vocabulary.clear();
+ unregisterLanguageModels();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/system/MultithreadedTranslationTests.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/system/MultithreadedTranslationTests.java b/src/test/java/org/apache/joshua/system/MultithreadedTranslationTests.java
new file mode 100644
index 0000000..4517314
--- /dev/null
+++ b/src/test/java/org/apache/joshua/system/MultithreadedTranslationTests.java
@@ -0,0 +1,140 @@
+/*
+ * 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.system;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+
+import org.apache.joshua.corpus.Vocabulary;
+import org.apache.joshua.decoder.Decoder;
+import org.apache.joshua.decoder.JoshuaConfiguration;
+import org.apache.joshua.decoder.Translation;
+import org.apache.joshua.decoder.Translations;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Integration test for multithreaded Joshua decoder tests. Grammar used is a
+ * toy packed grammar.
+ *
+ * @author kellens
+ */
+public class MultithreadedTranslationTests {
+
+ private JoshuaConfiguration joshuaConfig = null;
+ private Decoder decoder = null;
+ private static final String INPUT = "A K B1 U Z1 Z2 B2 C";
+ private int previousLogLevel;
+ private final static long NANO_SECONDS_PER_SECOND = 1_000_000_000;
+
+ @Before
+ public void setUp() throws Exception {
+ joshuaConfig = new JoshuaConfiguration();
+ joshuaConfig.search_algorithm = "cky";
+ joshuaConfig.mark_oovs = false;
+ joshuaConfig.pop_limit = 100;
+ joshuaConfig.use_unique_nbest = false;
+ joshuaConfig.include_align_index = false;
+ joshuaConfig.topN = 0;
+ joshuaConfig.tms.add("thrax -owner pt -maxspan 20 -path resources/wa_grammar.packed");
+ joshuaConfig.tms.add("thrax -owner glue -maxspan -1 -path resources/grammar.glue");
+ joshuaConfig.goal_symbol = "[GOAL]";
+ joshuaConfig.default_non_terminal = "[X]";
+ joshuaConfig.features.add("feature_function = OOVPenalty");
+ joshuaConfig.weights.add("tm_pt_0 1");
+ joshuaConfig.weights.add("tm_pt_1 1");
+ joshuaConfig.weights.add("tm_pt_2 1");
+ joshuaConfig.weights.add("tm_pt_3 1");
+ joshuaConfig.weights.add("tm_pt_4 1");
+ joshuaConfig.weights.add("tm_pt_5 1");
+ joshuaConfig.weights.add("tm_glue_0 1");
+ joshuaConfig.weights.add("OOVPenalty 2");
+ joshuaConfig.num_parallel_decoders = 500; // This will enable 500 parallel
+ // decoders to run at once.
+ // Useful to help flush out
+ // concurrency errors in
+ // underlying
+ // data-structures.
+ this.decoder = new Decoder(joshuaConfig, ""); // Second argument
+ // (configFile)
+ // is not even used by the
+ // constructor/initialize.
+
+ previousLogLevel = Decoder.VERBOSE;
+ Decoder.VERBOSE = 0;
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ this.decoder.cleanUp();
+ this.decoder = null;
+ Decoder.VERBOSE = previousLogLevel;
+ }
+
+
+
+ // This test was created specifically to reproduce a multithreaded issue
+ // related to mapped byte array access in the PackedGrammer getAlignmentArray
+ // function.
+
+ // We'll test the decoding engine using N = 10,000 identical inputs. This
+ // should be sufficient to induce concurrent data access for many shared
+ // data structures.
+
+ @Test
+ public void givenPackedGrammar_whenNTranslationsCalledConcurrently_thenReturnNResults() {
+ // GIVEN
+
+ int inputLines = 10000;
+ joshuaConfig.construct_structured_output = true; // Enabled alignments.
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < inputLines; i++) {
+ sb.append(INPUT + "\n");
+ }
+
+ // Append a large string together to simulate N requests to the decoding
+ // engine.
+ TranslationRequest req = new TranslationRequest(new ByteArrayInputStream(sb.toString()
+ .getBytes(Charset.forName("UTF-8"))), joshuaConfig);
+
+ // WHEN
+ // Translate all spans in parallel.
+ Translations translations = this.decoder.decodeAll(req);
+ ArrayList<Translation> translationResults = new ArrayList<Translation>();
+
+
+ final long translationStartTime = System.nanoTime();
+ Translation t;
+ while ((t = translations.next()) != null) {
+ translationResults.add(t);
+ }
+
+ final long translationEndTime = System.nanoTime();
+ final double pipelineLoadDurationInSeconds = (translationEndTime - translationStartTime) / ((double)NANO_SECONDS_PER_SECOND);
+ System.err.println(String.format("%.2f seconds", pipelineLoadDurationInSeconds));
+
+ // THEN
+ assertTrue(translationResults.size() == inputLines);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/system/StructuredOutputTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/system/StructuredOutputTest.java b/src/test/java/org/apache/joshua/system/StructuredOutputTest.java
new file mode 100644
index 0000000..27749c6
--- /dev/null
+++ b/src/test/java/org/apache/joshua/system/StructuredOutputTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.system;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.joshua.decoder.Decoder;
+import org.apache.joshua.decoder.JoshuaConfiguration;
+import org.apache.joshua.decoder.Translation;
+import org.apache.joshua.decoder.segment_file.Sentence;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.Assert;
+
+/**
+ * Integration test for the complete Joshua decoder using a toy grammar that translates
+ * a bunch of capital letters to lowercase letters. Rules in the test grammar
+ * drop and generate additional words and simulate reordering of rules, so that
+ * proper extraction of word alignments can be tested.
+ *
+ * @author fhieber
+ */
+public class StructuredOutputTest {
+
+ private JoshuaConfiguration joshuaConfig = null;
+ private Decoder decoder = null;
+ private Translation translation = null;
+ private static final String input = "A K B1 U Z1 Z2 B2 C";
+ private static final String expectedTranslation = "a b n1 u z c1 k1 k2 k3 n1 n2 n3 c2";
+ private static final String expectedWordAlignmentString = "0-0 2-1 6-1 3-3 4-4 5-4 7-5 1-6 1-7 1-8 7-12";
+ private static final List<List<Integer>> expectedWordAlignment = Arrays.asList(
+ Arrays.asList(0), Arrays.asList(2, 6), Arrays.asList(), Arrays.asList(3),
+ Arrays.asList(4, 5), Arrays.asList(7), Arrays.asList(1),
+ Arrays.asList(1), Arrays.asList(1), Arrays.asList(), Arrays.asList(),
+ Arrays.asList(), Arrays.asList(7));
+ private static final double expectedScore = -17.0;
+
+ @Before
+ public void setUp() throws Exception {
+ joshuaConfig = new JoshuaConfiguration();
+ joshuaConfig.search_algorithm = "cky";
+ joshuaConfig.mark_oovs = false;
+ joshuaConfig.pop_limit = 100;
+ joshuaConfig.use_unique_nbest = false;
+ joshuaConfig.include_align_index = false;
+ joshuaConfig.topN = 0;
+ joshuaConfig.tms.add("thrax pt 20 resources/wa_grammar");
+ joshuaConfig.tms.add("thrax glue -1 resources/grammar.glue");
+ joshuaConfig.goal_symbol = "[GOAL]";
+ joshuaConfig.default_non_terminal = "[X]";
+ joshuaConfig.features.add("feature_function = OOVPenalty");
+ joshuaConfig.weights.add("tm_pt_0 1");
+ joshuaConfig.weights.add("tm_pt_1 1");
+ joshuaConfig.weights.add("tm_pt_2 1");
+ joshuaConfig.weights.add("tm_pt_3 1");
+ joshuaConfig.weights.add("tm_pt_4 1");
+ joshuaConfig.weights.add("tm_pt_5 1");
+ joshuaConfig.weights.add("tm_glue_0 1");
+ joshuaConfig.weights.add("OOVPenalty 2");
+ decoder = new Decoder(joshuaConfig, ""); // second argument (configFile
+ // is not even used by the
+ // constructor/initialize)
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ decoder.cleanUp();
+ decoder = null;
+ translation = null;
+ }
+
+ private Translation decode(String input) {
+ Sentence sentence = new Sentence(input, 0, joshuaConfig);
+ return decoder.decode(sentence);
+ }
+
+ @Test
+ public void test() {
+
+ // test standard output
+ joshuaConfig.use_structured_output = false;
+ joshuaConfig.outputFormat = "%s | %a ";
+ translation = decode(input);
+ Assert.assertEquals(expectedTranslation + " | "
+ + expectedWordAlignmentString, translation.toString().trim());
+
+ // test structured output
+ joshuaConfig.use_structured_output = true; // set structured output creation to true
+ translation = decode(input);
+ Assert
+ .assertEquals(expectedTranslation, translation.getTranslationString());
+ Assert.assertEquals(Arrays.asList(expectedTranslation.split("\\s+")),
+ translation.getTranslationTokens());
+ Assert.assertEquals(expectedScore, translation.getTranslationScore(),
+ 0.00001);
+ Assert.assertEquals(expectedWordAlignment, translation.getWordAlignment());
+ Assert.assertEquals(translation.getWordAlignment().size(), translation
+ .getTranslationTokens().size());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/system/StructuredTranslationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/system/StructuredTranslationTest.java b/src/test/java/org/apache/joshua/system/StructuredTranslationTest.java
new file mode 100644
index 0000000..fe33a75
--- /dev/null
+++ b/src/test/java/org/apache/joshua/system/StructuredTranslationTest.java
@@ -0,0 +1,217 @@
+/*
+ * 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.system;
+
+import static java.util.Arrays.asList;
+import static org.apache.joshua.decoder.ff.FeatureVector.DENSE_FEATURE_NAMES;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.joshua.corpus.Vocabulary;
+import org.apache.joshua.decoder.Decoder;
+import org.apache.joshua.decoder.JoshuaConfiguration;
+import org.apache.joshua.decoder.StructuredTranslation;
+import org.apache.joshua.decoder.Translation;
+import org.apache.joshua.decoder.ff.FeatureVector;
+import org.apache.joshua.decoder.segment_file.Sentence;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Integration test for the complete Joshua decoder using a toy grammar that translates
+ * a bunch of capital letters to lowercase letters. Rules in the test grammar
+ * drop and generate additional words and simulate reordering of rules, so that
+ * proper extraction of word alignments and other information from the decoder
+ * can be tested.
+ *
+ * @author fhieber
+ */
+public class StructuredTranslationTest {
+
+ private JoshuaConfiguration joshuaConfig = null;
+ private Decoder decoder = null;
+ private static final String INPUT = "A K B1 U Z1 Z2 B2 C";
+ private static final String EXPECTED_TRANSLATION = "a b n1 u z c1 k1 k2 k3 n1 n2 n3 c2";
+ private static final List<String> EXPECTED_TRANSLATED_TOKENS = asList(EXPECTED_TRANSLATION.split("\\s+"));
+ private static final String EXPECTED_WORD_ALIGNMENT_STRING = "0-0 2-1 6-1 3-3 4-4 5-4 7-5 1-6 1-7 1-8 7-12";
+ private static final List<List<Integer>> EXPECTED_WORD_ALIGNMENT = asList(
+ asList(0), asList(2, 6), asList(), asList(3),
+ asList(4, 5), asList(7), asList(1),
+ asList(1), asList(1), asList(), asList(),
+ asList(), asList(7));
+ private static final double EXPECTED_SCORE = -17.0;
+ private static final Map<String,Float> EXPECTED_FEATURES = new HashMap<>();
+ static {
+ EXPECTED_FEATURES.put("tm_glue_0", 1.0f);
+ EXPECTED_FEATURES.put("tm_pt_0", -3.0f);
+ EXPECTED_FEATURES.put("tm_pt_1", -3.0f);
+ EXPECTED_FEATURES.put("tm_pt_2", -3.0f);
+ EXPECTED_FEATURES.put("tm_pt_3", -3.0f);
+ EXPECTED_FEATURES.put("tm_pt_4", -3.0f);
+ EXPECTED_FEATURES.put("tm_pt_5", -3.0f);
+ EXPECTED_FEATURES.put("OOV", 7.0f);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ joshuaConfig = new JoshuaConfiguration();
+ joshuaConfig.search_algorithm = "cky";
+ joshuaConfig.mark_oovs = false;
+ joshuaConfig.pop_limit = 100;
+ joshuaConfig.use_unique_nbest = false;
+ joshuaConfig.include_align_index = false;
+ joshuaConfig.topN = 0;
+ joshuaConfig.tms.add("thrax -owner pt -maxspan 20 -path resources/wa_grammar");
+ joshuaConfig.tms.add("thrax -owner glue -maxspan -1 -path resources/grammar.glue");
+ joshuaConfig.goal_symbol = "[GOAL]";
+ joshuaConfig.default_non_terminal = "[X]";
+ joshuaConfig.features.add("feature_function = OOVPenalty");
+ joshuaConfig.weights.add("tm_pt_0 1");
+ joshuaConfig.weights.add("tm_pt_1 1");
+ joshuaConfig.weights.add("tm_pt_2 1");
+ joshuaConfig.weights.add("tm_pt_3 1");
+ joshuaConfig.weights.add("tm_pt_4 1");
+ joshuaConfig.weights.add("tm_pt_5 1");
+ joshuaConfig.weights.add("tm_glue_0 1");
+ joshuaConfig.weights.add("OOVPenalty 1");
+ decoder = new Decoder(joshuaConfig, ""); // second argument (configFile
+ // is not even used by the
+ // constructor/initialize)
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ decoder.cleanUp();
+ decoder = null;
+ }
+
+ private Translation decode(String input) {
+ Sentence sentence = new Sentence(input, 0, joshuaConfig);
+ return decoder.decode(sentence);
+ }
+
+ @Test
+ public void givenInput_whenRegularOutputFormat_thenExpectedOutput() {
+ // GIVEN
+ joshuaConfig.construct_structured_output = false;
+ joshuaConfig.outputFormat = "%s | %a ";
+
+ // WHEN
+ final String translation = decode(INPUT).toString().trim();
+
+ // THEN
+ assertEquals(EXPECTED_TRANSLATION + " | " + EXPECTED_WORD_ALIGNMENT_STRING, translation);
+ }
+
+ @Test
+ public void givenInput_whenRegularOutputFormatWithTopN1_thenExpectedOutput() {
+ // GIVEN
+ joshuaConfig.construct_structured_output = false;
+ joshuaConfig.outputFormat = "%s | %e | %a | %c";
+ joshuaConfig.topN = 1;
+
+ // WHEN
+ final String translation = decode(INPUT).toString().trim();
+
+ // THEN
+ assertEquals(EXPECTED_TRANSLATION + " | " + INPUT + " | " + EXPECTED_WORD_ALIGNMENT_STRING + String.format(" | %.3f", EXPECTED_SCORE),
+ translation);
+ }
+
+ @Test
+ public void givenInput_whenStructuredOutputFormat_thenExpectedOutput() {
+ // GIVEN
+ joshuaConfig.construct_structured_output = true;
+
+ // WHEN
+ final StructuredTranslation translation = decode(INPUT).getStructuredTranslation();
+ final String translationString = translation.getTranslationString();
+ final List<String> translatedTokens = translation.getTranslationTokens();
+ final float translationScore = translation.getTranslationScore();
+ final List<List<Integer>> wordAlignment = translation.getTranslationWordAlignments();
+ final Map<String,Float> translationFeatures = translation.getTranslationFeatures();
+
+ // THEN
+ assertEquals(EXPECTED_TRANSLATION, translationString);
+ assertEquals(EXPECTED_TRANSLATED_TOKENS, translatedTokens);
+ assertEquals(EXPECTED_SCORE, translationScore, 0.00001);
+ assertEquals(EXPECTED_WORD_ALIGNMENT, wordAlignment);
+ assertEquals(wordAlignment.size(), translatedTokens.size());
+ assertEquals(EXPECTED_FEATURES.entrySet(), translationFeatures.entrySet());
+ }
+
+ @Test
+ public void givenEmptyInput_whenStructuredOutputFormat_thenEmptyOutput() {
+ // GIVEN
+ joshuaConfig.construct_structured_output = true;
+
+ // WHEN
+ final StructuredTranslation translation = decode("").getStructuredTranslation();
+ final String translationString = translation.getTranslationString();
+ final List<String> translatedTokens = translation.getTranslationTokens();
+ final float translationScore = translation.getTranslationScore();
+ final List<List<Integer>> wordAlignment = translation.getTranslationWordAlignments();
+
+ // THEN
+ assertEquals("", translationString);
+ assertTrue(translatedTokens.isEmpty());
+ assertEquals(0, translationScore, 0.00001);
+ assertTrue(wordAlignment.isEmpty());
+ }
+
+ @Test
+ public void givenOOVInput_whenStructuredOutputFormat_thenOOVOutput() {
+ // GIVEN
+ joshuaConfig.construct_structured_output = true;
+ final String input = "gabarbl";
+
+ // WHEN
+ final StructuredTranslation translation = decode(input).getStructuredTranslation();
+ final String translationString = translation.getTranslationString();
+ final List<String> translatedTokens = translation.getTranslationTokens();
+ final float translationScore = translation.getTranslationScore();
+ final List<List<Integer>> wordAlignment = translation.getTranslationWordAlignments();
+
+ // THEN
+ assertEquals(input, translationString);
+ assertTrue(translatedTokens.contains(input));
+ assertEquals(-99.0, translationScore, 0.00001);
+ assertTrue(wordAlignment.contains(asList(0)));
+ }
+
+ @Test
+ public void givenEmptyInput_whenRegularOutputFormat_thenNewlineOutput() {
+ // GIVEN
+ joshuaConfig.construct_structured_output = false;
+
+ // WHEN
+ final Translation translation = decode("");
+ final String translationString = translation.toString();
+
+ // THEN
+ assertEquals("\n", translationString);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/src/test/java/org/apache/joshua/util/FormatUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/joshua/util/FormatUtilsTest.java b/src/test/java/org/apache/joshua/util/FormatUtilsTest.java
new file mode 100644
index 0000000..853cf69
--- /dev/null
+++ b/src/test/java/org/apache/joshua/util/FormatUtilsTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.util;
+
+import static org.apache.joshua.util.FormatUtils.cleanNonTerminal;
+import static org.apache.joshua.util.FormatUtils.escapeSpecialSymbols;
+import static org.apache.joshua.util.FormatUtils.isNonterminal;
+import static org.apache.joshua.util.FormatUtils.markup;
+import static org.apache.joshua.util.FormatUtils.stripNonTerminalIndex;
+import static org.apache.joshua.util.FormatUtils.unescapeSpecialSymbols;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class FormatUtilsTest {
+
+ @Test
+ public void givenTokens_whenIsNonTerminal_thenTokensCorrectlyClassified() {
+ assertTrue(isNonterminal("[X]"));
+ assertTrue(isNonterminal("[X,1]"));
+ assertFalse(isNonterminal("[]"));
+ assertFalse(isNonterminal("[X)"));
+ }
+
+ @Test
+ public void givenTokens_whenCleanNonTerminal_thenCorrectlyCleaned() {
+ assertEquals(cleanNonTerminal("[GOAL]"), "GOAL");
+ assertEquals(cleanNonTerminal("[X]"), "X");
+ assertEquals(cleanNonTerminal("[X,1]"), "X");
+ assertEquals(cleanNonTerminal("bla"), "bla");
+ assertEquals(cleanNonTerminal("[bla"), "[bla");
+ }
+
+ @Test
+ public void givenTokens_whenStripNonTerminalIndex_thenCorrectlyStripped() {
+ assertEquals(stripNonTerminalIndex("[X,1]"), "[X]");
+ assertEquals(stripNonTerminalIndex("[X,114]"), "[X]");
+ assertEquals(stripNonTerminalIndex("[X,]"), "[X]");
+ assertEquals(stripNonTerminalIndex("[X]"), "[X]");
+ assertEquals(stripNonTerminalIndex("[X"), "[[X]");
+ }
+
+ @Test
+ public void givenTokens_whenMarkup_thenCorrectMarkup() {
+ assertEquals(markup("X"), "[X]");
+ assertEquals(markup("X", 1), "[X,1]");
+ assertEquals(markup("X", 15), "[X,15]");
+ assertEquals(markup("[X]", 1), "[X,1]");
+ assertEquals(markup("[X,1]", 4), "[X,4]");
+ }
+
+ @Test
+ public void givenSpecialSymbols_whenEscapeSpecialSymbols_thenCorrectlyEscaped() {
+ assertEquals(escapeSpecialSymbols("[ ] | ["), "-lsb- -rsb- -pipe- -lsb-");
+ }
+
+ @Test
+ public void givenEscapedSpecialSymbols_whenUnEscapeSpecialSymbols_thenCorrectlyUnEscaped() {
+ assertEquals(unescapeSpecialSymbols("-lsb- -rsb- -pipe- -lsb-"), "[ ] | [");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/tst/joshua/corpus/VocabularyTest.java
----------------------------------------------------------------------
diff --git a/tst/joshua/corpus/VocabularyTest.java b/tst/joshua/corpus/VocabularyTest.java
deleted file mode 100644
index 724d9c7..0000000
--- a/tst/joshua/corpus/VocabularyTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-package joshua.corpus;
-
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-public class VocabularyTest {
- private static final String WORD1 = "word1";
- private static final String WORD2 = "word2";
- private static final String NON_TERMINAL = "[X]";
- private static final String GOAL = "[GOAL]";
-
- @Before
- public void init() {
- Vocabulary.clear();
- }
-
- @After
- public void deinit() {
- Vocabulary.clear();
- }
-
- @Test
- public void givenVocabulary_whenEmpty_thenOnlyContainsUnknownWord() {
- assertTrue(Vocabulary.hasId(Vocabulary.UNKNOWN_ID));
- assertFalse(Vocabulary.hasId(1));
- assertFalse(Vocabulary.hasId(-1));
- assertEquals(Vocabulary.UNKNOWN_WORD, Vocabulary.word(Vocabulary.UNKNOWN_ID));
- assertEquals(1, Vocabulary.size());
- }
-
- @Test
- public void givenVocabulary_whenNewWord_thenMappingIsAdded() {
- final int FIRST_WORD_ID = 1;
- assertFalse(Vocabulary.hasId(FIRST_WORD_ID));
- assertEquals(FIRST_WORD_ID, Vocabulary.id(WORD1));
- //should return same id after second call:
- assertEquals(FIRST_WORD_ID, Vocabulary.id(WORD1));
- assertTrue(Vocabulary.hasId(FIRST_WORD_ID));
- assertEquals(WORD1, Vocabulary.word(FIRST_WORD_ID));
- assertEquals(2, Vocabulary.size());
- }
-
- @Test
- public void givenVocabulary_whenCheckingStringInBracketsOrNegativeNumber_thenIsNonTerminal() {
- //non-terminals
- assertTrue(Vocabulary.nt(NON_TERMINAL));
- //terminals
- assertFalse(Vocabulary.nt(WORD1));
- assertFalse(Vocabulary.nt("[]"));
- assertFalse(Vocabulary.nt("["));
- assertFalse(Vocabulary.nt("]"));
- assertFalse(Vocabulary.nt(""));
-
- //negative numbers indicate non-terminals
- assertTrue(Vocabulary.nt(-1));
- assertTrue(Vocabulary.nt(-5));
-
- //positive numbers indicate terminals:
- assertFalse(Vocabulary.nt(0));
- assertFalse(Vocabulary.nt(5));
-
-
- }
-
- @Test
- public void givenVocabulary_whenNonTerminal_thenReturnsStrictlyPositiveNonTerminalIndices() {
- final int FIRST_NON_TERMINAL_INDEX = 1;
- assertTrue(Vocabulary.id(NON_TERMINAL) < 0);
- assertTrue(Vocabulary.hasId(FIRST_NON_TERMINAL_INDEX));
- assertTrue(Vocabulary.hasId(-FIRST_NON_TERMINAL_INDEX));
-
- assertTrue(Vocabulary.id("") > 0);
- assertTrue(Vocabulary.id(WORD1) > 0);
-
- final int SECOND_NON_TERMINAL_INDEX = 4;
- assertTrue(Vocabulary.id(GOAL) < 0);
- assertTrue(Vocabulary.hasId(SECOND_NON_TERMINAL_INDEX));
- assertTrue(Vocabulary.hasId(-SECOND_NON_TERMINAL_INDEX));
-
- assertTrue(Vocabulary.id(WORD2) > 0);
- }
-
- @Rule
- public TemporaryFolder folder = new TemporaryFolder();
-
- @Test
- public void givenVocabulary_whenWritenAndReading_thenVocabularyStaysTheSame() throws IOException {
- File vocabFile = folder.newFile();
-
- int id1 = Vocabulary.id(WORD1);
- int id2 = Vocabulary.id(NON_TERMINAL);
- int id3 = Vocabulary.id(WORD2);
-
- Vocabulary.write(vocabFile.getAbsolutePath());
-
- Vocabulary.clear();
-
- Vocabulary.read(vocabFile);
-
- assertEquals(4, Vocabulary.size()); //unknown word + 3 other words
- assertTrue(Vocabulary.hasId(id1));
- assertTrue(Vocabulary.hasId(id2));
- assertTrue(Vocabulary.hasId(id3));
- assertEquals(id1, Vocabulary.id(WORD1));
- assertEquals(id2, Vocabulary.id(NON_TERMINAL));
- assertEquals(id3, Vocabulary.id(WORD2));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/tst/joshua/decoder/ff/lm/LanguageModelFFTest.java
----------------------------------------------------------------------
diff --git a/tst/joshua/decoder/ff/lm/LanguageModelFFTest.java b/tst/joshua/decoder/ff/lm/LanguageModelFFTest.java
deleted file mode 100644
index 83f5397..0000000
--- a/tst/joshua/decoder/ff/lm/LanguageModelFFTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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 joshua.decoder.ff.lm;
-
-import static org.junit.Assert.*;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import joshua.corpus.Vocabulary;
-import joshua.decoder.Decoder;
-import joshua.decoder.JoshuaConfiguration;
-import joshua.decoder.ff.FeatureVector;
-import joshua.decoder.ff.state_maintenance.NgramDPState;
-
-public class LanguageModelFFTest {
-
- private static final float WEIGHT = 0.5f;
-
- private LanguageModelFF ff;
-
- @Before
- public void setUp() {
- Decoder.resetGlobalState();
-
- FeatureVector weights = new FeatureVector();
- weights.set("lm_0", WEIGHT);
- String[] args = {"-lm_type", "berkeleylm", "-lm_order", "2", "-lm_file", "./joshua/test/lm/berkeley/lm"};
-
- JoshuaConfiguration config = new JoshuaConfiguration();
- ff = new LanguageModelFF(weights, args, config);
- }
-
- @After
- public void tearDown() {
- Decoder.resetGlobalState();
- }
-
- @Test
- public void givenNonStartSymbol_whenEstimateFutureCost_thenMultipleWeightAndLogProbabilty() {
- int[] left = {3};
- NgramDPState currentState = new NgramDPState(left, new int[left.length]);
-
- float score = ff.languageModel.sentenceLogProbability(left, 2, 1);
- assertEquals(-99.0f, score, 0.0);
-
- float cost = ff.estimateFutureCost(null, currentState, null);
- assertEquals(score * WEIGHT, cost, 0.0);
- }
-
- @Test
- public void givenOnlyStartSymbol_whenEstimateFutureCost_thenZeroResult() {
- int startSymbolId = Vocabulary.id(Vocabulary.START_SYM);
- int[] left = {startSymbolId};
- NgramDPState currentState = new NgramDPState(left, new int[left.length]);
-
- float score = ff.languageModel.sentenceLogProbability(left, 2, 2);
- assertEquals(0.0f, score, 0.0);
-
- float cost = ff.estimateFutureCost(null, currentState, null);
- assertEquals(score * WEIGHT, cost, 0.0);
- }
-
- @Test
- public void givenStartAndOneMoreSymbol_whenEstimateFutureCost_thenMultipleWeightAndLogProbabilty() {
- int startSymbolId = Vocabulary.id(Vocabulary.START_SYM);
- assertNotEquals(startSymbolId, 3);
- int[] left = {startSymbolId, 3};
- NgramDPState currentState = new NgramDPState(left, new int[left.length]);
-
- float score = ff.languageModel.sentenceLogProbability(left, 2, 2);
- assertEquals(-100.752754f, score, 0.0f);
-
- float cost = ff.estimateFutureCost(null, currentState, null);
- assertEquals(score * WEIGHT, cost, 0.0f);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f401535f/tst/joshua/decoder/ff/lm/berkeley_lm/LMBerkeleySentenceProbablityTest.java
----------------------------------------------------------------------
diff --git a/tst/joshua/decoder/ff/lm/berkeley_lm/LMBerkeleySentenceProbablityTest.java b/tst/joshua/decoder/ff/lm/berkeley_lm/LMBerkeleySentenceProbablityTest.java
deleted file mode 100644
index 74a832e..0000000
--- a/tst/joshua/decoder/ff/lm/berkeley_lm/LMBerkeleySentenceProbablityTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package joshua.decoder.ff.lm.berkeley_lm;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-import edu.berkeley.nlp.lm.ArrayEncodedNgramLanguageModel;
-
-public class LMBerkeleySentenceProbablityTest {
-
- @Test
- public void verifySentenceLogProbability() {
- LMGrammarBerkeley grammar = new LMGrammarBerkeley(2, "resources/berkeley_lm/lm");
- grammar.registerWord("the", 2);
- grammar.registerWord("chat-rooms", 3);
- grammar.registerWord("<unk>", 0);
-
- ArrayEncodedNgramLanguageModel<String> lm = grammar.getLM();
- float expected =
- lm.getLogProb(new int[] {}, 0, 0)
- + lm.getLogProb(new int[] {0}, 0, 1)
- + lm.getLogProb(new int[] {0, 2}, 0, 2)
- + lm.getLogProb(new int[] {2, 3}, 0, 2)
- + lm.getLogProb(new int[] {3, 0}, 0, 2);
-
- float result = grammar.sentenceLogProbability(new int[] {0, 2, 3, 0}, 2, 0);
- assertEquals(expected, result, 0.0);
- }
-}