You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by ma...@apache.org on 2023/02/09 10:29:55 UTC
[opennlp-sandbox] branch master updated: Bulk migrates JUnit 4 to JUnit 5 (#82)
This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/opennlp-sandbox.git
The following commit(s) were added to refs/heads/master by this push:
new 6702535 Bulk migrates JUnit 4 to JUnit 5 (#82)
6702535 is described below
commit 670253520ee1fa453c064ae70588bca449b4d018
Author: Richard Zowalla <13...@users.noreply.github.com>
AuthorDate: Thu Feb 9 11:29:49 2023 +0100
Bulk migrates JUnit 4 to JUnit 5 (#82)
- applies bulk migration from JUnit 4 to JUnit 5
- applies formatting according to OpenNLP style
---
caseditor-corpus-server-plugin/pom.xml | 17 +-
caseditor-opennlp-plugin/pom.xml | 17 +-
corpus-server/corpus-server-connector/pom.xml | 17 +-
.../corpus_server/connector/CSCasWriterTest.java | 28 +-
.../connector/CSCollectionReaderTest.java | 34 +-
.../corpus_server/connector/TestCorpusServer.java | 27 --
corpus-server/corpus-server-core/pom.xml | 16 +-
corpus-server/corpus-server-impl/pom.xml | 17 +-
corpus-server/corpus-server-tools/pom.xml | 19 +-
corpus-server/pom.xml | 6 -
mahout-addon/pom.xml | 17 +-
modelbuilder-addon/pom.xml | 19 +-
nlp-utils/pom.xml | 17 +-
.../java/org/apache/opennlp/utils/TestUtils.java | 2 -
.../AnomalyDetectionUtilsTest.java | 20 +-
.../apache/opennlp/utils/cfg/CFGBuilderTest.java | 43 +-
.../apache/opennlp/utils/cfg/CFGRunnerTest.java | 18 +-
.../opennlp/utils/cfg/ContextFreeGrammarTest.java | 31 +-
.../cfg/ProbabilisticContextFreeGrammarTest.java | 67 +--
.../org/apache/opennlp/utils/cfg/RuleTest.java | 17 +-
.../SimpleNaiveBayesClassifierTest.java | 69 +--
.../NaiveSentenceLanguageModelTest.java | 19 +-
.../TrigramSentenceLanguageModelTest.java | 21 +-
.../apache/opennlp/utils/ngram/NGramUtilsTest.java | 51 +-
.../utils/regression/GradientDescentUtilsTest.java | 6 +-
.../utils/regression/RegressionModelUtilsTest.java | 18 +-
opennlp-dl/pom.xml | 15 +-
.../java/opennlp/tools/dl/NeuralDocCatTest.java | 14 +-
.../src/test/java/opennlp/tools/dl/RNNTest.java | 45 +-
.../test/java/opennlp/tools/dl/StackedRNNTest.java | 45 +-
opennlp-similarity/pom.xml | 18 +-
.../MultiSentenceSearchResultsProcessorTest.java | 58 +--
.../apps/RelatedSentenceFinderTest.java | 67 +--
.../apps/StoryDiscourseNavigatorTest.java | 25 +-
.../pattern_structure/JSMLearnerOnLatticeTest.java | 531 +++++++++++----------
.../apps/SearchResultsProcessorTest.java | 10 +-
.../SpeechRecognitionResultsProcessorTest.java | 22 +-
.../apps/taxo_builder/TaxonomyBuildMatchTest.java | 22 +-
.../GeneralizationListReducerTest.java | 40 +-
.../tools/textsimilarity/LemmaFormManagerTest.java | 18 +-
.../ParseTreeChunkListScorerTest.java | 8 +-
.../tools/textsimilarity/ParseTreeChunkTest.java | 78 +--
.../tools/textsimilarity/SyntMatcherTest.java | 30 +-
.../ParserChunker2MatcherProcessorTest.java | 40 +-
.../chunker2matcher/PhraseNodeTest.java | 16 +-
opennlp-wsd/pom.xml | 17 +-
.../tools/disambiguator/AbstractEvaluatorTest.java | 6 +-
.../tools/disambiguator/LeskEvaluatorTest.java | 12 +-
.../opennlp/tools/disambiguator/LeskTester.java | 48 +-
.../tools/disambiguator/MFSEvaluatorTest.java | 14 +-
.../opennlp/tools/disambiguator/MFSTester.java | 46 +-
.../tools/disambiguator/WSDEvaluatorTest.java | 32 +-
.../opennlp/tools/disambiguator/WSDTester.java | 62 +--
pom.xml | 4 +-
summarizer/pom.xml | 17 +-
.../lexicalchaining/LexChainTest.java | 36 +-
.../LexChainingKeywordExtractorTest.java | 96 ++--
.../summarization/preprocess/DocProcessorTest.java | 16 +-
tagging-server/pom.xml | 17 +-
tf-ner-poc/pom.xml | 17 +-
.../opennlp/namefinder/FeedDictionaryTest.java | 26 +-
.../org/apache/opennlp/namefinder/PredictTest.java | 18 +-
.../apache/opennlp/namefinder/WordIndexerTest.java | 26 +-
wikinews-importer/pom.xml | 19 +-
64 files changed, 1210 insertions(+), 1054 deletions(-)
diff --git a/caseditor-corpus-server-plugin/pom.xml b/caseditor-corpus-server-plugin/pom.xml
index 5e7c3cc..0c7760b 100644
--- a/caseditor-corpus-server-plugin/pom.xml
+++ b/caseditor-corpus-server-plugin/pom.xml
@@ -51,9 +51,20 @@
<dependencies>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
diff --git a/caseditor-opennlp-plugin/pom.xml b/caseditor-opennlp-plugin/pom.xml
index bdcfb9e..c3e5b30 100644
--- a/caseditor-opennlp-plugin/pom.xml
+++ b/caseditor-opennlp-plugin/pom.xml
@@ -132,9 +132,20 @@
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/corpus-server/corpus-server-connector/pom.xml b/corpus-server/corpus-server-connector/pom.xml
index 3dec8ed..76fe1f0 100644
--- a/corpus-server/corpus-server-connector/pom.xml
+++ b/corpus-server/corpus-server-connector/pom.xml
@@ -65,8 +65,21 @@
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
diff --git a/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/CSCasWriterTest.java b/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/CSCasWriterTest.java
index 7bbe3dd..8dbc243 100644
--- a/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/CSCasWriterTest.java
+++ b/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/CSCasWriterTest.java
@@ -29,20 +29,21 @@ import org.apache.uima.collection.CasConsumer;
import org.apache.uima.resource.ResourceSpecifier;
import org.apache.uima.resource.metadata.TypeSystemDescription;
import org.apache.uima.util.XMLInputSource;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
-public class CSCasWriterTest extends AbstractCSTest {
+@Disabled
+class CSCasWriterTest extends AbstractCSTest {
private static final String CCPATH = "/CSCasConsumerTestDescriptor.xml";
private static final String BASE_PATH = CSCasWriterTest.class.getProtectionDomain().getCodeSource().getLocation().toExternalForm();
- @BeforeClass
- public static void setUp() throws IOException {
+ @BeforeAll
+ static void setUp() throws IOException {
// kick out the old db instances that might be present already in this environment
cleanTestDB();
@@ -53,21 +54,20 @@ public class CSCasWriterTest extends AbstractCSTest {
tsd.toXML(os);
CorporaStore corporaStore = new DerbyCorporaStore();
corporaStore.initialize(BASE_PATH.replace("file:", "").replace("/test-classes", ""));
- byte[] indexMapping = new byte[]{};
+ byte[] indexMapping = new byte[] {};
corporaStore.createCorpus("wikinews", os.toByteArray(), indexMapping);
} catch (Exception e) {
e.printStackTrace();
fail(e.getLocalizedMessage());
}
- new TestCorpusServer();
}
@Test
- @Ignore
- // TODO Investigate why this test fails with:
- // A CasConsumer descriptor specified implementation class "org.apache.opennlp.corpus_server.connector.CSCasWriter",
- // but this class does not implement the CasConsumer interface.
- public void testCasWrite() {
+ @Disabled
+ // TODO Investigate why this test fails with:
+ // A CasConsumer descriptor specified implementation class "org.apache.opennlp.corpus_server.connector.CSCasWriter",
+ // but this class does not implement the CasConsumer interface.
+ void testCasWrite() {
try (InputStream in = CSCasWriterTest.class.getResourceAsStream("/TypeSystem.xml")) {
XMLInputSource s = new XMLInputSource(CSCasWriterTest.class.getResource(CCPATH));
ResourceSpecifier rs = UIMAFramework.getXMLParser().parseCasConsumerDescription(s);
diff --git a/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/CSCollectionReaderTest.java b/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/CSCollectionReaderTest.java
index 2d58c50..e0d1caf 100644
--- a/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/CSCollectionReaderTest.java
+++ b/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/CSCollectionReaderTest.java
@@ -32,27 +32,28 @@ import org.apache.uima.resource.ResourceSpecifier;
import org.apache.uima.resource.metadata.TypeSystemDescription;
import org.apache.uima.util.CasCreationUtils;
import org.apache.uima.util.XMLInputSource;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
-public class CSCollectionReaderTest extends AbstractCSTest {
+@Disabled
+class CSCollectionReaderTest extends AbstractCSTest {
private static final String CRDPATH = "/CSCollectionReaderTestDescriptor.xml";
- @BeforeClass
- public static void setUp() throws IOException {
+ @BeforeAll
+ static void setUp() throws IOException {
// kick out the old db instances that might be present already in this environment
cleanTestDB();
@@ -64,7 +65,7 @@ public class CSCollectionReaderTest extends AbstractCSTest {
CorporaStore corporaStore = new DerbyCorporaStore();
corporaStore.initialize(BASE_PATH.replace("file:", "").replace("/test-classes", ""));
- byte[] indexMapping = new byte[]{};
+ byte[] indexMapping = new byte[] {};
corporaStore.createCorpus("wikinews", os.toByteArray(), indexMapping);
os.reset();
@@ -82,14 +83,13 @@ public class CSCollectionReaderTest extends AbstractCSTest {
e.printStackTrace();
fail(e.getLocalizedMessage());
}
- new TestCorpusServer();
}
@Test
- @Ignore
- // TODO Investigate why this test fails with:
- // No value has been assigned to the mandatory configuration parameter corpusName.
- public void explicitCRTest() {
+ @Disabled
+ // TODO Investigate why this test fails with:
+ // No value has been assigned to the mandatory configuration parameter corpusName.
+ void explicitCRTest() {
try {
XMLInputSource s = new XMLInputSource(CSCollectionReaderTest.class.getResource(CRDPATH));
ResourceSpecifier rs = UIMAFramework.getXMLParser().parseCollectionReaderDescription(s);
diff --git a/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/TestCorpusServer.java b/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/TestCorpusServer.java
deleted file mode 100644
index 05485fd..0000000
--- a/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/TestCorpusServer.java
+++ /dev/null
@@ -1,27 +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.opennlp.corpus_server.connector;
-
-/**
- * Utility CorpusServer extension class that can be used for test purposes.
- */
-public class TestCorpusServer {
- public TestCorpusServer() {
-// super.contextInitialized(null);
- }
-}
diff --git a/corpus-server/corpus-server-core/pom.xml b/corpus-server/corpus-server-core/pom.xml
index d54f879..a83351e 100644
--- a/corpus-server/corpus-server-core/pom.xml
+++ b/corpus-server/corpus-server-core/pom.xml
@@ -46,8 +46,20 @@
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/corpus-server/corpus-server-impl/pom.xml b/corpus-server/corpus-server-impl/pom.xml
index 316c56e..3daabff 100644
--- a/corpus-server/corpus-server-impl/pom.xml
+++ b/corpus-server/corpus-server-impl/pom.xml
@@ -78,8 +78,21 @@
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <scope>test</scope>
</dependency>
</dependencies>
diff --git a/corpus-server/corpus-server-tools/pom.xml b/corpus-server/corpus-server-tools/pom.xml
index 843d3eb..91a3002 100644
--- a/corpus-server/corpus-server-tools/pom.xml
+++ b/corpus-server/corpus-server-tools/pom.xml
@@ -57,10 +57,23 @@
<version>${uimaj.version}</version>
<scope>compile</scope>
</dependency>
-
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <scope>test</scope>
</dependency>
</dependencies>
diff --git a/corpus-server/pom.xml b/corpus-server/pom.xml
index fc909e1..a06826a 100644
--- a/corpus-server/pom.xml
+++ b/corpus-server/pom.xml
@@ -88,12 +88,6 @@
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</dependencyManagement>
diff --git a/mahout-addon/pom.xml b/mahout-addon/pom.xml
index f55b9ae..7a8b43e 100644
--- a/mahout-addon/pom.xml
+++ b/mahout-addon/pom.xml
@@ -46,9 +46,20 @@
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/modelbuilder-addon/pom.xml b/modelbuilder-addon/pom.xml
index 76faab1..91d250d 100644
--- a/modelbuilder-addon/pom.xml
+++ b/modelbuilder-addon/pom.xml
@@ -40,11 +40,22 @@
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-tools</artifactId>
</dependency>
-
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/nlp-utils/pom.xml b/nlp-utils/pom.xml
index 216fad9..bb66b8c 100644
--- a/nlp-utils/pom.xml
+++ b/nlp-utils/pom.xml
@@ -32,9 +32,20 @@
<dependencies>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/TestUtils.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/TestUtils.java
index 32d318f..4b6bbdb 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/TestUtils.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/TestUtils.java
@@ -21,12 +21,10 @@ package org.apache.opennlp.utils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;
-import org.junit.Ignore;
/**
* Utility class for tests
*/
-@Ignore
public class TestUtils {
private static final Random R = new Random();
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/anomalydetection/AnomalyDetectionUtilsTest.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/anomalydetection/AnomalyDetectionUtilsTest.java
index d5f2560..51b7901 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/anomalydetection/AnomalyDetectionUtilsTest.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/anomalydetection/AnomalyDetectionUtilsTest.java
@@ -21,35 +21,35 @@ package org.apache.opennlp.utils.anomalydetection;
import org.apache.opennlp.utils.TestUtils;
import org.apache.opennlp.utils.TrainingExample;
import org.apache.opennlp.utils.TrainingSet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Testcase for {@link org.apache.opennlp.utils.anomalydetection.AnomalyDetectionUtils}
*/
-public class AnomalyDetectionUtilsTest {
+class AnomalyDetectionUtilsTest {
@Test
- public void testGaussianDistributionProbabilityFromFitParameters() {
+ void testGaussianDistributionProbabilityFromFitParameters() {
TrainingSet trainingSet = new TrainingSet();
TestUtils.fillTrainingSet(trainingSet, 100, 5);
double[] mus = AnomalyDetectionUtils.fitMus(trainingSet);
assertNotNull(mus);
double[] sigmas = AnomalyDetectionUtils.fitSigmas(mus, trainingSet);
assertNotNull(sigmas);
- TrainingExample newInput = new TrainingExample(new double[]{0.4d,0.5d,0.5d,0.5d,0.2d}, 0d);
+ TrainingExample newInput = new TrainingExample(new double[] {0.4d, 0.5d, 0.5d, 0.5d, 0.2d}, 0d);
double probability = AnomalyDetectionUtils.getGaussianProbability(newInput, mus, sigmas);
- assertEquals(0.5d, probability, 0.5d);
+ assertEquals(probability, 0.5d, 0.5d);
}
@Test
- public void testGaussianDistributionProbabilityFromTrainingSet() {
+ void testGaussianDistributionProbabilityFromTrainingSet() {
TrainingSet trainingSet = new TrainingSet();
TestUtils.fillTrainingSet(trainingSet, 100, 5);
- TrainingExample newInput = new TrainingExample(new double[]{0.4d,0.5d,0.5d,0.5d,0.2d}, 0d);
+ TrainingExample newInput = new TrainingExample(new double[] {0.4d, 0.5d, 0.5d, 0.5d, 0.2d}, 0d);
double probability = AnomalyDetectionUtils.getGaussianProbability(newInput, trainingSet);
- assertEquals(0.5d, probability, 0.5d);
+ assertEquals(probability, 0.5d, 0.5d);
}
}
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/CFGBuilderTest.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/CFGBuilderTest.java
index 323ef6a..20e1d48 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/CFGBuilderTest.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/CFGBuilderTest.java
@@ -20,18 +20,19 @@ package org.apache.opennlp.utils.cfg;
import java.util.Arrays;
import java.util.Collections;
-import org.junit.Test;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Testcase for {@link org.apache.opennlp.utils.cfg.CFGBuilder}
*/
-public class CFGBuilderTest {
+class CFGBuilderTest {
@Test
- public void testVoidBuild() throws Exception {
+ void testVoidBuild() throws Exception {
CFGBuilder builder = CFGBuilder.createCFG();
assertNotNull(builder);
try {
@@ -43,12 +44,12 @@ public class CFGBuilderTest {
}
@Test
- public void testBuildWithEmptySets() throws Exception {
+ void testBuildWithEmptySets() throws Exception {
CFGBuilder builder = CFGBuilder.createCFG().
- withNonTerminals(Collections.<String>emptyList()).
- withTerminals(Collections.<String>emptyList()).
- withRules(Collections.<Rule>emptyList()).
- withStartSymbol("");
+ withNonTerminals(Collections.<String>emptyList()).
+ withTerminals(Collections.<String>emptyList()).
+ withRules(Collections.<Rule>emptyList()).
+ withStartSymbol("");
try {
assertNotNull(builder.build());
fail("cannot build a grammar whose start symbol doesn't belong to the non terminals symbols set");
@@ -58,23 +59,23 @@ public class CFGBuilderTest {
}
@Test
- public void testBuildWithMinimalGrammarSettings() throws Exception {
+ void testBuildWithMinimalGrammarSettings() throws Exception {
CFGBuilder builder = CFGBuilder.createCFG().
- withNonTerminals(Arrays.asList("")).
- withTerminals(Collections.<String>emptyList()).
- withRules(Collections.<Rule>emptyList()).
- withStartSymbol("");
+ withNonTerminals(Arrays.asList("")).
+ withTerminals(Collections.<String>emptyList()).
+ withRules(Collections.<Rule>emptyList()).
+ withStartSymbol("");
assertNotNull(builder.build());
}
@Test
- public void testBuildWithMinimalGrammarSettingsAndRandomExpansion() throws Exception {
+ void testBuildWithMinimalGrammarSettingsAndRandomExpansion() throws Exception {
CFGBuilder builder = CFGBuilder.createCFG().
- withNonTerminals(Arrays.asList("")).
- withTerminals(Collections.<String>emptyList()).
- withRules(Collections.<Rule>emptyList()).
- withRandomExpansion(true).
- withStartSymbol("");
+ withNonTerminals(Arrays.asList("")).
+ withTerminals(Collections.<String>emptyList()).
+ withRules(Collections.<Rule>emptyList()).
+ withRandomExpansion(true).
+ withStartSymbol("");
assertNotNull(builder.build());
}
}
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/CFGRunnerTest.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/CFGRunnerTest.java
index 2d98104..019eece 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/CFGRunnerTest.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/CFGRunnerTest.java
@@ -18,30 +18,30 @@
*/
package org.apache.opennlp.utils.cfg;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for {@link CFGRunner}
*/
-public class CFGRunnerTest {
+class CFGRunnerTest {
@Test
- public void testDefaultMain() throws Exception {
+ void testDefaultMain() throws Exception {
CFGRunner.main(new String[0]);
}
@Test
- public void testMainWithWD() throws Exception {
- CFGRunner.main(new String[]{"-wn"});
+ void testMainWithWD() throws Exception {
+ CFGRunner.main(new String[] {"-wn"});
}
@Test
- public void testMainWithPT() throws Exception {
- CFGRunner.main(new String[]{"-pt"});
+ void testMainWithPT() throws Exception {
+ CFGRunner.main(new String[] {"-pt"});
}
@Test
- public void testMainWithWNAndPT() throws Exception {
- CFGRunner.main(new String[]{"-wn", "-pt"});
+ void testMainWithWNAndPT() throws Exception {
+ CFGRunner.main(new String[] {"-wn", "-pt"});
}
}
\ No newline at end of file
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/ContextFreeGrammarTest.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/ContextFreeGrammarTest.java
index a16c6e9..afb8149 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/ContextFreeGrammarTest.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/ContextFreeGrammarTest.java
@@ -20,23 +20,24 @@ package org.apache.opennlp.utils.cfg;
import java.util.Collection;
import java.util.LinkedList;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Testcase for {@link org.apache.opennlp.utils.cfg.ContextFreeGrammar}
*/
-public class ContextFreeGrammarTest {
+class ContextFreeGrammarTest {
private static Collection<String> terminals;
private static Collection<String> nonTerminals; // PoS + Parse tags
private static String startSymbol;
private static Collection<Rule> rules;
- @BeforeClass
- public static void setUp() throws Exception {
+ @BeforeAll
+ static void setUp() throws Exception {
nonTerminals = new LinkedList<String>();
nonTerminals.add("S");
nonTerminals.add("NP");
@@ -108,15 +109,15 @@ public class ContextFreeGrammarTest {
}
@Test
- public void testSingleSentenceExpansion() throws Exception {
+ void testSingleSentenceExpansion() throws Exception {
ContextFreeGrammar contextFreeGrammar = new ContextFreeGrammar(nonTerminals, terminals, rules, startSymbol);
String[] expansion = contextFreeGrammar.leftMostDerivation("S");
- assertArrayEquals(new String[]{"the", "man", "works"}, expansion);
+ assertArrayEquals(new String[] {"the", "man", "works"}, expansion);
checkExpansion(expansion);
}
@Test
- public void testSingleSentenceRandomExpansion() throws Exception {
+ void testSingleSentenceRandomExpansion() throws Exception {
ContextFreeGrammar contextFreeGrammar = new ContextFreeGrammar(nonTerminals, terminals, rules, startSymbol, true);
String[] expansion = contextFreeGrammar.leftMostDerivation("S");
checkExpansion(expansion);
@@ -124,19 +125,19 @@ public class ContextFreeGrammarTest {
@Test
- public void testMultipleSentencesExpansion() throws Exception {
+ void testMultipleSentencesExpansion() throws Exception {
ContextFreeGrammar contextFreeGrammar = new ContextFreeGrammar(nonTerminals, terminals, rules, startSymbol);
String[] expansion = contextFreeGrammar.leftMostDerivation("S", "CJ", "S");
- assertArrayEquals(new String[]{"the", "man", "works", "and", "the", "man", "works"}, expansion);
+ assertArrayEquals(new String[] {"the", "man", "works", "and", "the", "man", "works"}, expansion);
checkExpansion(expansion);
expansion = contextFreeGrammar.leftMostDerivation("S", "DJ", "S", "CJ", "P");
- assertArrayEquals(new String[]{"the", "man", "works", "but", "the", "man", "works", "and", "the", "man", "works",
- "and", "the", "man", "works"}, expansion);
+ assertArrayEquals(new String[] {"the", "man", "works", "but", "the", "man", "works", "and", "the", "man", "works",
+ "and", "the", "man", "works"}, expansion);
checkExpansion(expansion);
}
@Test
- public void testMultipleSentencesRandomExpansion() throws Exception {
+ void testMultipleSentencesRandomExpansion() throws Exception {
ContextFreeGrammar contextFreeGrammar = new ContextFreeGrammar(nonTerminals, terminals, rules, startSymbol, true);
String[] expansion = contextFreeGrammar.leftMostDerivation("S", "CJ", "S");
checkExpansion(expansion);
@@ -148,7 +149,7 @@ public class ContextFreeGrammarTest {
assertNotNull(expansion);
assertTrue(expansion.length > 0);
for (String t : expansion) {
- assertTrue("term " + t + " is not a terminal symbol", terminals.contains(t));
+ assertTrue(terminals.contains(t), "term " + t + " is not a terminal symbol");
}
}
}
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/ProbabilisticContextFreeGrammarTest.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/ProbabilisticContextFreeGrammarTest.java
index f820612..55742f9 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/ProbabilisticContextFreeGrammarTest.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/ProbabilisticContextFreeGrammarTest.java
@@ -29,24 +29,25 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
/**
* Testcase for {@link org.apache.opennlp.utils.cfg.ProbabilisticContextFreeGrammar}
*/
-public class ProbabilisticContextFreeGrammarTest {
+class ProbabilisticContextFreeGrammarTest {
private static LinkedList<String> nonTerminals;
private static String startSymbol;
private static LinkedList<String> terminals;
private static Map<Rule, Double> rules;
- @BeforeClass
- public static void setUp() throws Exception {
+ @BeforeAll
+ static void setUp() throws Exception {
nonTerminals = new LinkedList<String>();
nonTerminals.add("S");
nonTerminals.add("NP");
@@ -110,7 +111,7 @@ public class ProbabilisticContextFreeGrammarTest {
}
@Test
- public void testIntermediateProbability() throws Exception {
+ void testIntermediateProbability() throws Exception {
ArrayList<String> sentence = new ArrayList<String>();
sentence.add("the");
sentence.add("dog");
@@ -124,14 +125,14 @@ public class ProbabilisticContextFreeGrammarTest {
ProbabilisticContextFreeGrammar pcfg = new ProbabilisticContextFreeGrammar(nonTerminals, terminals, rules, startSymbol);
double pi = pcfg.pi(sentence, 0, 1, pcfg.getStartSymbol()).getProbability();
- assertEquals(0.3d, pi, 0d);
+ assertEquals(0.3d, pi);
pi = pcfg.pi(sentence, 2, 4, "VP").getProbability();
- assertEquals(0.35d, pi, 0d);
+ assertEquals(0.35d, pi);
}
@Test
- public void testFullSentenceCKY() throws Exception {
+ void testFullSentenceCKY() throws Exception {
ProbabilisticContextFreeGrammar pcfg = new ProbabilisticContextFreeGrammar(nonTerminals, terminals, rules, startSymbol, true);
// fixed sentence one
@@ -190,7 +191,7 @@ public class ProbabilisticContextFreeGrammarTest {
}
@Test
- public void testParseString() throws Exception {
+ void testParseString() throws Exception {
String string = "(S (VP (Adv last) (Vb tidy)) (NP (Adj biogenic) (NN Gainesville)))";
Map<Rule, Double> rules = ProbabilisticContextFreeGrammar.parseRules(string);
assertNotNull(rules);
@@ -198,30 +199,30 @@ public class ProbabilisticContextFreeGrammarTest {
}
@Test
- public void testReadingItalianPennTreebankParseTreeSamples() throws Exception {
+ void testReadingItalianPennTreebankParseTreeSamples() throws Exception {
String newsSample = "( (S \n" +
- " (VP (VMA~RE Slitta) \n" +
- " (PP-LOC (PREP a) \n" +
- " (NP (NOU~PR Tirana))) \n" +
- " (NP-EXTPSBJ-433 \n" +
- " (NP (ART~DE la) (NOU~CS decisione)) \n" +
- " (PP (PREP sullo) \n" +
- " (NP \n" +
- " (NP (ART~DE sullo) (NOU~CS stato)) \n" +
- " (PP (PREP di) \n" +
- " (NP (NOU~CS emergenza))))))) \n" +
- " (NP-SBJ (-NONE- *-433)) \n" +
- " (. .)) ) ";
+ " (VP (VMA~RE Slitta) \n" +
+ " (PP-LOC (PREP a) \n" +
+ " (NP (NOU~PR Tirana))) \n" +
+ " (NP-EXTPSBJ-433 \n" +
+ " (NP (ART~DE la) (NOU~CS decisione)) \n" +
+ " (PP (PREP sullo) \n" +
+ " (NP \n" +
+ " (NP (ART~DE sullo) (NOU~CS stato)) \n" +
+ " (PP (PREP di) \n" +
+ " (NP (NOU~CS emergenza))))))) \n" +
+ " (NP-SBJ (-NONE- *-433)) \n" +
+ " (. .)) ) ";
Map<Rule, Double> rules = new HashMap<>();
ProbabilisticContextFreeGrammar.parseRules(rules, true, newsSample);
assertNotNull(rules);
String newsSample2 = "( (S \n" +
- " (NP-SBJ (ART~DE La) (NOU~CS mafia) (ADJ~QU italiana)) \n" +
- " (VP (VMA~RE opera) \n" +
- " (PP-LOC (PREP in) \n" +
- " (NP (NOU~PR Albania)))) \n" +
- " (. .)) ) ";
+ " (NP-SBJ (ART~DE La) (NOU~CS mafia) (ADJ~QU italiana)) \n" +
+ " (VP (VMA~RE opera) \n" +
+ " (PP-LOC (PREP in) \n" +
+ " (NP (NOU~PR Albania)))) \n" +
+ " (. .)) ) ";
Map<Rule, Double> rules2 = new HashMap<>();
ProbabilisticContextFreeGrammar.parseRules(rules2, true, newsSample2);
assertNotNull(rules2);
@@ -238,9 +239,9 @@ public class ProbabilisticContextFreeGrammarTest {
assertTrue(derivation.length > 1);
}
- @Ignore
+ @Disabled
@Test
- public void testReadingItalianPennTreebankParseTree() throws Exception {
+ void testReadingItalianPennTreebankParseTree() throws Exception {
InputStream resourceAsStream = getClass().getResourceAsStream("/it-tb-news.txt");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resourceAsStream));
Collection<String> sentences = parseSentences(bufferedReader);
@@ -267,7 +268,7 @@ public class ProbabilisticContextFreeGrammarTest {
while ((line = bufferedReader.readLine()) != null) {
if (line.contains("(") || line.contains(")")) {
sentence.append(line);
- } else if (line.contains("*****")){
+ } else if (line.contains("*****")) {
// only use single sentences
String s = sentence.toString();
if (s.trim().split("\\(S ").length == 2 && s.trim().startsWith("( (S")) {
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/RuleTest.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/RuleTest.java
index 9c43087..4856930 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/RuleTest.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/cfg/RuleTest.java
@@ -19,39 +19,40 @@
package org.apache.opennlp.utils.cfg;
import java.util.TreeSet;
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
/**
* Testcase for {@link Rule}
*/
-public class RuleTest {
+class RuleTest {
@Test
- public void testEquals() throws Exception {
+ void testEquals() throws Exception {
Rule r1 = new Rule("NP", "NP", "PP");
Rule r2 = new Rule("NP", "NP", "PP");
assertEquals(r1, r2);
}
@Test
- public void testNotEquals() throws Exception {
+ void testNotEquals() throws Exception {
Rule r1 = new Rule("NP", "DT", "NN");
Rule r2 = new Rule("NP", "NP", "PP");
assertNotEquals(r1, r2);
}
@Test
- public void testHashcode() throws Exception {
+ void testHashcode() throws Exception {
Rule r1 = new Rule("NP", "DT", "NN");
Rule r2 = new Rule("NP", "NP", "PP");
assertNotEquals(r1.hashCode(), r2.hashCode());
}
@Test
- public void testCompare() throws Exception {
+ void testCompare() throws Exception {
TreeSet<Rule> rules = new TreeSet<Rule>();
Rule r1 = new Rule("NP", "DT", "NN");
Rule r2 = new Rule("NP", "NP", "PP");
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/classification/SimpleNaiveBayesClassifierTest.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/classification/SimpleNaiveBayesClassifierTest.java
index 8d7f408..76d463a 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/classification/SimpleNaiveBayesClassifierTest.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/classification/SimpleNaiveBayesClassifierTest.java
@@ -20,65 +20,66 @@ package org.apache.opennlp.utils.classification;
import java.util.HashMap;
import java.util.Map;
-import org.junit.Test;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Testcase for {@link org.apache.opennlp.utils.classification.SimpleNaiveBayesClassifier}
*/
-public class SimpleNaiveBayesClassifierTest {
+class SimpleNaiveBayesClassifierTest {
@Test
- public void ppsIntegrationTest() {
+ void ppsIntegrationTest() {
Map<String, String> trainedCorpus = new HashMap<>();
trainedCorpus.put("CAVOUR ad.te napoleone III affare: cat. C/2 ottimo" +
- " stato ingresso angolo cottura bagno con doccia e camera. " +
- "ottimo per investimento o piccolo studio per professionisti" +
- " e 99.000 Ag.Imm.", "A");
+ " stato ingresso angolo cottura bagno con doccia e camera. " +
+ "ottimo per investimento o piccolo studio per professionisti" +
+ " e 99.000 Ag.Imm.", "A");
trainedCorpus.put("TRASTEVERE via degli Orti di Trastevere in palazzo " +
- "signorile (con s. portineria) appartamento mq 180 + cantina mq" +
- " 6 con rifiniture di pregio marmi & armadi a muro + ampia " +
- "balconata 50 mq assolutamente no agenzie E 930.000", "N");
+ "signorile (con s. portineria) appartamento mq 180 + cantina mq" +
+ " 6 con rifiniture di pregio marmi & armadi a muro + ampia " +
+ "balconata 50 mq assolutamente no agenzie E 930.000", "N");
trainedCorpus.put("CORSO VITTORIO Emanuele V. del banco di santo spirito" +
- " 3° piano con ascensore appartamento di 142 mq commerciali " +
- "composto da: ingresso disimpegno tre camere soggiorno cucina" +
- " due bagni due cantine per un totale di 15 mq e. 900.000 Ag.Imm.", "A");
+ " 3° piano con ascensore appartamento di 142 mq commerciali " +
+ "composto da: ingresso disimpegno tre camere soggiorno cucina" +
+ " due bagni due cantine per un totale di 15 mq e. 900.000 Ag.Imm.", "A");
trainedCorpus.put("TRASTEVERE Ippolito Nievo quinto piano tripla " +
- "esposizione ingresso salone doppio cucina abitabile tre " +
- "camere servizio ripostiglio terrazzo e soffitta da ristrutturare " +
- "e 650.000 Ag.Imm.", "A");
+ "esposizione ingresso salone doppio cucina abitabile tre " +
+ "camere servizio ripostiglio terrazzo e soffitta da ristrutturare " +
+ "e 650.000 Ag.Imm.", "A");
trainedCorpus.put("TRASTEVERE E.Rolli solo privati palazzo epoca doppia" +
- " esposizione ingresso soppalcato soggiorno 2 camere cucinotto " +
- "bagno 84 mq IV piano no ascensore 385.000 giardino condominio", "N");
+ " esposizione ingresso soppalcato soggiorno 2 camere cucinotto " +
+ "bagno 84 mq IV piano no ascensore 385.000 giardino condominio", "N");
trainedCorpus.put("CENTRO monti sforza elegante edificio con ampi spazi" +
- " comuni ristrutturato ingresso soggiorno angolo cucina camera " +
- "letto armadi a muro bagno vasca con finestra pavimenti cotto " +
- "luminoso silenzioso doppio affaccio climatizzato e 405.000 ag. " +
- "imm. cl en.g", "A");
+ " comuni ristrutturato ingresso soggiorno angolo cucina camera " +
+ "letto armadi a muro bagno vasca con finestra pavimenti cotto " +
+ "luminoso silenzioso doppio affaccio climatizzato e 405.000 ag. " +
+ "imm. cl en.g", "A");
trainedCorpus.put("SAN LORENZO app.to epoca privato vende salone due " +
- "camere cucina abit. due bagni ripostigli vari II piano con" +
- " ascensore triplo affaccio E 530.000 ", "N");
+ "camere cucina abit. due bagni ripostigli vari II piano con" +
+ " ascensore triplo affaccio E 530.000 ", "N");
trainedCorpus.put("SAN LORENZO Via Porta Labicana appartamento mq 80 " +
- "piano rialzato con ingresso 3 camere cucina bagno E 395.000 ", "N");
+ "piano rialzato con ingresso 3 camere cucina bagno E 395.000 ", "N");
trainedCorpus.put("SAN LORENZO via degli Umbri I° p. 3 stanze cucina " +
- "servizio terrazzino interno buono stato E. 390.000 tratt. " +
- "assoloutamente no agenzie ", "N");
+ "servizio terrazzino interno buono stato E. 390.000 tratt. " +
+ "assoloutamente no agenzie ", "N");
SimpleNaiveBayesClassifier classifier = new SimpleNaiveBayesClassifier(trainedCorpus);
boolean isAgency = classifier.calculateClass("CENTRO S.Maria Maggiore " +
- "angolo Napoleone III in palazzo epoca con portiere 110 mq ristrutt." +
- " IIp salone doppio cucina ab. 2 camere bagno ripost. balcone " +
- "perimetrale E. 730.000 tratt. ").equals("A");
+ "angolo Napoleone III in palazzo epoca con portiere 110 mq ristrutt." +
+ " IIp salone doppio cucina ab. 2 camere bagno ripost. balcone " +
+ "perimetrale E. 730.000 tratt. ").equals("A");
assertFalse(isAgency);
isAgency = classifier.calculateClass("TRASTEVERE via del Mattonato in " +
- "piccola palazzina d'epoca app.to finemente ristrutturato " +
- "ingresso salone camera cucina tinello servizio balconcino " +
- "aria condiz. e 540.000 Ag.Imm. ").equals("A");
+ "piccola palazzina d'epoca app.to finemente ristrutturato " +
+ "ingresso salone camera cucina tinello servizio balconcino " +
+ "aria condiz. e 540.000 Ag.Imm. ").equals("A");
assertTrue(isAgency);
}
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/languagemodel/NaiveSentenceLanguageModelTest.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/languagemodel/NaiveSentenceLanguageModelTest.java
index c4d0825..55d6554 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/languagemodel/NaiveSentenceLanguageModelTest.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/languagemodel/NaiveSentenceLanguageModelTest.java
@@ -19,31 +19,32 @@
package org.apache.opennlp.utils.languagemodel;
import java.util.Collections;
+
import org.apache.opennlp.utils.TestUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Testcase for {@link org.apache.opennlp.utils.languagemodel.NaiveSentenceLanguageModel}
*/
-public class NaiveSentenceLanguageModelTest {
+class NaiveSentenceLanguageModelTest {
@Test
public void testEmptyVocabularyProbability() {
NaiveSentenceLanguageModel<String> model = new NaiveSentenceLanguageModel<>();
- assertEquals("probability with an empty vocabulary is always 0",
- 0d, model.calculateProbability(Collections.emptySet(), new String[0]), 0d);
- assertEquals("probability with an empty vocabulary is always 0",
- 0d, model.calculateProbability(Collections.emptySet(), new String[]{"1", "2", "3"}), 0d);
+ assertEquals(0d, model.calculateProbability(Collections.emptySet(), new String[0]),
+ 0d, "probability with an empty vocabulary is always 0");
+ assertEquals(0d, model.calculateProbability(Collections.emptySet(),
+ new String[] {"1", "2", "3"}), 0d, "probability with an empty vocabulary is always 0");
}
@Test
public void testRandomVocabularyAndSentence() {
NaiveSentenceLanguageModel<String> model = new NaiveSentenceLanguageModel<>();
double probability = model.calculateProbability(TestUtils.generateRandomVocabulary(), TestUtils.generateRandomSentence());
- assertTrue("a probability measure should be between 0 and 1 [was " + probability + "]", probability >= 0 && probability <= 1);
+ assertTrue(probability >= 0 && probability <= 1, "a probability measure should be between 0 and 1 [was " + probability + "]");
}
}
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/languagemodel/TrigramSentenceLanguageModelTest.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/languagemodel/TrigramSentenceLanguageModelTest.java
index 32fb47c..46d63c3 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/languagemodel/TrigramSentenceLanguageModelTest.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/languagemodel/TrigramSentenceLanguageModelTest.java
@@ -19,12 +19,13 @@
package org.apache.opennlp.utils.languagemodel;
import java.util.Collections;
+
import org.apache.opennlp.utils.TestUtils;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Testcase for {@link org.apache.opennlp.utils.languagemodel.TrigramSentenceLanguageModel}
@@ -34,19 +35,19 @@ public class TrigramSentenceLanguageModelTest {
@Test
public void testEmptyVocabularyProbability() {
TrigramSentenceLanguageModel<String> model = new TrigramSentenceLanguageModel<>();
- assertEquals("probability with an empty vocabulary is always 0",
- 0d, model.calculateProbability(Collections.emptySet(), new String[0]), 0d);
- assertEquals("probability with an empty vocabulary is always 0",
- 0d, model.calculateProbability(Collections.emptySet(), new String[]{"1", "2", "3"}), 0d);
+ assertEquals(0d, model.calculateProbability(Collections.emptySet(), new String[0]), 0d,
+ "probability with an empty vocabulary is always 0");
+ assertEquals(0d, model.calculateProbability(Collections.emptySet(), new String[] {"1", "2", "3"}), 0d,
+ "probability with an empty vocabulary is always 0");
}
@Test
- @Ignore
+ @Disabled
public void testRandomVocabularyAndSentence() {
TrigramSentenceLanguageModel<String> model = new TrigramSentenceLanguageModel<>();
double probability = model.calculateProbability(TestUtils.generateRandomVocabulary(), TestUtils.generateRandomSentence());
// TODO Investigate why probability yields NaN sometimes and crashes the test in the next line
- assertTrue("a probability measure should be between 0 and 1 [was " + probability + "]", probability >= 0 && probability <= 1);
+ assertTrue(probability >= 0 && probability <= 1, "a probability measure should be between 0 and 1 [was " + probability + "]");
}
}
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/ngram/NGramUtilsTest.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/ngram/NGramUtilsTest.java
index a988e98..854965e 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/ngram/NGramUtilsTest.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/ngram/NGramUtilsTest.java
@@ -20,23 +20,24 @@ package org.apache.opennlp.utils.ngram;
import java.util.Collection;
import java.util.LinkedList;
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Testcase for {@link org.apache.opennlp.utils.ngram.NGramUtils}
*/
-public class NGramUtilsTest {
+class NGramUtilsTest {
@Test
- public void testBigram() {
+ void testBigram() {
Collection<String[]> set = new LinkedList<>();
- set.add(new String[]{"<s>", "I", "am", "Sam", "</s>"});
- set.add(new String[]{"<s>", "Sam", "I", "am", "</s>"});
- set.add(new String[]{"<s>", "I", "do", "not", "like", "green", "eggs", "and", "ham", "</s>"});
- set.add(new String[]{});
+ set.add(new String[] {"<s>", "I", "am", "Sam", "</s>"});
+ set.add(new String[] {"<s>", "Sam", "I", "am", "</s>"});
+ set.add(new String[] {"<s>", "I", "do", "not", "like", "green", "eggs", "and", "ham", "</s>"});
+ set.add(new String[] {});
Double d = NGramUtils.calculateBigramMLProbability("I", "<s>", set);
assertTrue(d > 0);
assertEquals(Double.valueOf(0.6666666666666666d), d);
@@ -47,12 +48,12 @@ public class NGramUtilsTest {
}
@Test
- public void testTrigram() {
+ void testTrigram() {
Collection<String[]> set = new LinkedList<>();
- set.add(new String[]{"<s>", "I", "am", "Sam", "</s>"});
- set.add(new String[]{"<s>", "Sam", "I", "am", "</s>"});
- set.add(new String[]{"<s>", "I", "do", "not", "like", "green", "eggs", "and", "ham", "</s>"});
- set.add(new String[]{});
+ set.add(new String[] {"<s>", "I", "am", "Sam", "</s>"});
+ set.add(new String[] {"<s>", "Sam", "I", "am", "</s>"});
+ set.add(new String[] {"<s>", "I", "do", "not", "like", "green", "eggs", "and", "ham", "</s>"});
+ set.add(new String[] {});
Double d = NGramUtils.calculateTrigramMLProbability("I", "am", "Sam", set);
assertEquals(Double.valueOf(0.5), d);
d = NGramUtils.calculateTrigramMLProbability("Sam", "I", "am", set);
@@ -60,29 +61,29 @@ public class NGramUtilsTest {
}
@Test
- public void testLinearInterpolation() {
+ void testLinearInterpolation() {
Collection<String[]> set = new LinkedList<>();
- set.add(new String[]{"the", "green", "book", "STOP"});
- set.add(new String[]{"my", "blue", "book", "STOP"});
- set.add(new String[]{"his", "green", "house", "STOP"});
- set.add(new String[]{"book", "STOP"});
+ set.add(new String[] {"the", "green", "book", "STOP"});
+ set.add(new String[] {"my", "blue", "book", "STOP"});
+ set.add(new String[] {"his", "green", "house", "STOP"});
+ set.add(new String[] {"book", "STOP"});
Double lambda = 1d / 3d;
Double d = NGramUtils.calculateLinearInterpolationProbability("the", "green", "book", set, lambda, lambda, lambda);
assertNotNull(d);
assertTrue(d > 0);
- assertEquals("wrong result", Double.valueOf(0.5714285714285714d), d);
+ assertEquals(Double.valueOf(0.5714285714285714d), d, "wrong result");
}
@Test
- public void testLinearInterpolation2() {
+ void testLinearInterpolation2() {
Collection<String[]> set = new LinkedList<>();
- set.add(new String[]{"D", "N", "V", "STOP"});
- set.add(new String[]{"D", "N", "V", "STOP"});
+ set.add(new String[] {"D", "N", "V", "STOP"});
+ set.add(new String[] {"D", "N", "V", "STOP"});
Double lambda = 1d / 3d;
Double d = NGramUtils.calculateLinearInterpolationProbability("N", "V", "STOP", set, lambda, lambda, lambda);
assertNotNull(d);
assertTrue(d > 0);
- assertEquals("wrong result", Double.valueOf(0.75d), d);
+ assertEquals(Double.valueOf(0.75d), d, "wrong result");
}
}
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/regression/GradientDescentUtilsTest.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/regression/GradientDescentUtilsTest.java
index 4486120..258985f 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/regression/GradientDescentUtilsTest.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/regression/GradientDescentUtilsTest.java
@@ -20,15 +20,15 @@ package org.apache.opennlp.utils.regression;
import org.apache.opennlp.utils.TestUtils;
import org.apache.opennlp.utils.TrainingSet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Testcase for {@link org.apache.opennlp.utils.regression.GradientDescentUtils}
*/
-public class GradientDescentUtilsTest {
+class GradientDescentUtilsTest {
@Test
- public void testConvergence() {
+ void testConvergence() {
TrainingSet trainingSet = new TrainingSet();
TestUtils.fillTrainingSet(trainingSet, 100, 5);
GradientDescentUtils.batchGradientDescent(trainingSet, 0.00002);
diff --git a/nlp-utils/src/test/java/org/apache/opennlp/utils/regression/RegressionModelUtilsTest.java b/nlp-utils/src/test/java/org/apache/opennlp/utils/regression/RegressionModelUtilsTest.java
index 8676989..045dfb8 100644
--- a/nlp-utils/src/test/java/org/apache/opennlp/utils/regression/RegressionModelUtilsTest.java
+++ b/nlp-utils/src/test/java/org/apache/opennlp/utils/regression/RegressionModelUtilsTest.java
@@ -20,26 +20,26 @@ package org.apache.opennlp.utils.regression;
import org.apache.opennlp.utils.TrainingExample;
import org.apache.opennlp.utils.TrainingSet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Testcase for {@link org.apache.opennlp.utils.regression.RegressionModelUtils}
*/
-public class RegressionModelUtilsTest {
+class RegressionModelUtilsTest {
@Test
- public void testLMS() {
+ void testLMS() {
TrainingSet trainingSet = new TrainingSet();
- trainingSet.add(new TrainingExample(new double[]{10, 10}, 1));
+ trainingSet.add(new TrainingExample(new double[] {10, 10}, 1));
LinearCombinationHypothesis hypothesis = new LinearCombinationHypothesis(1, 1);
double[] updatedParameters = RegressionModelUtils.batchLeastMeanSquareUpdate(
- new double[]{1, 1}, 0.1, trainingSet, hypothesis);
+ new double[] {1, 1}, 0.1, trainingSet, hypothesis);
assertNotNull(updatedParameters);
assertEquals(2, updatedParameters.length);
- assertEquals(-18d, updatedParameters[0], 0.0);
- assertEquals(-18d, updatedParameters[1], 0.0);
+ assertEquals(-18d, updatedParameters[0]);
+ assertEquals(-18d, updatedParameters[1]);
}
}
diff --git a/opennlp-dl/pom.xml b/opennlp-dl/pom.xml
index 58df820..7a8c802 100644
--- a/opennlp-dl/pom.xml
+++ b/opennlp-dl/pom.xml
@@ -103,9 +103,18 @@
<version>2.33</version>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/opennlp-dl/src/test/java/opennlp/tools/dl/NeuralDocCatTest.java b/opennlp-dl/src/test/java/opennlp/tools/dl/NeuralDocCatTest.java
index 9d0cb83..a592ed1 100644
--- a/opennlp-dl/src/test/java/opennlp/tools/dl/NeuralDocCatTest.java
+++ b/opennlp-dl/src/test/java/opennlp/tools/dl/NeuralDocCatTest.java
@@ -21,20 +21,20 @@ package opennlp.tools.dl;
import java.util.Arrays;
import java.util.Map;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests for {@link NeuralDocCat}
*/
-@Ignore
-public class NeuralDocCatTest {
+@Disabled
+class NeuralDocCatTest {
@Test
- public void testDocCatTrainingOnTweets() throws Exception {
+ void testDocCatTrainingOnTweets() throws Exception {
NeuralDocCatTrainer.Args args = new NeuralDocCatTrainer.Args();
args.glovesPath = "/path/to/glove.6B/glove.6B.50d.txt";
args.labels = Arrays.asList("0", "1");
diff --git a/opennlp-dl/src/test/java/opennlp/tools/dl/RNNTest.java b/opennlp-dl/src/test/java/opennlp/tools/dl/RNNTest.java
index 342fa20..ef6eb5a 100644
--- a/opennlp-dl/src/test/java/opennlp/tools/dl/RNNTest.java
+++ b/opennlp-dl/src/test/java/opennlp/tools/dl/RNNTest.java
@@ -21,40 +21,27 @@ package opennlp.tools.dl;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import java.util.Random;
+import java.util.stream.Stream;
import org.apache.commons.io.IOUtils;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
/**
* CV tests for {@link RNN}
*/
-@RunWith(Parameterized.class)
public class RNNTest {
- private float learningRate;
- private int seqLength;
- private int hiddenLayerSize;
- private int epochs;
-
- private Random r = new Random();
+ private Random r = new Random(42);
private String text;
private List<String> words;
- public RNNTest(float learningRate, int seqLength, int hiddenLayerSize, int epochs) {
- this.learningRate = learningRate;
- this.seqLength = seqLength;
- this.hiddenLayerSize = hiddenLayerSize;
- this.epochs = epochs;
- }
-
- @Before
+ @BeforeEach
public void setUp() throws Exception {
try (InputStream stream = getClass().getResourceAsStream("/text/sentences.txt")) {
text = IOUtils.toString(stream, StandardCharsets.UTF_8);
@@ -62,20 +49,20 @@ public class RNNTest {
}
}
- @Parameterized.Parameters
- public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][] {
- {1e-3f, 25, 50, 5},
- });
+ private static Stream<Arguments> provideRNNParams() {
+ return Stream.of(
+ Arguments.of(1e-3f, 25, 50, 5)
+ );
}
- @Test
- @Ignore
+ @Disabled
// TODO check why this fails with:
// java.lang.IllegalStateException: Can't transpose array with rank < 2: array shape [62]
// ...
// on MacOS (only?)
- public void testVanillaCharRNNLearn() throws Exception {
+ @ParameterizedTest
+ @MethodSource("provideRNNParams")
+ public void testVanillaCharRNNLearn(float learningRate, int seqLength, int hiddenLayerSize, int epochs) throws Exception {
RNN rnn = new RNN(learningRate, seqLength, hiddenLayerSize, epochs, text, 10, true);
evaluate(rnn, true);
rnn.serialize("target/crnn-weights-");
diff --git a/opennlp-dl/src/test/java/opennlp/tools/dl/StackedRNNTest.java b/opennlp-dl/src/test/java/opennlp/tools/dl/StackedRNNTest.java
index e5968e1..f8ae25f 100644
--- a/opennlp-dl/src/test/java/opennlp/tools/dl/StackedRNNTest.java
+++ b/opennlp-dl/src/test/java/opennlp/tools/dl/StackedRNNTest.java
@@ -21,40 +21,27 @@ package opennlp.tools.dl;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import java.util.Random;
+import java.util.stream.Stream;
import org.apache.commons.io.IOUtils;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
/**
* Tests for {@link StackedRNN}
*/
-@RunWith(Parameterized.class)
public class StackedRNNTest {
- private final float learningRate;
- private final int seqLength;
- private final int hiddenLayerSize;
- private final int epochs;
-
- private final Random r = new Random();
+ private final Random r = new Random(42);
private String text;
private List<String> words;
- public StackedRNNTest(float learningRate, int seqLength, int hiddenLayerSize, int epochs) {
- this.learningRate = learningRate;
- this.seqLength = seqLength;
- this.hiddenLayerSize = hiddenLayerSize;
- this.epochs = epochs;
- }
-
- @Before
+ @BeforeEach
public void setUp() throws Exception {
try (InputStream stream = getClass().getResourceAsStream("/text/sentences.txt")) {
text = IOUtils.toString(stream, StandardCharsets.UTF_8);
@@ -62,20 +49,20 @@ public class StackedRNNTest {
}
}
- @Parameterized.Parameters
- public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][] {
- {1e-3f, 25, 50, 4},
- });
+ private static Stream<Arguments> provideRNNParams() {
+ return Stream.of(
+ Arguments.of(1e-3f, 25, 50, 5)
+ );
}
- @Test
- @Ignore
+ @Disabled
// TODO check why this fails with:
// java.lang.IllegalStateException: Can't transpose array with rank < 2: array shape [62]
// ...
// on MacOS (only?)
- public void testStackedCharRNNLearn() throws Exception {
+ @ParameterizedTest
+ @MethodSource("provideRNNParams")
+ public void testVanillaCharRNNLearn(float learningRate, int seqLength, int hiddenLayerSize, int epochs) throws Exception {
RNN rnn = new StackedRNN(learningRate, seqLength, hiddenLayerSize, epochs, text, 10, true, true);
evaluate(rnn, true);
rnn.serialize("target/scrnn-weights-");
diff --git a/opennlp-similarity/pom.xml b/opennlp-similarity/pom.xml
index cb39cd6..7bc3105 100644
--- a/opennlp-similarity/pom.xml
+++ b/opennlp-similarity/pom.xml
@@ -97,11 +97,23 @@
<version>1.7.33</version>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/apps/MultiSentenceSearchResultsProcessorTest.java b/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/apps/MultiSentenceSearchResultsProcessorTest.java
index 7aeb477..a4c5409 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/apps/MultiSentenceSearchResultsProcessorTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/apps/MultiSentenceSearchResultsProcessorTest.java
@@ -20,21 +20,21 @@ import java.util.List;
import opennlp.tools.similarity.apps.HitBase;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
- public class MultiSentenceSearchResultsProcessorTest {
+class MultiSentenceSearchResultsProcessorTest {
- private final MultiSentenceSearchResultsProcessor proc = new MultiSentenceSearchResultsProcessor();
+ private final MultiSentenceSearchResultsProcessor proc = new MultiSentenceSearchResultsProcessor();
- @Test
- @Ignore
- // TODO OPENNLP-1455 This test case fails with: "UnknownHostException: api.datamarket.azure.com: nodename nor servname provided, or not known"
- public void testSearchOrder() {
- List<HitBase> res; HitBase first = null;
- String query ;
+ @Test
+ @Disabled // TODO OPENNLP-1455 This test case fails with: "UnknownHostException: api.datamarket.azure.com: nodename nor servname provided, or not known"
+ void testSearchOrder() {
+ List<HitBase> res;
+ HitBase first = null;
+ String query;
/*
query = "I am now living abroad and have health insurance from Russia. How can I avoid penalty for not having health insurance in US";
res = proc.runSearchViaAPI(query);
@@ -43,26 +43,26 @@ import static org.junit.Assert.assertTrue;
first = res.get(0);
assertTrue(first.getGenerWithQueryScore() > 2.0f);
*/
-
-
- query = "Furious about reports that the IRS was used to target conservative groups, President Obama said that acting IRS Director Steve T. Miller was asked to resign. "+
- "IRS actions were inexcusable. Americans are right to be angry about it. Obama will not tolerate this type of behavior by IRS";
- res = proc.runSearchViaAPI(query);
- // we verify that top answers have high similarity score
- System.out.println(res);
- first = res.get(0);
- assertTrue(first.getGenerWithQueryScore() > 000f);
- query = " I see no meaningful distinction between complacency or complicity in the military's latest failure to uphold their own " +
- "standards of conduct. Nor do I see a distinction between the service member who orchestrated this offense and the chain of " +
- "command that was either oblivious to or tolerant of criminal behavior";
- res = proc.runSearchViaAPI(query);
- first = res.get(0);
- assertTrue(first.getGenerWithQueryScore() > 1.69);
- // assertTrue(second.getTitle().indexOf("living abroad")>-1);
- proc.close();
- }
+ query = "Furious about reports that the IRS was used to target conservative groups, President Obama said that acting IRS Director Steve T. Miller was asked to resign. " +
+ "IRS actions were inexcusable. Americans are right to be angry about it. Obama will not tolerate this type of behavior by IRS";
+ res = proc.runSearchViaAPI(query);
+ // we verify that top answers have high similarity score
+ System.out.println(res);
+ first = res.get(0);
+ assertTrue(first.getGenerWithQueryScore() > 000f);
+
+ query = " I see no meaningful distinction between complacency or complicity in the military's latest failure to uphold their own " +
+ "standards of conduct. Nor do I see a distinction between the service member who orchestrated this offense and the chain of " +
+ "command that was either oblivious to or tolerant of criminal behavior";
+ res = proc.runSearchViaAPI(query);
+ first = res.get(0);
+ assertTrue(first.getGenerWithQueryScore() > 1.69);
+ // assertTrue(second.getTitle().indexOf("living abroad")>-1);
+ proc.close();
+
+ }
/*public void testSimpleQuery(){
List<HitBase> res = proc.runSearchViaAPI("How can I pay tax on my income abroad");
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/apps/RelatedSentenceFinderTest.java b/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/apps/RelatedSentenceFinderTest.java
index 7f8d149..16fb7aa 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/apps/RelatedSentenceFinderTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/apps/RelatedSentenceFinderTest.java
@@ -21,28 +21,29 @@ import java.util.ArrayList;
import opennlp.tools.similarity.apps.ContentGenerator;
import opennlp.tools.similarity.apps.HitBase;
-import org.junit.Test;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.api.Test;
-public class RelatedSentenceFinderTest {
-
- private final ContentGenerator finder = new ContentGenerator();
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
- @Test
- public void testAugmentWithMinedSentencesAndVerifyRelevanceTest(){
- HitBase input = new HitBase();
- input.setAbstractText("He is pictured here in the Swiss Patent Office where he did ...");
- input.setUrl("https://apod.nasa.gov/apod/ap951219.html");
- input.setTitle("Albert Einstein");
- HitBase result = finder.buildParagraphOfGeneratedText(input, "Swiss Patent Office", new ArrayList<>());
- assertNotNull(result.getOriginalSentences());
- assertTrue(result.getOriginalSentences().size()>0);
- // TODO Investigate why the below to checks fail
- // assertTrue(result.getFragments().size()>0);
- // assertTrue(result.getFragments().get(0).getFragment().contains("Swiss Patent Office"));
- }
+class RelatedSentenceFinderTest {
+
+ private final ContentGenerator finder = new ContentGenerator();
+
+ @Test
+ void testAugmentWithMinedSentencesAndVerifyRelevanceTest() {
+ HitBase input = new HitBase();
+ input.setAbstractText("He is pictured here in the Swiss Patent Office where he did ...");
+ input.setUrl("https://apod.nasa.gov/apod/ap951219.html");
+ input.setTitle("Albert Einstein");
+ HitBase result = finder.buildParagraphOfGeneratedText(input, "Swiss Patent Office", new ArrayList<>());
+ assertNotNull(result.getOriginalSentences());
+ assertTrue(result.getOriginalSentences().size() > 0);
+ // TODO Investigate why the below to checks fail
+ // assertTrue(result.getFragments().size()>0);
+ // assertTrue(result.getFragments().get(0).getFragment().contains("Swiss Patent Office"));
+ }
/*
public void testBuildParagraphOfGeneratedTextTest(){
@@ -60,19 +61,19 @@ public class RelatedSentenceFinderTest {
}
*/
- @Test
- public void testBuildParagraphOfGeneratedTextTestYearInTheEnd(){
-
- HitBase input = new HitBase();
- input.setAbstractText("Albert Einstein was born ... Germany, on March 14, 1879");
- input.setUrl("https://www.nobelprize.org/prizes/physics/1921/einstein/biographical");
- input.setTitle("Albert Einstein - Biographical");
- HitBase result = finder.buildParagraphOfGeneratedText(input, "Albert Einstein", new ArrayList<>());
- assertNotNull(result.getOriginalSentences());
- assertTrue(result.getOriginalSentences().size()>0);
- assertTrue(result.getFragments().size()>0);
- assertTrue(result.getFragments().get(0).getFragment().contains("Albert Einstein"));
- }
+ @Test
+ void testBuildParagraphOfGeneratedTextTestYearInTheEnd() {
+
+ HitBase input = new HitBase();
+ input.setAbstractText("Albert Einstein was born ... Germany, on March 14, 1879");
+ input.setUrl("https://www.nobelprize.org/prizes/physics/1921/einstein/biographical");
+ input.setTitle("Albert Einstein - Biographical");
+ HitBase result = finder.buildParagraphOfGeneratedText(input, "Albert Einstein", new ArrayList<>());
+ assertNotNull(result.getOriginalSentences());
+ assertTrue(result.getOriginalSentences().size() > 0);
+ assertTrue(result.getFragments().size() > 0);
+ assertTrue(result.getFragments().get(0).getFragment().contains("Albert Einstein"));
+ }
/*
public void testBuildParagraphOfGeneratedTextTestBio1(){
@@ -131,7 +132,7 @@ public class RelatedSentenceFinderTest {
assertTrue(result.getFragments().size()>0);
assertTrue(result.getFragments().get(0).getFragment().indexOf("view of the world")>-1);
} */
-
+
}
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/apps/StoryDiscourseNavigatorTest.java b/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/apps/StoryDiscourseNavigatorTest.java
index 79aba13..8cd6407 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/apps/StoryDiscourseNavigatorTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/apps/StoryDiscourseNavigatorTest.java
@@ -18,22 +18,21 @@ package opennlp.tools.parse_thicket.apps;
import java.util.Arrays;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import opennlp.tools.similarity.apps.StoryDiscourseNavigator;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class StoryDiscourseNavigatorTest {
+class StoryDiscourseNavigatorTest {
- @Test
- @Ignore
- // TODO OPENNLP-1455 This test fails with "UnknownHostException: api.datamarket.azure.com: nodename nor servname provided, or not known"
- public void testGeneratedExtensionKeywords(){
- String[] res = new StoryDiscourseNavigator().obtainAdditionalKeywordsForAnEntity("Albert Einstein");
- assertTrue(res.length>0);
- assertTrue(Arrays.asList(res).toString().contains("physics"));
- assertTrue(Arrays.asList(res).toString().contains("relativity"));
- }
+ @Test
+ @Disabled // TODO OPENNLP-1455 This test fails with "UnknownHostException: api.datamarket.azure.com: nodename nor servname provided, or not known"
+ void testGeneratedExtensionKeywords() {
+ String[] res = new StoryDiscourseNavigator().obtainAdditionalKeywordsForAnEntity("Albert Einstein");
+ assertTrue(res.length > 0);
+ assertTrue(Arrays.asList(res).toString().contains("physics"));
+ assertTrue(Arrays.asList(res).toString().contains("relativity"));
+ }
}
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/pattern_structure/JSMLearnerOnLatticeTest.java b/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/pattern_structure/JSMLearnerOnLatticeTest.java
index f7c1af0..46633d6 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/pattern_structure/JSMLearnerOnLatticeTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/parse_thicket/pattern_structure/JSMLearnerOnLatticeTest.java
@@ -28,230 +28,245 @@ import opennlp.tools.textsimilarity.ParseTreeChunk;
import opennlp.tools.textsimilarity.ParseTreeChunkListScorer;
import opennlp.tools.textsimilarity.ParseTreeMatcherDeterministic;
import opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcessor;
-import org.junit.Test;
-
-public class JSMLearnerOnLatticeTest {
- private final ParserChunker2MatcherProcessor chunk_maker = ParserChunker2MatcherProcessor.getInstance();
- private final LinguisticPatternStructure psPos = new LinguisticPatternStructure(0,0), psNeg = new LinguisticPatternStructure(0,0);
- private final ParseTreeMatcherDeterministic md = new ParseTreeMatcherDeterministic();
-
- @Test
- public void testJSMLearner() {
-
- String text1p = "I rent an office space. This office is for my business. I can deduct office rental expense from my business profit to calculate net income. ";
- String text2p = "To run my business, I have to rent an office. The net business profit is calculated as follows. Rental expense needs to be subtracted from revenue. ";
- String text3p = "To store goods for my retail business I rent some space. When I calculate the net income, I take revenue and subtract business expenses such as office rent. ";
- String text4p = "I rent some space for my business. To calculate my net income, I subtract from revenue my rental business expense.";
-
-
- String text1n = "I rent out a first floor unit of my house to a travel business. I need to add the rental income to my profit. However, when I repair my house, I can deduct the repair expense from my rental income. ";
- String text2n = "I receive rental income from my office. I have to claim it as a profit in my tax forms. I need to add my rental income to my profits, but subtract rental expenses such as repair from it. ";
- String text3n = "I advertised my property as a business rental. Advertisement and repair expenses can be subtracted from the rental income. Remaining rental income needs to be added to my profit and be reported as taxable profit. ";
- String text4n = "I showed my property to a business owner to rent. Expenses on my time spent on advertisement are subtracted from the rental income. My rental profits are added to my taxable income. ";
-
- List<List<ParseTreeChunk>> chunks1p = chunk_maker.formGroupedPhrasesFromChunksForPara(text1p);
- List<List<ParseTreeChunk>> chunks2p = chunk_maker.formGroupedPhrasesFromChunksForPara(text2p);
- List<List<ParseTreeChunk>> chunks3p = chunk_maker.formGroupedPhrasesFromChunksForPara(text3p);
- List<List<ParseTreeChunk>> chunks4p = chunk_maker.formGroupedPhrasesFromChunksForPara(text4p);
- List<List<ParseTreeChunk>> chunks1n = chunk_maker.formGroupedPhrasesFromChunksForPara(text1n);
- List<List<ParseTreeChunk>> chunks2n = chunk_maker.formGroupedPhrasesFromChunksForPara(text2n);
- List<List<ParseTreeChunk>> chunks3n = chunk_maker.formGroupedPhrasesFromChunksForPara(text3n);
- List<List<ParseTreeChunk>> chunks4n = chunk_maker.formGroupedPhrasesFromChunksForPara(text4n);
-
-
- LinkedHashSet<Integer> obj;
- obj = new LinkedHashSet<>();
- obj.add(0);
- psPos.AddIntent(chunks1p, obj, 0);
- obj = new LinkedHashSet<>();
- obj.add(1);
- psPos.AddIntent(chunks2p, obj, 0);
- obj = new LinkedHashSet<>();
- obj.add(2);
- psPos.AddIntent(chunks3p, obj, 0);
- obj = new LinkedHashSet<>();
- obj.add(3);
- psPos.AddIntent(chunks4p, obj, 0);
- obj = new LinkedHashSet<>();
- obj.add(0);
- psNeg.AddIntent(chunks1n, obj, 0);
- obj = new LinkedHashSet<>();
- obj.add(1);
- psNeg.AddIntent(chunks2n, obj, 0);
- obj = new LinkedHashSet<>();
- obj.add(2);
- psNeg.AddIntent(chunks3n, obj, 0);
- obj = new LinkedHashSet<>();
- obj.add(3);
- psNeg.AddIntent(chunks4n, obj, 0);
-
- String unknown = "I do not want to rent anything to anyone. I just want to rent a space for myself. I neither calculate deduction of individual or business tax. I subtract my tax from my income";
- List<List<ParseTreeChunk>> chunksUnknown = chunk_maker.formGroupedPhrasesFromChunksForPara(unknown);
- List<List<List<ParseTreeChunk>>> posIntersections = new ArrayList<>(),
- negIntersections = new ArrayList<>();
- List<List<ParseTreeChunk>> intersection;
- for(int iConcept = 0; iConcept<psPos.conceptList.size(); iConcept++){
- if (psPos.conceptList.get(iConcept).intent!=null && psPos.conceptList.get(iConcept).intent.size()>0){
- intersection = md
- .matchTwoSentencesGroupedChunksDeterministic(psPos.conceptList.get(iConcept).intent, chunksUnknown);
- if (reduceList(intersection).size()>0)
- posIntersections.add(reduceList(intersection));
- }
- if (psNeg.conceptList.get(iConcept).intent!=null && psNeg.conceptList.get(iConcept).intent.size()>0){
- intersection = md
- .matchTwoSentencesGroupedChunksDeterministic(psNeg.conceptList.get(iConcept).intent, chunksUnknown);
- if (reduceList(intersection).size()>0)
- negIntersections.add(reduceList(intersection));
- }
- }
-
- Pair<List<List<List<ParseTreeChunk>>>, List<List<List<ParseTreeChunk>>>> pair =
- removeInconsistenciesFromPosNegIntersections( posIntersections,
- negIntersections);
-
- posIntersections = pair.getFirst();
- negIntersections = pair.getSecond();
-
- List<List<List<ParseTreeChunk>>> posIntersectionsUnderNeg = new ArrayList<>(),
- negIntersectionsUnderPos = new ArrayList<>();
-
- for(int iConcept = 0; iConcept<psNeg.conceptList.size(); iConcept++){
- for (List<List<ParseTreeChunk>> negIntersection : negIntersections) {
- intersection = md
- .matchTwoSentencesGroupedChunksDeterministic(psNeg.conceptList.get(iConcept).intent, negIntersection);
- if (reduceList(intersection).size() > 0)
- posIntersectionsUnderNeg.add(reduceList(intersection));
- }
- }
- for(int iConcept = 0; iConcept<psPos.conceptList.size(); iConcept++){
- for (List<List<ParseTreeChunk>> posIntersection : posIntersections) {
- intersection = md
- .matchTwoSentencesGroupedChunksDeterministic(psPos.conceptList.get(iConcept).intent, posIntersection);
- if (reduceList(intersection).size() > 0)
- negIntersectionsUnderPos.add(reduceList(intersection));
- }
+import org.junit.jupiter.api.Test;
+
+class JSMLearnerOnLatticeTest {
+ private final ParserChunker2MatcherProcessor chunk_maker = ParserChunker2MatcherProcessor.getInstance();
+ private final LinguisticPatternStructure psPos = new LinguisticPatternStructure(0, 0), psNeg = new LinguisticPatternStructure(0, 0);
+ private final ParseTreeMatcherDeterministic md = new ParseTreeMatcherDeterministic();
+
+ @Test
+ void testJSMLearner() {
+
+ String text1p = "I rent an office space. This office is for my business. I can deduct office rental expense from my business profit to calculate net income. ";
+ String text2p = "To run my business, I have to rent an office. The net business profit is calculated as follows. Rental expense needs to be subtracted from revenue. ";
+ String text3p = "To store goods for my retail business I rent some space. When I calculate the net income, I take revenue and subtract business expenses such as office rent. ";
+ String text4p = "I rent some space for my business. To calculate my net income, I subtract from revenue my rental business expense.";
+
+
+ String text1n = "I rent out a first floor unit of my house to a travel business. I need to add the rental income to my profit. However, when I repair my house, I can deduct the repair expense from my rental income. ";
+ String text2n = "I receive rental income from my office. I have to claim it as a profit in my tax forms. I need to add my rental income to my profits, but subtract rental expenses such as repair from it. ";
+ String text3n = "I advertised my property as a business rental. Advertisement and repair expenses can be subtracted from the rental income. Remaining rental income needs to be added to my profit and be reported as taxable profit. ";
+ String text4n = "I showed my property to a business owner to rent. Expenses on my time spent on advertisement are subtracted from the rental income. My rental profits are added to my taxable income. ";
+
+ List<List<ParseTreeChunk>> chunks1p = chunk_maker.formGroupedPhrasesFromChunksForPara(text1p);
+ List<List<ParseTreeChunk>> chunks2p = chunk_maker.formGroupedPhrasesFromChunksForPara(text2p);
+ List<List<ParseTreeChunk>> chunks3p = chunk_maker.formGroupedPhrasesFromChunksForPara(text3p);
+ List<List<ParseTreeChunk>> chunks4p = chunk_maker.formGroupedPhrasesFromChunksForPara(text4p);
+ List<List<ParseTreeChunk>> chunks1n = chunk_maker.formGroupedPhrasesFromChunksForPara(text1n);
+ List<List<ParseTreeChunk>> chunks2n = chunk_maker.formGroupedPhrasesFromChunksForPara(text2n);
+ List<List<ParseTreeChunk>> chunks3n = chunk_maker.formGroupedPhrasesFromChunksForPara(text3n);
+ List<List<ParseTreeChunk>> chunks4n = chunk_maker.formGroupedPhrasesFromChunksForPara(text4n);
+
+
+ LinkedHashSet<Integer> obj;
+ obj = new LinkedHashSet<>();
+ obj.add(0);
+ psPos.AddIntent(chunks1p, obj, 0);
+ obj = new LinkedHashSet<>();
+ obj.add(1);
+ psPos.AddIntent(chunks2p, obj, 0);
+ obj = new LinkedHashSet<>();
+ obj.add(2);
+ psPos.AddIntent(chunks3p, obj, 0);
+ obj = new LinkedHashSet<>();
+ obj.add(3);
+ psPos.AddIntent(chunks4p, obj, 0);
+ obj = new LinkedHashSet<>();
+ obj.add(0);
+ psNeg.AddIntent(chunks1n, obj, 0);
+ obj = new LinkedHashSet<>();
+ obj.add(1);
+ psNeg.AddIntent(chunks2n, obj, 0);
+ obj = new LinkedHashSet<>();
+ obj.add(2);
+ psNeg.AddIntent(chunks3n, obj, 0);
+ obj = new LinkedHashSet<>();
+ obj.add(3);
+ psNeg.AddIntent(chunks4n, obj, 0);
+
+ String unknown = "I do not want to rent anything to anyone. I just want to rent a space for myself. I neither calculate deduction of individual or business tax. I subtract my tax from my income";
+ List<List<ParseTreeChunk>> chunksUnknown = chunk_maker.formGroupedPhrasesFromChunksForPara(unknown);
+ List<List<List<ParseTreeChunk>>> posIntersections = new ArrayList<>(),
+ negIntersections = new ArrayList<>();
+ List<List<ParseTreeChunk>> intersection;
+ for (int iConcept = 0; iConcept < psPos.conceptList.size(); iConcept++) {
+ if (psPos.conceptList.get(iConcept).intent != null && psPos.conceptList.get(iConcept).intent.size() > 0) {
+ intersection = md
+ .matchTwoSentencesGroupedChunksDeterministic(psPos.conceptList.get(iConcept).intent, chunksUnknown);
+ if (reduceList(intersection).size() > 0) {
+ posIntersections.add(reduceList(intersection));
+ }
+ }
+ if (psNeg.conceptList.get(iConcept).intent != null && psNeg.conceptList.get(iConcept).intent.size() > 0) {
+ intersection = md
+ .matchTwoSentencesGroupedChunksDeterministic(psNeg.conceptList.get(iConcept).intent, chunksUnknown);
+ if (reduceList(intersection).size() > 0) {
+ negIntersections.add(reduceList(intersection));
+ }
+ }
+ }
+
+ Pair<List<List<List<ParseTreeChunk>>>, List<List<List<ParseTreeChunk>>>> pair =
+ removeInconsistenciesFromPosNegIntersections(posIntersections,
+ negIntersections);
+
+ posIntersections = pair.getFirst();
+ negIntersections = pair.getSecond();
+
+ List<List<List<ParseTreeChunk>>> posIntersectionsUnderNeg = new ArrayList<>(),
+ negIntersectionsUnderPos = new ArrayList<>();
+
+ for (int iConcept = 0; iConcept < psNeg.conceptList.size(); iConcept++) {
+ for (List<List<ParseTreeChunk>> negIntersection : negIntersections) {
+ intersection = md
+ .matchTwoSentencesGroupedChunksDeterministic(psNeg.conceptList.get(iConcept).intent, negIntersection);
+ if (reduceList(intersection).size() > 0) {
+ posIntersectionsUnderNeg.add(reduceList(intersection));
+ }
+ }
+ }
+
+ for (int iConcept = 0; iConcept < psPos.conceptList.size(); iConcept++) {
+ for (List<List<ParseTreeChunk>> posIntersection : posIntersections) {
+ intersection = md
+ .matchTwoSentencesGroupedChunksDeterministic(psPos.conceptList.get(iConcept).intent, posIntersection);
+ if (reduceList(intersection).size() > 0) {
+ negIntersectionsUnderPos.add(reduceList(intersection));
+ }
+ }
+ }
+
+ List<ParseTreeChunk> posIntersectionsUnderNegLst = flattenParseTreeChunkLst(posIntersectionsUnderNeg);
+ List<ParseTreeChunk> negIntersectionsUnderPosLst = flattenParseTreeChunkLst(negIntersectionsUnderPos);
+
+ posIntersectionsUnderNegLst = subtract(posIntersectionsUnderNegLst, negIntersectionsUnderPosLst);
+ negIntersectionsUnderPosLst = subtract(negIntersectionsUnderPosLst, posIntersectionsUnderNegLst);
+
+ // System.out.println("Pos - neg inters = "+posIntersectionsUnderNegLst);
+ // System.out.println("Neg - pos inters = "+negIntersectionsUnderPosLst);
+
+ }
+
+ private List<List<ParseTreeChunk>> reduceList(List<List<ParseTreeChunk>> list) {
+ float minScore = 1.3f;
+ List<List<ParseTreeChunk>> newList = new ArrayList<>();
+
+
+ ParseTreeChunkListScorer scorer = new ParseTreeChunkListScorer();
+ for (List<ParseTreeChunk> group : list) {
+ List<ParseTreeChunk> newGroup = new ArrayList<>();
+ for (ParseTreeChunk ch : group) {
+ if (scorer.getScore(ch) > minScore) {
+ newGroup.add(ch);
+ }
+ }
+ if (newGroup.size() > 0) {
+ newList.add(newGroup);
}
-
- List<ParseTreeChunk>posIntersectionsUnderNegLst = flattenParseTreeChunkLst(posIntersectionsUnderNeg);
- List<ParseTreeChunk>negIntersectionsUnderPosLst=flattenParseTreeChunkLst(negIntersectionsUnderPos);
-
- posIntersectionsUnderNegLst = subtract(posIntersectionsUnderNegLst, negIntersectionsUnderPosLst);
- negIntersectionsUnderPosLst= subtract(negIntersectionsUnderPosLst, posIntersectionsUnderNegLst);
-
- // System.out.println("Pos - neg inters = "+posIntersectionsUnderNegLst);
- // System.out.println("Neg - pos inters = "+negIntersectionsUnderPosLst);
-
- }
-
- private List<List<ParseTreeChunk>> reduceList(List<List<ParseTreeChunk>> list){
- float minScore = 1.3f;
- List<List<ParseTreeChunk>> newList = new ArrayList<>();
-
-
- ParseTreeChunkListScorer scorer = new ParseTreeChunkListScorer();
- for( List<ParseTreeChunk> group: list){
- List<ParseTreeChunk> newGroup = new ArrayList<>();
- for(ParseTreeChunk ch: group){
- if (scorer.getScore(ch) > minScore)
- newGroup.add(ch);
- }
- if (newGroup.size()>0)
- newList.add(newGroup);
- }
-
- return newList;
-
- }
-
- private List<List<ParseTreeChunk>> flattenParseTreeChunkListList(List<List<List<ParseTreeChunk>>> listOfLists){
- List<List<ParseTreeChunk>> newList = new ArrayList<>();
-
- for( List<List<ParseTreeChunk>> member: listOfLists){
- Set<ParseTreeChunk> newSet= new HashSet<>();
- for( List<ParseTreeChunk> group: member){
- if (group.size()>0)
- newSet.addAll(group);
- }
- newList.add(new ArrayList<>(newSet));
+ }
+
+ return newList;
+
+ }
+
+ private List<List<ParseTreeChunk>> flattenParseTreeChunkListList(List<List<List<ParseTreeChunk>>> listOfLists) {
+ List<List<ParseTreeChunk>> newList = new ArrayList<>();
+
+ for (List<List<ParseTreeChunk>> member : listOfLists) {
+ Set<ParseTreeChunk> newSet = new HashSet<>();
+ for (List<ParseTreeChunk> group : member) {
+ if (group.size() > 0) {
+ newSet.addAll(group);
+ }
+ }
+ newList.add(new ArrayList<>(newSet));
+ }
+
+ return newList;
+ }
+
+ private List<ParseTreeChunk> flattenParseTreeChunkLst(List<List<List<ParseTreeChunk>>> listOfLists) {
+ Set<ParseTreeChunk> newSetAll = new HashSet<>();
+ for (List<List<ParseTreeChunk>> member : listOfLists) {
+ Set<ParseTreeChunk> newSet = new HashSet<>();
+ for (List<ParseTreeChunk> group : member) {
+ if (group.size() > 0) {
+ newSet.addAll(group);
+ }
+ }
+ newSetAll.addAll(newSet);
+ }
+
+ return removeDuplicates(new ArrayList<>(newSetAll));
+ }
+
+ private List<ParseTreeChunk> removeDuplicates(List<ParseTreeChunk> dupes) {
+ List<Integer> toDelete = new ArrayList<>();
+ for (int i = 0; i < dupes.size(); i++) {
+ for (int j = i + 1; j < dupes.size(); j++) {
+ if (dupes.get(i).equals(dupes.get(j))) {
+ toDelete.add(j);
+ }
+ }
+ }
+ List<ParseTreeChunk> cleaned = new ArrayList<>();
+ for (int i = 0; i < dupes.size(); i++) {
+ if (!toDelete.contains(i)) {
+ cleaned.add(dupes.get(i));
}
-
- return newList;
- }
-
- private List<ParseTreeChunk> flattenParseTreeChunkLst(List<List<List<ParseTreeChunk>>> listOfLists){
- Set<ParseTreeChunk> newSetAll = new HashSet<>();
- for( List<List<ParseTreeChunk>> member: listOfLists){
- Set<ParseTreeChunk> newSet= new HashSet<>();
- for( List<ParseTreeChunk> group: member){
- if (group.size()>0)
- newSet.addAll(group);
- }
- newSetAll.addAll(newSet);
+ }
+ return cleaned;
+ }
+
+ private List<ParseTreeChunk> subtract(List<ParseTreeChunk> main, List<ParseTreeChunk> toSubtract) {
+ List<Integer> toDelete = new ArrayList<>();
+ for (int i = 0; i < main.size(); i++) {
+ for (ParseTreeChunk parseTreeChunk : toSubtract) {
+ if (main.get(i).equals(parseTreeChunk)) {
+ toDelete.add(i);
+ }
+ }
+ }
+ List<ParseTreeChunk> cleaned = new ArrayList<>();
+ for (int i = 0; i < main.size(); i++) {
+ if (!toDelete.contains(i)) {
+ cleaned.add(main.get(i));
}
-
- return removeDuplicates(new ArrayList<>(newSetAll));
- }
-
- private List<ParseTreeChunk> removeDuplicates(List<ParseTreeChunk> dupes){
- List<Integer> toDelete = new ArrayList<>();
- for(int i=0; i<dupes.size(); i++)
- for(int j=i+1; j<dupes.size(); j++){
- if (dupes.get(i).equals(dupes.get(j))){
- toDelete.add(j);
- }
- }
- List<ParseTreeChunk> cleaned = new ArrayList<>();
- for(int i=0; i<dupes.size(); i++){
- if (!toDelete.contains(i))
- cleaned.add(dupes.get(i));
- }
- return cleaned;
- }
-
- private List<ParseTreeChunk> subtract(List<ParseTreeChunk> main, List<ParseTreeChunk> toSubtract){
- List<Integer> toDelete = new ArrayList<>();
- for(int i=0; i<main.size(); i++)
- for (ParseTreeChunk parseTreeChunk : toSubtract) {
- if (main.get(i).equals(parseTreeChunk)) {
- toDelete.add(i);
- }
- }
- List<ParseTreeChunk> cleaned = new ArrayList<>();
- for(int i=0; i<main.size(); i++){
- if (!toDelete.contains(i))
- cleaned.add(main.get(i));
+ }
+ return cleaned;
+ }
+
+ private List<ParseTreeChunk> intersectParseTreeChunkLists(List<ParseTreeChunk> a, List<ParseTreeChunk> b) {
+ List<Integer> inters = new ArrayList<>();
+ for (int i = 0; i < a.size(); i++) {
+ for (ParseTreeChunk parseTreeChunk : b) {
+ if (a.get(i).equals(parseTreeChunk)) {
+ inters.add(i);
+ }
+ }
+ }
+ List<ParseTreeChunk> cleaned = new ArrayList<>();
+ for (int i = 0; i < a.size(); i++) {
+ if (inters.contains(i)) {
+ cleaned.add(a.get(i));
}
- return cleaned;
- }
-
- private List<ParseTreeChunk> intersectParseTreeChunkLists(List<ParseTreeChunk> a, List<ParseTreeChunk> b){
- List<Integer> inters = new ArrayList<>();
- for(int i=0; i<a.size(); i++)
- for (ParseTreeChunk parseTreeChunk : b) {
- if (a.get(i).equals(parseTreeChunk)) {
- inters.add(i);
- }
- }
- List<ParseTreeChunk> cleaned = new ArrayList<>();
- for(int i=0; i<a.size(); i++){
- if (inters.contains(i))
- cleaned.add(a.get(i));
- }
- return cleaned;
- }
+ }
+ return cleaned;
+ }
- private Pair<List<List<List<ParseTreeChunk>>>, List<List<List<ParseTreeChunk>>>>
- removeInconsistenciesFromPosNegIntersections(List<List<List<ParseTreeChunk>>> pos,
- List<List<List<ParseTreeChunk>>> neg ){
+ private Pair<List<List<List<ParseTreeChunk>>>, List<List<List<ParseTreeChunk>>>>
+ removeInconsistenciesFromPosNegIntersections(List<List<List<ParseTreeChunk>>> pos,
+ List<List<List<ParseTreeChunk>>> neg) {
- List<ParseTreeChunk> posIntersectionsFl = flattenParseTreeChunkLst(pos);
- List<ParseTreeChunk> negIntersectionsFl = flattenParseTreeChunkLst(neg);
+ List<ParseTreeChunk> posIntersectionsFl = flattenParseTreeChunkLst(pos);
+ List<ParseTreeChunk> negIntersectionsFl = flattenParseTreeChunkLst(neg);
- List<ParseTreeChunk> intersParseTreeChunkLists = intersectParseTreeChunkLists(posIntersectionsFl, negIntersectionsFl);
+ List<ParseTreeChunk> intersParseTreeChunkLists = intersectParseTreeChunkLists(posIntersectionsFl, negIntersectionsFl);
- List<List<List<ParseTreeChunk>>> cleanedFromInconsPos = new ArrayList<>(),
- cleanedFromInconsNeg = new ArrayList<>();
+ List<List<List<ParseTreeChunk>>> cleanedFromInconsPos = new ArrayList<>(),
+ cleanedFromInconsNeg = new ArrayList<>();
/*
System.out.println("pos = "+ pos);
System.out.println("neg = "+ neg);
@@ -260,49 +275,57 @@ public class JSMLearnerOnLatticeTest {
System.out.println("inters = "+ intersParseTreeChunkLists);
*/
- for( List<List<ParseTreeChunk>> member: pos){
- List<List<ParseTreeChunk>> memberList = new ArrayList<>();
- for( List<ParseTreeChunk> group: member){
- List<ParseTreeChunk> newGroup = new ArrayList<>();
- for(ParseTreeChunk ch: group){
- boolean bSkip = false;
- for(ParseTreeChunk check: intersParseTreeChunkLists){
- if (check.equals(ch))
- bSkip=true;
- }
- if (!bSkip)
- newGroup.add(ch);
- }
- if (newGroup.size()>0)
- memberList.add(newGroup);
- }
- if (memberList.size()>0)
- cleanedFromInconsPos.add(memberList);
+ for (List<List<ParseTreeChunk>> member : pos) {
+ List<List<ParseTreeChunk>> memberList = new ArrayList<>();
+ for (List<ParseTreeChunk> group : member) {
+ List<ParseTreeChunk> newGroup = new ArrayList<>();
+ for (ParseTreeChunk ch : group) {
+ boolean bSkip = false;
+ for (ParseTreeChunk check : intersParseTreeChunkLists) {
+ if (check.equals(ch)) {
+ bSkip = true;
+ }
+ }
+ if (!bSkip) {
+ newGroup.add(ch);
+ }
+ }
+ if (newGroup.size() > 0) {
+ memberList.add(newGroup);
+ }
+ }
+ if (memberList.size() > 0) {
+ cleanedFromInconsPos.add(memberList);
}
-
- for( List<List<ParseTreeChunk>> member: neg){
- List<List<ParseTreeChunk>> memberList = new ArrayList<>();
- for( List<ParseTreeChunk> group: member){
- List<ParseTreeChunk> newGroup = new ArrayList<>();
- for(ParseTreeChunk ch: group){
- boolean bSkip = false;
- for(ParseTreeChunk check: intersParseTreeChunkLists){
- if (check.equals(ch))
- bSkip=true;
- }
- if (!bSkip)
- newGroup.add(ch);
- }
- if (newGroup.size()>0)
- memberList.add(newGroup);
- }
- if (memberList.size()>0)
- cleanedFromInconsNeg.add(memberList);
+ }
+
+ for (List<List<ParseTreeChunk>> member : neg) {
+ List<List<ParseTreeChunk>> memberList = new ArrayList<>();
+ for (List<ParseTreeChunk> group : member) {
+ List<ParseTreeChunk> newGroup = new ArrayList<>();
+ for (ParseTreeChunk ch : group) {
+ boolean bSkip = false;
+ for (ParseTreeChunk check : intersParseTreeChunkLists) {
+ if (check.equals(ch)) {
+ bSkip = true;
+ }
+ }
+ if (!bSkip) {
+ newGroup.add(ch);
+ }
+ }
+ if (newGroup.size() > 0) {
+ memberList.add(newGroup);
+ }
+ }
+ if (memberList.size() > 0) {
+ cleanedFromInconsNeg.add(memberList);
}
+ }
- return new Pair<>(cleanedFromInconsPos, cleanedFromInconsNeg);
+ return new Pair<>(cleanedFromInconsPos, cleanedFromInconsNeg);
- }
+ }
}
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/similarity/apps/SearchResultsProcessorTest.java b/opennlp-similarity/src/test/java/opennlp/tools/similarity/apps/SearchResultsProcessorTest.java
index 738f702..5739a56 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/similarity/apps/SearchResultsProcessorTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/similarity/apps/SearchResultsProcessorTest.java
@@ -18,15 +18,15 @@ package opennlp.tools.similarity.apps;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class SearchResultsProcessorTest {
+class SearchResultsProcessorTest {
private final SearchResultsProcessor proc = new SearchResultsProcessor();
@Test
- public void testSearchOrder() {
+ void testSearchOrder() {
List<HitBase> res = proc.runSearch("How can I pay tax on my income abroad");
// we verify that top answers have high similarity score
@@ -43,7 +43,7 @@ public class SearchResultsProcessorTest {
}
@Test
- public void testSearchOrder2() {
+ void testSearchOrder2() {
List<HitBase> res = proc.runSearch("Can I estimate what my income tax would be by using my last pay");
HitBase first = res.get(0);
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/similarity/apps/SpeechRecognitionResultsProcessorTest.java b/opennlp-similarity/src/test/java/opennlp/tools/similarity/apps/SpeechRecognitionResultsProcessorTest.java
index 2c8a516..8027591 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/similarity/apps/SpeechRecognitionResultsProcessorTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/similarity/apps/SpeechRecognitionResultsProcessorTest.java
@@ -21,25 +21,25 @@ package opennlp.tools.similarity.apps;
import java.util.Arrays;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import opennlp.tools.similarity.apps.SpeechRecognitionResultsProcessor.SentenceMeaningfullnessScore;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class SpeechRecognitionResultsProcessorTest {
+class SpeechRecognitionResultsProcessorTest {
@Test
- public void testRestaurantEntityInSpeechRecognitionResults() {
+ void testRestaurantEntityInSpeechRecognitionResults() {
SpeechRecognitionResultsProcessor proc = new SpeechRecognitionResultsProcessor();
List<SentenceMeaningfullnessScore> res = proc.runSearchAndScoreMeaningfulness(Arrays.asList(
- "remember to buy milk tomorrow for details",
- "remember to buy milk tomorrow from trader joes",
- "remember to buy milk tomorrow from 3 to jones",
- "remember to buy milk tomorrow for for details",
- "remember to buy milk tomorrow from third to joes",
- "remember to buy milk tomorrow from third to jones",
- "remember to buy milk tomorrow from for d jones"));
+ "remember to buy milk tomorrow for details",
+ "remember to buy milk tomorrow from trader joes",
+ "remember to buy milk tomorrow from 3 to jones",
+ "remember to buy milk tomorrow for for details",
+ "remember to buy milk tomorrow from third to joes",
+ "remember to buy milk tomorrow from third to jones",
+ "remember to buy milk tomorrow from for d jones"));
assertTrue(res.get(1).getScore() > res.get(0).getScore()
&& res.get(1).getScore() > res.get(2).getScore()
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/similarity/apps/taxo_builder/TaxonomyBuildMatchTest.java b/opennlp-similarity/src/test/java/opennlp/tools/similarity/apps/taxo_builder/TaxonomyBuildMatchTest.java
index b14215a..18f30d9 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/similarity/apps/taxo_builder/TaxonomyBuildMatchTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/similarity/apps/taxo_builder/TaxonomyBuildMatchTest.java
@@ -16,23 +16,23 @@
*/
package opennlp.tools.similarity.apps.taxo_builder;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class TaxonomyBuildMatchTest {
+class TaxonomyBuildMatchTest {
@Test
- public void testTaxonomySeedImport() {
+ void testTaxonomySeedImport() {
AriAdapter ad = new AriAdapter();
ad.getChainsFromARIfile("src/test/resources/taxonomies/irs_dom.ari");
assertTrue(ad.lemma_AssocWords.size() > 0);
}
@Test
- @Ignore // TODO Check if this test works as expected, and: why it takes so much time.
- public void testTaxonomyBuild() {
+ @Disabled // TODO Check if this test works as expected, and: why it takes so much time.
+ void testTaxonomyBuild() {
TaxonomyExtenderViaMebMining self = new TaxonomyExtenderViaMebMining();
self.extendTaxonomy("src/test/resources/taxonomies/irs_dom.ari", "tax", "en");
self.close();
@@ -40,13 +40,13 @@ public class TaxonomyBuildMatchTest {
}
@Test
- public void testTaxonomyMatch() {
+ void testTaxonomyMatch() {
TaxoQuerySnapshotMatcher matcher = new TaxoQuerySnapshotMatcher(
"src/test/resources/taxonomies/irs_domTaxo.dat");
int score = matcher.getTaxoScore(
- "Can Form 1040 EZ be used to claim the earned income credit.",
- "Can Form 1040EZ be used to claim the earned income credit? . " +
- "Must I be entitled to claim a child as a dependent to claim the earned income credit based on the child being ");
+ "Can Form 1040 EZ be used to claim the earned income credit.",
+ "Can Form 1040EZ be used to claim the earned income credit? . " +
+ "Must I be entitled to claim a child as a dependent to claim the earned income credit based on the child being ");
assertTrue(score > 3);
matcher.close();
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/GeneralizationListReducerTest.java b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/GeneralizationListReducerTest.java
index 7cc4ff1..82fad2b 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/GeneralizationListReducerTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/GeneralizationListReducerTest.java
@@ -20,38 +20,38 @@ package opennlp.tools.textsimilarity;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class GeneralizationListReducerTest {
+class GeneralizationListReducerTest {
private final GeneralizationListReducer generalizationListReducer = new GeneralizationListReducer();
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
assertNotNull(generalizationListReducer);
}
@Test
- public void test() {
- ParseTreeChunk ch1 = new ParseTreeChunk("VP", new String[] { "run",
- "around", "tigers", "zoo" }, new String[] { "VB", "IN", "NP", "NP" });
+ void test() {
+ ParseTreeChunk ch1 = new ParseTreeChunk("VP", new String[] {"run",
+ "around", "tigers", "zoo"}, new String[] {"VB", "IN", "NP", "NP"});
- ParseTreeChunk ch2 = new ParseTreeChunk("NP", new String[] { "run",
- "around", "tigers" }, new String[] { "VB", "IN", "NP", });
+ ParseTreeChunk ch2 = new ParseTreeChunk("NP", new String[] {"run",
+ "around", "tigers"}, new String[] {"VB", "IN", "NP",});
- ParseTreeChunk ch3 = new ParseTreeChunk("NP", new String[] { "the",
- "tigers" }, new String[] { "DT", "NP", });
+ ParseTreeChunk ch3 = new ParseTreeChunk("NP", new String[] {"the",
+ "tigers"}, new String[] {"DT", "NP",});
- ParseTreeChunk ch4 = new ParseTreeChunk("NP", new String[] { "the", "*",
- "flying", "car" }, new String[] { "DT", "NN", "VBG", "NN" });
+ ParseTreeChunk ch4 = new ParseTreeChunk("NP", new String[] {"the", "*",
+ "flying", "car"}, new String[] {"DT", "NN", "VBG", "NN"});
- ParseTreeChunk ch5 = new ParseTreeChunk("NP", new String[] { "the", "*" },
- new String[] { "DT", "NN", });
+ ParseTreeChunk ch5 = new ParseTreeChunk("NP", new String[] {"the", "*"},
+ new String[] {"DT", "NN",});
// [DT-the NN-* VBG-flying NN-car ], [], [], [DT-the NN-* ]]
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/LemmaFormManagerTest.java b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/LemmaFormManagerTest.java
index 9fb2c1e..97eaf8c 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/LemmaFormManagerTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/LemmaFormManagerTest.java
@@ -17,24 +17,24 @@
package opennlp.tools.textsimilarity;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
-public class LemmaFormManagerTest {
+class LemmaFormManagerTest {
private final LemmaFormManager lemmaFormManager = new LemmaFormManager();
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
assertNotNull(lemmaFormManager);
}
@Test
- public void testMatches() {
+ void testMatches() {
assertEquals(lemmaFormManager.matchLemmas(null, "loud", "loudness", "NN"),
"loud");
assertNull(lemmaFormManager.matchLemmas(null, "24", "12", "CD"));
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/ParseTreeChunkListScorerTest.java b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/ParseTreeChunkListScorerTest.java
index 8b1cb37..0533b3c 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/ParseTreeChunkListScorerTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/ParseTreeChunkListScorerTest.java
@@ -19,16 +19,16 @@ package opennlp.tools.textsimilarity;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class ParseTreeChunkListScorerTest {
+class ParseTreeChunkListScorerTest {
private final ParseTreeChunkListScorer parseTreeChunkListScorer = new ParseTreeChunkListScorer();
private final ParseTreeChunk parseTreeChunk = new ParseTreeChunk();
@Test
- public void test() {
+ void test() {
List<List<ParseTreeChunk>> chs = parseTreeChunk
.obtainParseTreeChunkListByParsingList("[[ [NN-* IN-in NP-israel ], [NP-* IN-in NP-israel ], [NP-* IN-* TO-* NN-* ], [NN-visa IN-* NN-* IN-in ]],"
+ " [ [VB-get NN-visa IN-* NN-* IN-in .-* ], [VBD-* IN-* NN-* NN-* .-* ], [VB-* NP-* ]]]");
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/ParseTreeChunkTest.java b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/ParseTreeChunkTest.java
index 9294e20..72a6f9f 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/ParseTreeChunkTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/ParseTreeChunkTest.java
@@ -17,19 +17,19 @@
package opennlp.tools.textsimilarity;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.List;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
-public class ParseTreeChunkTest {
+class ParseTreeChunkTest {
private final ParseTreeMatcherDeterministic parseTreeMatcher = new ParseTreeMatcherDeterministic();
private final ParseTreeChunk parseTreeChunk = new ParseTreeChunk();
private final ParseTreeChunkListScorer parseTreeChunkListScorer = new ParseTreeChunkListScorer();
@Test
- public void test() {
+ void test() {
ParseTreeChunk ch1, ch2;
List<List<ParseTreeChunk>> chRes;
@@ -39,60 +39,60 @@ public class ParseTreeChunkTest {
// NP [JJ-great JJ-unsecured NN-loan NNS-deals ]
// NP [JJ-great NN-pizza NNS-deals ]
- ch1 = new ParseTreeChunk("NP", new String[] { "great", "unsecured", "loan",
- "deals" }, new String[] { "JJ", "JJ", "NN", "NNS" });
- ch2 = new ParseTreeChunk("NP", new String[] { "great", "pizza", "deals" },
- new String[] { "JJ", "NN", "NNS" });
+ ch1 = new ParseTreeChunk("NP", new String[] {"great", "unsecured", "loan",
+ "deals"}, new String[] {"JJ", "JJ", "NN", "NNS"});
+ ch2 = new ParseTreeChunk("NP", new String[] {"great", "pizza", "deals"},
+ new String[] {"JJ", "NN", "NNS"});
assertEquals(parseTreeMatcher.generalizeTwoGroupedPhrasesDeterministic(ch1, ch2).toString(),
- "[ [JJ-great NNS-deals ]]");
+ "[ [JJ-great NNS-deals ]]");
- ch1 = new ParseTreeChunk("NP", new String[] { "great", "unsecured", "loan",
- "of", "jambo" }, new String[] { "JJ", "JJ", "NN", "IN", "NN" });
+ ch1 = new ParseTreeChunk("NP", new String[] {"great", "unsecured", "loan",
+ "of", "jambo"}, new String[] {"JJ", "JJ", "NN", "IN", "NN"});
- ch2 = new ParseTreeChunk("NP", new String[] { "great", "jambo", "loan" },
- new String[] { "JJ", "NN", "NN" });
+ ch2 = new ParseTreeChunk("NP", new String[] {"great", "jambo", "loan"},
+ new String[] {"JJ", "NN", "NN"});
assertEquals(parseTreeMatcher.generalizeTwoGroupedPhrasesDeterministic(ch1, ch2).toString(),
- "[ [JJ-great NN-loan ], [NN-jambo ]]");
+ "[ [JJ-great NN-loan ], [NN-jambo ]]");
- ch1 = new ParseTreeChunk("NP", new String[] { "I", "love", "to", "run",
- "around", "zoo", "with", "tigers" }, new String[] { "NP", "VBP", "TO",
- "VB", "IN", "NP", "IN", "NP" });
+ ch1 = new ParseTreeChunk("NP", new String[] {"I", "love", "to", "run",
+ "around", "zoo", "with", "tigers"}, new String[] {"NP", "VBP", "TO",
+ "VB", "IN", "NP", "IN", "NP"});
- ch2 = new ParseTreeChunk("NP", new String[] { "I", "like", "it", "because",
- "it", "is", "loud" }, new String[] { "NP", "IN", "NP", "IN", "NP",
- "VBZ", "ADJP" });
+ ch2 = new ParseTreeChunk("NP", new String[] {"I", "like", "it", "because",
+ "it", "is", "loud"}, new String[] {"NP", "IN", "NP", "IN", "NP",
+ "VBZ", "ADJP"});
assertEquals(parseTreeMatcher.generalizeTwoGroupedPhrasesDeterministic(ch1, ch2).toString(),
- "[ [NP-i ]]");
+ "[ [NP-i ]]");
- ch1 = new ParseTreeChunk("NP", new String[] { "love", "to", "run",
- "around", "zoo", "with", "tigers" }, new String[] { "VBP", "TO", "VB",
- "IN", "NP", "IN", "NP" });
+ ch1 = new ParseTreeChunk("NP", new String[] {"love", "to", "run",
+ "around", "zoo", "with", "tigers"}, new String[] {"VBP", "TO", "VB",
+ "IN", "NP", "IN", "NP"});
- ch2 = new ParseTreeChunk("VP", new String[] { "run", "to", "the", "tiger",
- "zoo" }, new String[] { "VBP", "TO", "DT", "NN", "NN" });
+ ch2 = new ParseTreeChunk("VP", new String[] {"run", "to", "the", "tiger",
+ "zoo"}, new String[] {"VBP", "TO", "DT", "NN", "NN"});
assertEquals(parseTreeMatcher.generalizeTwoGroupedPhrasesDeterministic(ch1, ch2).toString(),
"[ [VBP-* TO-to ], [VB-run IN-* NP-zoo ], [NP-tigers ]]");
- ch1 = new ParseTreeChunk("VP", new String[] { "love", "to", "run",
- "around", "tigers", "zoo" }, new String[] { "VBP", "TO", "VB", "IN",
- "NP", "NP" });
- ch2 = new ParseTreeChunk("VP", new String[] { "run", "to", "the", "tiger",
- "zoo" }, new String[] { "VBP", "TO", "DT", "NN", "NN" });
+ ch1 = new ParseTreeChunk("VP", new String[] {"love", "to", "run",
+ "around", "tigers", "zoo"}, new String[] {"VBP", "TO", "VB", "IN",
+ "NP", "NP"});
+ ch2 = new ParseTreeChunk("VP", new String[] {"run", "to", "the", "tiger",
+ "zoo"}, new String[] {"VBP", "TO", "DT", "NN", "NN"});
assertEquals(parseTreeMatcher.generalizeTwoGroupedPhrasesDeterministic(ch1, ch2).toString(),
- "[ [VBP-* TO-to ], [VB-run IN-* NP-tigers NP-zoo ]]");
- ch1 = new ParseTreeChunk("VP", new String[] { "run", "around", "tigers",
- "zoo" }, new String[] { "VB", "IN", "NP", "NP" });
+ "[ [VBP-* TO-to ], [VB-run IN-* NP-tigers NP-zoo ]]");
+ ch1 = new ParseTreeChunk("VP", new String[] {"run", "around", "tigers",
+ "zoo"}, new String[] {"VB", "IN", "NP", "NP"});
- ch2 = new ParseTreeChunk("NP", new String[] { "run", "to", "the", "tiger",
- "zoo" }, new String[] { "VBP", "TO", "DT", "NN", "NN" });
+ ch2 = new ParseTreeChunk("NP", new String[] {"run", "to", "the", "tiger",
+ "zoo"}, new String[] {"VBP", "TO", "DT", "NN", "NN"});
assertEquals(parseTreeMatcher.generalizeTwoGroupedPhrasesDeterministic(ch1, ch2).toString(),
- "[ [VB-run IN-* NP-tigers NP-zoo ]]");
+ "[ [VB-run IN-* NP-tigers NP-zoo ]]");
List<List<ParseTreeChunk>> lch1 = parseTreeChunk.obtainParseTreeChunkListByParsingList(
- "[[[DT-all NNS-children WHNP-who VBP-are CD-four NNS-years JJ-old IN-on CC-or IN-before NP-September ]]]");
+ "[[[DT-all NNS-children WHNP-who VBP-are CD-four NNS-years JJ-old IN-on CC-or IN-before NP-September ]]]");
List<List<ParseTreeChunk>> lch2 = parseTreeChunk.obtainParseTreeChunkListByParsingList(
- "[[[NP-Children CD-four NNS-years JJ-old ]]]");
+ "[[[NP-Children CD-four NNS-years JJ-old ]]]");
chRes = parseTreeMatcher.matchTwoSentencesGroupedChunksDeterministic(lch1, lch2);
assertEquals(chRes.toString(), "[[ [NNS-children CD-four NNS-years JJ-old ]]]");
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/SyntMatcherTest.java b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/SyntMatcherTest.java
index ae503d9..f9bcd7e 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/SyntMatcherTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/SyntMatcherTest.java
@@ -20,36 +20,36 @@ package opennlp.tools.textsimilarity;
import java.util.List;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcessor;
-import static org.junit.Assert.*;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-public class SyntMatcherTest {
+class SyntMatcherTest {
private final ParseTreeChunk parseTreeChunk = new ParseTreeChunk();
-
+
private ParserChunker2MatcherProcessor parserChunker2Matcher;
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
parserChunker2Matcher = ParserChunker2MatcherProcessor.getInstance();
assertNotNull(parserChunker2Matcher);
}
- @After
- public void cleanUp() {
+ @AfterEach
+ void cleanUp() {
if (parserChunker2Matcher != null) {
parserChunker2Matcher.close();
}
}
@Test
- public void testMatch() {
+ void testMatch() {
List<List<ParseTreeChunk>> matchResult = parserChunker2Matcher.assessRelevance(
// "Can I get auto focus lens for digital camera",
// "How can I get short focus zoom lens for digital camera"
@@ -83,7 +83,7 @@ public class SyntMatcherTest {
}
@Test
- public void testMatchDigitalCamera() {
+ void testMatchDigitalCamera() {
List<List<ParseTreeChunk>> matchResult = parserChunker2Matcher.assessRelevance(
"I am curious how to use the digital zoom of this camera for filming insects",
"How can I get short focus zoom lens for digital camera")
@@ -98,7 +98,7 @@ public class SyntMatcherTest {
}
@Test
- public void testHighSimilarity() {
+ void testHighSimilarity() {
List<List<ParseTreeChunk>> matchResult = parserChunker2Matcher.assessRelevance(
"Can I get auto focus lens for digital camera",
"How can I get short focus zoom lens for digital camera")
@@ -113,7 +113,7 @@ public class SyntMatcherTest {
}
@Test
- public void testZClose() {
+ void testZClose() {
ParserChunker2MatcherProcessor.getInstance().close();
}
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/chunker2matcher/ParserChunker2MatcherProcessorTest.java b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/chunker2matcher/ParserChunker2MatcherProcessorTest.java
index 66a0012..295aafc 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/chunker2matcher/ParserChunker2MatcherProcessorTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/chunker2matcher/ParserChunker2MatcherProcessorTest.java
@@ -19,39 +19,39 @@ package opennlp.tools.textsimilarity.chunker2matcher;
import java.util.List;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import opennlp.tools.textsimilarity.ParseTreeChunk;
import opennlp.tools.textsimilarity.ParseTreeChunkListScorer;
import opennlp.tools.textsimilarity.TextSimilarityBagOfWords;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class ParserChunker2MatcherProcessorTest {
+class ParserChunker2MatcherProcessorTest {
private final TextSimilarityBagOfWords parserBOW = new TextSimilarityBagOfWords();
private final ParseTreeChunkListScorer parseTreeChunkListScorer = new ParseTreeChunkListScorer();
-
+
private ParserChunker2MatcherProcessor parser;
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
parser = ParserChunker2MatcherProcessor.getInstance();
assertNotNull(parser);
}
- @After
- public void cleanUp() {
+ @AfterEach
+ void cleanUp() {
if (parser != null) {
parser.close();
}
}
@Test
- public void testGroupedPhrasesFormer() {
+ void testGroupedPhrasesFormer() {
String text = "Where do I apply? Go to your town office or city hall. If your town doesn't have an office, ask the town clerk or a Selectman. Tell them that you need a 1040 tax form . I Can 't Pay the Taxes on my House: What Can I Do?. Pine Tree Legal";
List<List<ParseTreeChunk>> res = parser.formGroupedPhrasesFromChunksForPara(text);
@@ -75,12 +75,12 @@ public class ParserChunker2MatcherProcessorTest {
res.toString());
res = parser.formGroupedPhrasesFromChunksForSentence("UN Ambassador Ron Prosor repeated the Israeli position that the only way the Palestinians will get UN membership and statehood is through direct negotiations with the Israelis on a comprehensive peace agreement");
assertEquals(
- "[[NP [NNP-UN NNP-Ambassador NNP-Ron NNP-Prosor ], NP [DT-the JJ-Israeli NN-position IN-that DT-the JJ-only NN-way DT-the NNPS-Palestinians ], NP [DT-the JJ-only NN-way DT-the NNPS-Palestinians ], NP [DT-the NNPS-Palestinians ], NP [NN-membership CC-and NN-statehood VBZ-is IN-through JJ-direct NNS-negotiations IN-with DT-the NNP-Israelis IN-on DT-a JJ-comprehensive NN-peace NN-agreement ], NP [JJ-direct NNS-negotiations IN-with DT-the NNP-Israelis IN-on DT-a JJ-comprehensive [...]
+ "[[NP [NNP-UN NNP-Ambassador NNP-Ron NNP-Prosor ], NP [DT-the JJ-Israeli NN-position IN-that DT-the JJ-only NN-way DT-the NNPS-Palestinians ], NP [DT-the JJ-only NN-way DT-the NNPS-Palestinians ], NP [DT-the NNPS-Palestinians ], NP [NN-membership CC-and NN-statehood VBZ-is IN-through JJ-direct NNS-negotiations IN-with DT-the NNP-Israelis IN-on DT-a JJ-comprehensive NN-peace NN-agreement ], NP [JJ-direct NNS-negotiations IN-with DT-the NNP-Israelis IN-on DT-a JJ-comprehensive NN-p [...]
res.toString());
}
@Test
- public void testPrintParseTree() {
+ void testPrintParseTree() {
try {
parser.printParseTree("How can I get short focus zoom lens for digital camera");
} catch (Exception e) {
@@ -89,7 +89,7 @@ public class ParserChunker2MatcherProcessorTest {
}
@Test
- public void testRelevanceAssessm() {
+ void testRelevanceAssessm() {
String phrase1 = "Its classy design and the Mercedes name make it a very cool vehicle to drive. "
+ "The engine makes it a powerful car. "
+ "The strong engine gives it enough power. "
@@ -103,14 +103,14 @@ public class ParserChunker2MatcherProcessorTest {
}
@Test
- public void testCompareRelevanceAssessmWithBagOfWords() {
+ void testCompareRelevanceAssessmWithBagOfWords() {
// we first demonstrate how similarity expression for DIFFERENT cases have
// too high score for bagOfWords
String phrase1 = "How to deduct rental expense from income ";
String phrase2 = "How to deduct repair expense from rental income.";
List<List<ParseTreeChunk>> matchResult = parser.assessRelevance(phrase1, phrase2).getMatchResult();
- assertEquals(
- "[[ [NN-expense IN-from NN-income ], [JJ-rental NN-* ]], [ [TO-to VB-deduct JJ-rental NN-* ], [VB-deduct NN-expense IN-from NN-income ]]]",
+ assertEquals(
+ "[[ [NN-expense IN-from NN-income ], [JJ-rental NN-* ]], [ [TO-to VB-deduct JJ-rental NN-* ], [VB-deduct NN-expense IN-from NN-income ]]]",
matchResult.toString());
double matchScore = parseTreeChunkListScorer.getParseTreeChunkListScore(matchResult);
double bagOfWordsScore = parserBOW.assessRelevanceAndGetScore(phrase1, phrase2);
@@ -124,7 +124,7 @@ public class ParserChunker2MatcherProcessorTest {
phrase2 = "Means to deduct educational expense for my son";
matchResult = parser.assessRelevance(phrase1, phrase2).getMatchResult();
assertEquals(
- "[[ [JJ-* NN-expense IN-for PRP$-my NN-* ]], [ [TO-to VB-* JJ-* NN-expense IN-for PRP$-my NN-* ]]]",
+ "[[ [JJ-* NN-expense IN-for PRP$-my NN-* ]], [ [TO-to VB-* JJ-* NN-expense IN-for PRP$-my NN-* ]]]",
matchResult.toString());
matchScore = parseTreeChunkListScorer.getParseTreeChunkListScore(matchResult);
bagOfWordsScore = parserBOW.assessRelevanceAndGetScore(phrase1, phrase2);
diff --git a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/chunker2matcher/PhraseNodeTest.java b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/chunker2matcher/PhraseNodeTest.java
index 99466d8..94b5a0d 100644
--- a/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/chunker2matcher/PhraseNodeTest.java
+++ b/opennlp-similarity/src/test/java/opennlp/tools/textsimilarity/chunker2matcher/PhraseNodeTest.java
@@ -19,24 +19,24 @@ package opennlp.tools.textsimilarity.chunker2matcher;
import java.util.List;
-import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class PhraseNodeTest {
-public class PhraseNodeTest {
-
private final ParserChunker2MatcherProcessor proc = ParserChunker2MatcherProcessor.getInstance();
- @After
- public void cleanUp() {
+ @AfterEach
+ void cleanUp() {
if (proc != null) {
proc.close();
}
}
@Test
- public void testPOSTagsExtraction() {
+ void testPOSTagsExtraction() {
SentenceNode node = proc.parseSentenceNode("How can I get there");
diff --git a/opennlp-wsd/pom.xml b/opennlp-wsd/pom.xml
index 4a47817..763ca67 100644
--- a/opennlp-wsd/pom.xml
+++ b/opennlp-wsd/pom.xml
@@ -57,9 +57,20 @@
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/AbstractEvaluatorTest.java b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/AbstractEvaluatorTest.java
index 57840eb..19d383c 100644
--- a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/AbstractEvaluatorTest.java
+++ b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/AbstractEvaluatorTest.java
@@ -19,14 +19,14 @@
package opennlp.tools.disambiguator;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.BeforeAll;
public abstract class AbstractEvaluatorTest {
private static final String MODELS_DIR = "src/test/resources/models/";
- @BeforeClass
- public static void initEnv() {
+ @BeforeAll
+ static void initEnv() {
WSDHelper.loadTokenizer(MODELS_DIR + "en-token.bin");
WSDHelper.loadTagger(MODELS_DIR + "en-pos-maxent.bin");
WSDHelper.loadLemmatizer(MODELS_DIR + "en-lemmatizer.dict.gz");
diff --git a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/LeskEvaluatorTest.java b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/LeskEvaluatorTest.java
index 114306b..90836f4 100644
--- a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/LeskEvaluatorTest.java
+++ b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/LeskEvaluatorTest.java
@@ -21,23 +21,23 @@ package opennlp.tools.disambiguator;
import java.util.ArrayList;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import opennlp.tools.disambiguator.datareader.SensevalReader;
-public class LeskEvaluatorTest extends AbstractEvaluatorTest {
+class LeskEvaluatorTest extends AbstractEvaluatorTest {
static SensevalReader seReader = new SensevalReader();
@Test
- @Ignore // TODO OPENNLP-1446: Investigate why test fails while parsing 'EnglishLS.train'
- public void testEvaluation() {
+ @Disabled // TODO OPENNLP-1446: Investigate why test fails while parsing 'EnglishLS.train'
+ void testEvaluation() {
WSDHelper.print("Evaluation Started");
Lesk lesk = new Lesk();
LeskParameters leskParams = new LeskParameters();
- boolean a[] = { true, true, true, true, true, false, false, false, false, false };
+ boolean a[] = {true, true, true, true, true, false, false, false, false, false};
leskParams.setFeatures(a);
leskParams.setLeskType(LeskParameters.LESK_TYPE.LESK_EXT_CTXT);
lesk.setParams(leskParams);
diff --git a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/LeskTester.java b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/LeskTester.java
index 46cb313..2724b79 100644
--- a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/LeskTester.java
+++ b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/LeskTester.java
@@ -6,9 +6,9 @@
* 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
@@ -19,13 +19,13 @@
package opennlp.tools.disambiguator;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.List;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import opennlp.tools.disambiguator.LeskParameters.LESK_TYPE;
import opennlp.tools.lemmatizer.Lemmatizer;
@@ -33,13 +33,13 @@ import opennlp.tools.util.Span;
/**
* This is the test class for {@link Lesk}.
- *
+ * <p>
* The scope of this test is to make sure that the Lesk disambiguator code can
* be executed. This test can not detect mistakes which lead to incorrect
* feature generation or other mistakes which decrease the disambiguation
* performance of the disambiguator.
*/
-public class LeskTester {
+class LeskTester {
// TODO write more tests
static String modelsDir = "src/test/resources/models/";
@@ -66,8 +66,8 @@ public class LeskTester {
/*
* Setup the testing variables
*/
- @BeforeClass
- public static void setUp() {
+ @BeforeAll
+ static void setUp() {
WSDHelper.loadTagger(modelsDir + "en-pos-maxent.bin");
WSDHelper.loadTokenizer(modelsDir + "en-token.bin");
@@ -90,7 +90,7 @@ public class LeskTester {
LeskParameters params = new LeskParameters();
params.setLeskType(LESK_TYPE.LESK_EXT);
- boolean a[] = { true, true, true, true, true, true, true, true, true, true };
+ boolean a[] = {true, true, true, true, true, true, true, true, true, true};
params.setFeatures(a);
lesk.setParams(params);
}
@@ -99,9 +99,9 @@ public class LeskTester {
* Tests disambiguating only one word : The ambiguous word "please"
*/
@Test
- public void testOneWordDisambiguation() {
+ void testOneWordDisambiguation() {
String sense = lesk.disambiguate(sentence1, tags1, lemmas1.get(0).toArray(new String[0]), 8);
- assertEquals("Check 'please' sense ID", "WORDNET please%2:37:00:: -1", sense);
+ assertEquals("WORDNET please%2:37:00:: -1", sense, "Check 'please' sense ID");
}
/*
@@ -110,29 +110,29 @@ public class LeskTester {
* as determiners
*/
@Test
- public void testWordSpanDisambiguation() {
+ void testWordSpanDisambiguation() {
Span span = new Span(3, 7);
List<String> senses = lesk.disambiguate(sentence2, tags2, lemmas2.get(0).toArray(new String[0]), span);
- assertEquals("Check number of returned words", 5, senses.size());
- assertEquals("Check 'highly' sense ID", "WORDNET highly%4:02:01:: 3.8",
- senses.get(0));
- assertEquals("Check 'radioactive' sense ID",
- "WORDNET radioactive%3:00:00:: 6.0", senses.get(1));
- assertEquals("Check preposition", "WSDHELPER to", senses.get(2));
- assertEquals("Check determiner", "WSDHELPER determiner", senses.get(3));
+ assertEquals(5, senses.size(), "Check number of returned words");
+ assertEquals("WORDNET highly%4:02:01:: 3.8",
+ senses.get(0), "Check 'highly' sense ID");
+ assertEquals(
+ "WORDNET radioactive%3:00:00:: 6.0", senses.get(1), "Check 'radioactive' sense ID");
+ assertEquals("WSDHELPER to", senses.get(2), "Check preposition");
+ assertEquals("WSDHELPER determiner", senses.get(3), "Check determiner");
}
/*
* Tests disambiguating all the words
*/
@Test
- public void testAllWordsDisambiguation() {
+ void testAllWordsDisambiguation() {
List<String> senses = lesk.disambiguate(sentence3, tags3, lemmas3.get(0).toArray(new String[0]));
- assertEquals("Check number of returned words", 15, senses.size());
- assertEquals("Check preposition", "WSDHELPER personal pronoun",
- senses.get(6));
+ assertEquals(15, senses.size(), "Check number of returned words");
+ assertEquals("WSDHELPER personal pronoun",
+ senses.get(6), "Check preposition");
}
}
\ No newline at end of file
diff --git a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/MFSEvaluatorTest.java b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/MFSEvaluatorTest.java
index 9d630be..34defb7 100644
--- a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/MFSEvaluatorTest.java
+++ b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/MFSEvaluatorTest.java
@@ -6,9 +6,9 @@
* 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
@@ -21,18 +21,18 @@ package opennlp.tools.disambiguator;
import java.util.ArrayList;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import opennlp.tools.disambiguator.datareader.SensevalReader;
-public class MFSEvaluatorTest extends AbstractEvaluatorTest {
+class MFSEvaluatorTest extends AbstractEvaluatorTest {
static SensevalReader seReader = new SensevalReader();
@Test
- @Ignore // TODO OPENNLP-1446: Investigate why test fails while parsing 'EnglishLS.train'
- public void testEvaluation() {
+ @Disabled // TODO OPENNLP-1446: Investigate why test fails while parsing 'EnglishLS.train'
+ void testEvaluation() {
WSDHelper.print("Evaluation Started");
MFS mfs = new MFS();
diff --git a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/MFSTester.java b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/MFSTester.java
index 72fab32..6b70476 100644
--- a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/MFSTester.java
+++ b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/MFSTester.java
@@ -6,9 +6,9 @@
* 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
@@ -19,26 +19,26 @@
package opennlp.tools.disambiguator;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.List;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import opennlp.tools.lemmatizer.Lemmatizer;
import opennlp.tools.util.Span;
/**
* This is the test class for {@link MFS}.
- *
+ * <p>
* The scope of this test is to make sure that the MFS disambiguator code can be
* executed. This test can not detect mistakes which lead to incorrect feature
* generation or other mistakes which decrease the disambiguation performance of
* the disambiguator.
*/
-public class MFSTester {
+class MFSTester {
// TODO write more tests
// TODO modify when we fix the parameter model
@@ -66,8 +66,8 @@ public class MFSTester {
/*
* Setup the testing variables and the training files
*/
- @BeforeClass
- public static void setUpAndTraining() {
+ @BeforeAll
+ static void setUpAndTraining() {
WSDHelper.loadTagger(modelsDir + "en-pos-maxent.bin");
WSDHelper.loadTokenizer(modelsDir + "en-token.bin");
@@ -94,9 +94,9 @@ public class MFSTester {
* Tests disambiguating only one word : The ambiguous word "please"
*/
@Test
- public void testOneWordDisambiguation() {
+ void testOneWordDisambiguation() {
String sense = mfs.disambiguate(sentence1, tags1, lemmas1.get(0).toArray(new String[0]), 8);
- assertEquals("Check 'please' sense ID", "WORDNET please%2:37:00::", sense);
+ assertEquals("WORDNET please%2:37:00::", sense, "Check 'please' sense ID");
}
/*
@@ -105,28 +105,28 @@ public class MFSTester {
* as determiners
*/
@Test
- public void testWordSpanDisambiguation() {
+ void testWordSpanDisambiguation() {
Span span = new Span(3, 7);
List<String> senses = mfs.disambiguate(sentence2, tags2, lemmas2.get(0).toArray(new String[0]), span);
- assertEquals("Check number of returned words", 5, senses.size());
- assertEquals("Check 'highly' sense ID", "WORDNET highly%4:02:01::",
- senses.get(0));
- assertEquals("Check 'radioactive' sense ID",
- "WORDNET radioactive%3:00:00::", senses.get(1));
- assertEquals("Check preposition", "WSDHELPER to", senses.get(2));
- assertEquals("Check determiner", "WSDHELPER determiner", senses.get(3));
+ assertEquals(5, senses.size(), "Check number of returned words");
+ assertEquals("WORDNET highly%4:02:01::",
+ senses.get(0), "Check 'highly' sense ID");
+ assertEquals(
+ "WORDNET radioactive%3:00:00::", senses.get(1), "Check 'radioactive' sense ID");
+ assertEquals("WSDHELPER to", senses.get(2), "Check preposition");
+ assertEquals("WSDHELPER determiner", senses.get(3), "Check determiner");
}
/*
* Tests disambiguating all the words
*/
@Test
- public void testAllWordsDisambiguation() {
+ void testAllWordsDisambiguation() {
List<String> senses = mfs.disambiguate(sentence3, tags3, lemmas3.get(0).toArray(new String[0]));
- assertEquals("Check number of returned words", 15, senses.size());
- assertEquals("Check preposition", "WSDHELPER personal pronoun",
- senses.get(6));
+ assertEquals(15, senses.size(), "Check number of returned words");
+ assertEquals("WSDHELPER personal pronoun",
+ senses.get(6), "Check preposition");
}
}
\ No newline at end of file
diff --git a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/WSDEvaluatorTest.java b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/WSDEvaluatorTest.java
index d6f37b3..b543acf 100644
--- a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/WSDEvaluatorTest.java
+++ b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/WSDEvaluatorTest.java
@@ -23,19 +23,19 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import opennlp.tools.disambiguator.datareader.SemcorReaderExtended;
import opennlp.tools.disambiguator.datareader.SensevalReader;
import opennlp.tools.util.ObjectStream;
import opennlp.tools.util.TrainingParameters;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
// TODO improve the tests improve parameters
-public class WSDEvaluatorTest extends AbstractEvaluatorTest {
+class WSDEvaluatorTest extends AbstractEvaluatorTest {
static SensevalReader seReader;
@@ -46,10 +46,10 @@ public class WSDEvaluatorTest extends AbstractEvaluatorTest {
static WSDModel model;
static ArrayList<String> testWords;
-
+
@Test
- @Ignore // TODO OPENNLP-1446: Investigate why test fails while parsing 'EnglishLS.train'
- public void testTraining() {
+ @Disabled // TODO OPENNLP-1446: Investigate why test fails while parsing 'EnglishLS.train'
+ void testTraining() {
WSDHelper.print("Evaluation Started");
@@ -79,15 +79,15 @@ public class WSDEvaluatorTest extends AbstractEvaluatorTest {
File outFile;
try {
writeModel = WSDisambiguatorME
- .train("en", sampleStream, trainingParams, params);
- assertNotNull("Checking the model to be written", writeModel);
+ .train("en", sampleStream, trainingParams, params);
+ assertNotNull(writeModel, "Checking the model to be written");
writeModel.writeModel(params.getTrainingDataDirectory() + word);
outFile = new File(
- params.getTrainingDataDirectory() + word + ".wsd.model");
+ params.getTrainingDataDirectory() + word + ".wsd.model");
model = new WSDModel(outFile);
- assertNotNull("Checking the read model", model);
+ assertNotNull(model, "Checking the read model");
wsdME = new WSDisambiguatorME(model, params);
- assertNotNull("Checking the disambiguator", wsdME);
+ assertNotNull(wsdME, "Checking the disambiguator");
} catch (IOException e1) {
e1.printStackTrace();
fail("Exception in training");
@@ -98,8 +98,8 @@ public class WSDEvaluatorTest extends AbstractEvaluatorTest {
}
@Test
- @Ignore // Make this work once we have migrated to JUnit5 in the sandbox components
- public void testDisambiguationEval() {
+ @Disabled // Make this work once we have migrated to JUnit5 in the sandbox components
+ void testDisambiguationEval() {
WSDHelper.print("Evaluation Started");
@@ -114,7 +114,7 @@ public class WSDEvaluatorTest extends AbstractEvaluatorTest {
WSDHelper.print("------------------" + word + "------------------");
for (WSDSample instance : instances) {
if (instance.getSenseIDs() != null && !instance.getSenseIDs()[0]
- .equals("null")) {
+ .equals("null")) {
evaluator.evaluateSample(instance);
}
}
diff --git a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/WSDTester.java b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/WSDTester.java
index 36ff2f3..36971a5 100644
--- a/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/WSDTester.java
+++ b/opennlp-wsd/src/test/java/opennlp/tools/disambiguator/WSDTester.java
@@ -6,9 +6,9 @@
* 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
@@ -19,15 +19,15 @@
package opennlp.tools.disambiguator;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.*;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import opennlp.tools.disambiguator.datareader.SemcorReaderExtended;
import opennlp.tools.lemmatizer.Lemmatizer;
@@ -48,7 +48,7 @@ import opennlp.tools.util.TrainingParameters;
* from the training sentences.
*/
-public class WSDTester {
+class WSDTester {
// TODO write more tests
// TODO modify when we fix the parameter model
@@ -64,7 +64,7 @@ public class WSDTester {
static String test1 = "We need to discuss an important topic, please write to me soon.";
static String test2 = "The component was highly radioactive to the point that"
- + " it has been activated the second it touched water";
+ + " it has been activated the second it touched water";
static String test3 = "The summer is almost over and I did not go to the beach even once";
static String[] sentence1;
@@ -82,7 +82,8 @@ public class WSDTester {
/*
* Setup the testing variables
*/
- @BeforeClass public static void setUpAndTraining() {
+ @BeforeAll
+ static void setUpAndTraining() {
WSDHelper.loadTokenizer(modelsDir + "en-token.bin");
WSDHelper.loadTagger(modelsDir + "en-pos-maxent.bin");
WSDHelper.loadLemmatizer(modelsDir + "en-lemmatizer.dict.gz");
@@ -99,7 +100,7 @@ public class WSDTester {
lemmas1 = lemmatizer.lemmatize(Arrays.asList(sentence1), Arrays.asList(tags1));
lemmas2 = lemmatizer.lemmatize(Arrays.asList(sentence2), Arrays.asList(tags2));
lemmas3 = lemmatizer.lemmatize(Arrays.asList(sentence3), Arrays.asList(tags3));
-
+
params = new WSDDefaultParameters("");
params.setTrainingDataDirectory(trainingDataDirectory);
TrainingParameters trainingParams = new TrainingParameters();
@@ -114,27 +115,28 @@ public class WSDTester {
try {
writeModel = WSDisambiguatorME
- .train("en", sampleStream, trainingParams, params);
- assertNotNull("Checking the model to be written", writeModel);
+ .train("en", sampleStream, trainingParams, params);
+ assertNotNull(writeModel, "Checking the model to be written");
writeModel.writeModel(params.getTrainingDataDirectory() + test);
outFile = new File(
- params.getTrainingDataDirectory() + test + ".wsd.model");
+ params.getTrainingDataDirectory() + test + ".wsd.model");
model = new WSDModel(outFile);
- assertNotNull("Checking the read model", model);
+ assertNotNull(model, "Checking the read model");
wsdME = new WSDisambiguatorME(model, params);
- assertNotNull("Checking the disambiguator", wsdME);
+ assertNotNull(wsdME, "Checking the disambiguator");
} catch (IOException e1) {
e1.printStackTrace();
- fail("Exception in training: "+ e1.getMessage());
+ fail("Exception in training: " + e1.getMessage());
}
}
/*
* Tests disambiguating only one word : The ambiguous word "please"
*/
- @Test public void testOneWordDisambiguation() {
+ @Test
+ void testOneWordDisambiguation() {
String sense = wsdME.disambiguate(sentence1, tags1, lemmas1.get(0).toArray(new String[0]), 8);
- assertEquals("Check 'please' sense ID", "WORDNET please%2:37:00::", sense);
+ assertEquals("WORDNET please%2:37:00::", sense, "Check 'please' sense ID");
}
/*
@@ -142,28 +144,30 @@ public class WSDTester {
* and polysemous words as well as words that do not need disambiguation such
* as determiners
*/
- @Test public void testWordSpanDisambiguation() {
+ @Test
+ void testWordSpanDisambiguation() {
Span span = new Span(3, 7);
List<String> senses = wsdME.disambiguate(sentence2, tags2, lemmas2.get(0).toArray(new String[0]), span);
- assertEquals("Check number of returned words", 5, senses.size());
- assertEquals("Check 'highly' sense ID", "WORDNET highly%4:02:01::",
- senses.get(0));
- assertEquals("Check 'radioactive' sense ID",
- "WORDNET radioactive%3:00:00::", senses.get(1));
- assertEquals("Check preposition", "WSDHELPER to", senses.get(2));
- assertEquals("Check determiner", "WSDHELPER determiner", senses.get(3));
+ assertEquals(5, senses.size(), "Check number of returned words");
+ assertEquals("WORDNET highly%4:02:01::",
+ senses.get(0), "Check 'highly' sense ID");
+ assertEquals(
+ "WORDNET radioactive%3:00:00::", senses.get(1), "Check 'radioactive' sense ID");
+ assertEquals("WSDHELPER to", senses.get(2), "Check preposition");
+ assertEquals("WSDHELPER determiner", senses.get(3), "Check determiner");
}
/*
* Tests disambiguating all the words
*/
- @Test public void testAllWordsDisambiguation() {
+ @Test
+ void testAllWordsDisambiguation() {
List<String> senses = wsdME.disambiguate(sentence3, tags3, lemmas3.get(0).toArray(new String[0]));
- assertEquals("Check number of returned words", 15, senses.size());
- assertEquals("Check preposition", "WSDHELPER personal pronoun",
- senses.get(6));
+ assertEquals(15, senses.size(), "Check number of returned words");
+ assertEquals("WSDHELPER personal pronoun",
+ senses.get(6), "Check preposition");
}
}
diff --git a/pom.xml b/pom.xml
index c5a0725..dca2b4b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -166,8 +166,8 @@
<opennlp.forkCount>1.0C</opennlp.forkCount>
<coveralls.maven.plugin>4.3.0</coveralls.maven.plugin>
<jacoco.maven.plugin>0.7.9</jacoco.maven.plugin>
- <maven.surefire.plugin>2.22.2</maven.surefire.plugin>
- <maven.failsafe.plugin>2.22.2</maven.failsafe.plugin>
+ <maven.surefire.plugin>3.0.0-M5</maven.surefire.plugin>
+ <maven.failsafe.plugin>3.0.0-M5</maven.failsafe.plugin>
<mockito.version>3.9.0</mockito.version>
</properties>
diff --git a/summarizer/pom.xml b/summarizer/pom.xml
index eda1638..fc98caa 100644
--- a/summarizer/pom.xml
+++ b/summarizer/pom.xml
@@ -50,9 +50,20 @@
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/summarizer/src/test/java/opennlp/summarization/lexicalchaining/LexChainTest.java b/summarizer/src/test/java/opennlp/summarization/lexicalchaining/LexChainTest.java
index 0f7763c..72804cb 100644
--- a/summarizer/src/test/java/opennlp/summarization/lexicalchaining/LexChainTest.java
+++ b/summarizer/src/test/java/opennlp/summarization/lexicalchaining/LexChainTest.java
@@ -20,21 +20,21 @@ package opennlp.summarization.lexicalchaining;
import opennlp.summarization.Sentence;
import opennlp.summarization.preprocess.DefaultDocProcessor;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class LexChainTest {
+class LexChainTest {
private static final String article =
- "US President Barack Obama has welcomed an agreement between the US and Russia under which Syria's chemical weapons must be destroyed or removed by mid-2014 as an \"important step\"."
+ "US President Barack Obama has welcomed an agreement between the US and Russia under which Syria's chemical weapons must be destroyed or removed by mid-2014 as an \"important step\"."
+ "But a White House statement cautioned that the US expected Syria to live up to its public commitments. "
+ "The US-Russian framework document stipulates that Syria must provide details of its stockpile within a week. "
+ "If Syria fails to comply, the deal could be enforced by a UN resolution. "
@@ -44,14 +44,14 @@ public class LexChainTest {
private static DefaultDocProcessor dp;
private static LexicalChainingSummarizer lcs;
- @BeforeClass
- public static void initEnv() throws Exception {
+ @BeforeAll
+ static void initEnv() throws Exception {
dp = new DefaultDocProcessor(LexChainTest.class.getResourceAsStream("/en-sent.bin"));
lcs = new LexicalChainingSummarizer(dp, LexChainTest.class.getResourceAsStream("/en-pos-maxent.bin"));
}
-
+
@Test
- public void testBuildLexicalChains() {
+ void testBuildLexicalChains() {
List<Sentence> sent = dp.getSentencesFromStr(article);
assertNotNull(sent);
List<LexicalChain> vh = lcs.buildLexicalChains(article, sent);
@@ -62,17 +62,17 @@ public class LexChainTest {
List<Sentence> s = dp.getSentencesFromStr(article);
Hashtable<String, Boolean> comp = new Hashtable<>();
- for(int i=vh.size()-1;i>=Math.max(vh.size()-50, 0);i--) {
+ for (int i = vh.size() - 1; i >= Math.max(vh.size() - 50, 0); i--) {
LexicalChain lc = vh.get(i);
- if(! (comp.containsKey(lc.getWord().get(0).getLexicon()))) {
+ if (!(comp.containsKey(lc.getWord().get(0).getLexicon()))) {
comp.put(lc.getWord().get(0).getLexicon(), Boolean.TRUE);
/*
for(int j=0;j<lc.getWord().size();j++)
System.out.print(lc.getWord().get(j) + " -- ");
*/
-
- assertEquals(1.0d, lc.score(), 0d);
+
+ assertEquals(1.0d, lc.score());
/*
for(Sentence sid : lc.getSentences()) {
//if(sid>=0 && sid<s.size())
@@ -85,7 +85,7 @@ public class LexChainTest {
}
@Test
- public void testGetRelation() {
+ void testGetRelation() {
try {
WordRelationshipDetermination lcs = new WordRelationshipDetermination();
LexicalChain l = new LexicalChain();
@@ -98,8 +98,8 @@ public class LexChainTest {
assertEquals(1, rel2.relation);
assertEquals(1, rel3.relation);
// assertEquals(rel, LexicalChainingSummarizer.STRONG_RELATION);
- assertEquals( WordRelation.MED_RELATION, rel2.relation);
- assertEquals( WordRelation.MED_RELATION, rel3.relation);
+ assertEquals(WordRelation.MED_RELATION, rel2.relation);
+ assertEquals(WordRelation.MED_RELATION, rel3.relation);
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/summarizer/src/test/java/opennlp/summarization/lexicalchaining/LexChainingKeywordExtractorTest.java b/summarizer/src/test/java/opennlp/summarization/lexicalchaining/LexChainingKeywordExtractorTest.java
index 181dc96..24cac18 100644
--- a/summarizer/src/test/java/opennlp/summarization/lexicalchaining/LexChainingKeywordExtractorTest.java
+++ b/summarizer/src/test/java/opennlp/summarization/lexicalchaining/LexChainingKeywordExtractorTest.java
@@ -1,59 +1,59 @@
/*
- * 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.
-*/
+ * 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 opennlp.summarization.lexicalchaining;
import java.util.List;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import opennlp.summarization.Sentence;
import opennlp.summarization.preprocess.DefaultDocProcessor;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-
-public class LexChainingKeywordExtractorTest {
-
- private static final String article =
- "US President Barack Obama has welcomed an agreement between the US and Russia under which Syria's chemical weapons must be destroyed or removed by mid-2014 as an \"important step\"."
- + "But a White House statement cautioned that the US expected Syria to live up to its public commitments. "
- + "The US-Russian framework document stipulates that Syria must provide details of its stockpile within a week. "
- + "If Syria fails to comply, the deal could be enforced by a UN resolution. "
- + "China, France, the UK, the UN and Nato have all expressed satisfaction at the agreement. "
- + "In Beijing, Foreign Minister Wang Yi said on Sunday that China welcomes the general agreement between the US and Russia.";
-
- private static DefaultDocProcessor dp;
- private static LexicalChainingSummarizer lcs;
-
- @BeforeClass
- public static void initEnv() throws Exception {
- dp = new DefaultDocProcessor(LexChainingKeywordExtractorTest.class.getResourceAsStream("/en-sent.bin"));
- lcs = new LexicalChainingSummarizer(dp, LexChainingKeywordExtractorTest.class.getResourceAsStream("/en-pos-maxent.bin"));
- }
-
- @Test
- public void testGetKeywords() {
- List<Sentence> sent = dp.getSentencesFromStr(article);
- List<LexicalChain> vh = lcs.buildLexicalChains(article, sent);
- LexChainingKeywordExtractor ke = new LexChainingKeywordExtractor();
- List<String> keywords = ke.getKeywords(vh, 5);
- assertNotNull(keywords);
- assertFalse(keywords.isEmpty());
- }
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+class LexChainingKeywordExtractorTest {
+
+ private static final String article =
+ "US President Barack Obama has welcomed an agreement between the US and Russia under which Syria's chemical weapons must be destroyed or removed by mid-2014 as an \"important step\"."
+ + "But a White House statement cautioned that the US expected Syria to live up to its public commitments. "
+ + "The US-Russian framework document stipulates that Syria must provide details of its stockpile within a week. "
+ + "If Syria fails to comply, the deal could be enforced by a UN resolution. "
+ + "China, France, the UK, the UN and Nato have all expressed satisfaction at the agreement. "
+ + "In Beijing, Foreign Minister Wang Yi said on Sunday that China welcomes the general agreement between the US and Russia.";
+
+ private static DefaultDocProcessor dp;
+ private static LexicalChainingSummarizer lcs;
+
+ @BeforeAll
+ static void initEnv() throws Exception {
+ dp = new DefaultDocProcessor(LexChainingKeywordExtractorTest.class.getResourceAsStream("/en-sent.bin"));
+ lcs = new LexicalChainingSummarizer(dp, LexChainingKeywordExtractorTest.class.getResourceAsStream("/en-pos-maxent.bin"));
+ }
+
+ @Test
+ void testGetKeywords() {
+ List<Sentence> sent = dp.getSentencesFromStr(article);
+ List<LexicalChain> vh = lcs.buildLexicalChains(article, sent);
+ LexChainingKeywordExtractor ke = new LexChainingKeywordExtractor();
+ List<String> keywords = ke.getKeywords(vh, 5);
+ assertNotNull(keywords);
+ assertFalse(keywords.isEmpty());
+ }
}
diff --git a/summarizer/src/test/java/opennlp/summarization/preprocess/DocProcessorTest.java b/summarizer/src/test/java/opennlp/summarization/preprocess/DocProcessorTest.java
index 812fa6e..5b8d1df 100644
--- a/summarizer/src/test/java/opennlp/summarization/preprocess/DocProcessorTest.java
+++ b/summarizer/src/test/java/opennlp/summarization/preprocess/DocProcessorTest.java
@@ -20,28 +20,28 @@ package opennlp.summarization.preprocess;
import java.util.List;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import opennlp.summarization.Sentence;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-public class DocProcessorTest {
+class DocProcessorTest {
private static DefaultDocProcessor dp;
- @BeforeClass
- public static void initEnv() throws Exception {
+ @BeforeAll
+ static void initEnv() throws Exception {
dp = new DefaultDocProcessor(DocProcessorTest.class.getResourceAsStream("/en-sent.bin"));
}
@Test
- public void testGetSentencesFromStr() {
+ void testGetSentencesFromStr() {
String sent = "This is a sentence, with some punctuations; to test if the sentence breaker can handle it! Is every thing working OK ? Yes.";
List<Sentence> doc = dp.getSentencesFromStr(sent);
//dp.docToString(fileName);
- assertEquals(doc.size(),3);
+ assertEquals(doc.size(), 3);
}
}
diff --git a/tagging-server/pom.xml b/tagging-server/pom.xml
index 97f8858..7dd01ea 100644
--- a/tagging-server/pom.xml
+++ b/tagging-server/pom.xml
@@ -77,9 +77,20 @@
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/tf-ner-poc/pom.xml b/tf-ner-poc/pom.xml
index a409796..4725965 100644
--- a/tf-ner-poc/pom.xml
+++ b/tf-ner-poc/pom.xml
@@ -31,9 +31,20 @@
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/tf-ner-poc/src/test/java/org/apache/opennlp/namefinder/FeedDictionaryTest.java b/tf-ner-poc/src/test/java/org/apache/opennlp/namefinder/FeedDictionaryTest.java
index 5efa709..835ec02 100644
--- a/tf-ner-poc/src/test/java/org/apache/opennlp/namefinder/FeedDictionaryTest.java
+++ b/tf-ner-poc/src/test/java/org/apache/opennlp/namefinder/FeedDictionaryTest.java
@@ -1,7 +1,7 @@
package org.apache.opennlp.namefinder;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.util.Arrays;
@@ -9,18 +9,18 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-public class FeedDictionaryTest {
+class FeedDictionaryTest {
private static WordIndexer indexer;
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
try (InputStream words = new GZIPInputStream(FeedDictionaryTest.class.getResourceAsStream("/words.txt.gz"));
InputStream chars = new GZIPInputStream(FeedDictionaryTest.class.getResourceAsStream("/chars.txt.gz"))) {
-
+
indexer = new WordIndexer(words, chars);
} catch (Exception ex) {
indexer = null;
@@ -29,18 +29,18 @@ public class FeedDictionaryTest {
}
@Test
- public void testToTokenIds() {
+ void testToTokenIds() {
String text1 = "Stormy Cars ' friend says she also plans to sue Michael Cohen .";
TokenIds oneSentence = indexer.toTokenIds(text1.split("\\s+"));
assertNotNull(oneSentence);
- assertEquals("Expect 13 tokenIds", 13, oneSentence.getWordIds()[0].length);
+ assertEquals(13, oneSentence.getWordIds()[0].length, "Expect 13 tokenIds");
String[] text2 = new String[] {"I wish I was born in Copenhagen Denmark",
- "Donald Trump died on his way to Tivoli Gardens in Denmark ."};
+ "Donald Trump died on his way to Tivoli Gardens in Denmark ."};
List<String[]> collect = Arrays.stream(text2).map(s -> s.split("\\s+")).collect(Collectors.toList());
TokenIds twoSentences = indexer.toTokenIds(collect.toArray(new String[2][]));
assertNotNull(twoSentences);
- assertEquals("Expect 8 tokenIds", 8, twoSentences.getWordIds()[0].length);
- assertEquals("Expect 12 tokenIds", 12, twoSentences.getWordIds()[1].length);
+ assertEquals(8, twoSentences.getWordIds()[0].length, "Expect 8 tokenIds");
+ assertEquals(12, twoSentences.getWordIds()[1].length, "Expect 12 tokenIds");
}
}
diff --git a/tf-ner-poc/src/test/java/org/apache/opennlp/namefinder/PredictTest.java b/tf-ner-poc/src/test/java/org/apache/opennlp/namefinder/PredictTest.java
index aa7097b..8b02f6d 100644
--- a/tf-ner-poc/src/test/java/org/apache/opennlp/namefinder/PredictTest.java
+++ b/tf-ner-poc/src/test/java/org/apache/opennlp/namefinder/PredictTest.java
@@ -1,20 +1,20 @@
package org.apache.opennlp.namefinder;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import opennlp.tools.util.Span;
import java.io.IOException;
import java.nio.file.Path;
-public class PredictTest {
+class PredictTest {
- @Test @Ignore
- // TODO This test is not platform neutral and, for instance, fails with:
- // "Cannot find TensorFlow native library for OS: darwin, architecture: aarch64"
- // We need JUnit 5 in the sandbox to circumvent this, so it can be run in supported environments
- public void testFindTokens() throws IOException {
+ @Test
+ @Disabled // TODO This test is not platform neutral and, for instance, fails with
+ // "Cannot find TensorFlow native library for OS: darwin, architecture: aarch64"
+ // We need JUnit 5 in the sandbox to circumvent this, so it can be run in supported environments
+ void testFindTokens() throws IOException {
// can be changed to File or InputStream
String words = PredictTest.class.getResource("/words.txt.gz").getPath();
@@ -29,7 +29,7 @@ public class PredictTest {
String[] tokens = "Stormy Cars ' friend says she also plans to sue Michael Cohen .".split("\\s+");
Span[] pred = tagger.find(tokens);
- for (int i=0; i<tokens.length; i++) {
+ for (int i = 0; i < tokens.length; i++) {
System.out.print(tokens[i] + "/" + pred[i] + " ");
}
System.out.println();
diff --git a/tf-ner-poc/src/test/java/org/apache/opennlp/namefinder/WordIndexerTest.java b/tf-ner-poc/src/test/java/org/apache/opennlp/namefinder/WordIndexerTest.java
index 184367f..ca612b5 100644
--- a/tf-ner-poc/src/test/java/org/apache/opennlp/namefinder/WordIndexerTest.java
+++ b/tf-ner-poc/src/test/java/org/apache/opennlp/namefinder/WordIndexerTest.java
@@ -6,19 +6,19 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
-public class WordIndexerTest {
+class WordIndexerTest {
private static WordIndexer indexer;
- @BeforeClass
- public static void beforeClass() {
+ @BeforeAll
+ static void beforeClass() {
try (InputStream words = new GZIPInputStream(WordIndexerTest.class.getResourceAsStream("/words.txt.gz"));
InputStream chars = new GZIPInputStream(WordIndexerTest.class.getResourceAsStream("/chars.txt.gz"))) {
indexer = new WordIndexer(words, chars);
@@ -29,11 +29,11 @@ public class WordIndexerTest {
}
@Test
- public void testToTokenIdsWithOneSentence() {
+ void testToTokenIdsWithOneSentence() {
String text = "Stormy Cars ' friend says she also plans to sue Michael Cohen .";
TokenIds ids = indexer.toTokenIds(text.split("\\s+"));
- assertEquals("Expect 13 tokenIds", 13, ids.getWordIds()[0].length);
+ assertEquals(13, ids.getWordIds()[0].length, "Expect 13 tokenIds");
assertArrayEquals(new int[] {7, 30, 34, 80, 42, 3}, ids.getCharIds()[0][0]);
assertArrayEquals(new int[] {51, 41, 80, 54}, ids.getCharIds()[0][1]);
@@ -67,10 +67,10 @@ public class WordIndexerTest {
}
@Test
- public void testToTokenIdsWithTwoSentences() {
+ void testToTokenIdsWithTwoSentences() {
String[] text = new String[] {"I wish I was born in Copenhagen Denmark",
- "Donald Trump died on his way to Tivoli Gardens in Denmark ."};
+ "Donald Trump died on his way to Tivoli Gardens in Denmark ."};
List<String[]> collect = Arrays.stream(text).map(s -> s.split("\\s+")).collect(Collectors.toList());
@@ -124,5 +124,5 @@ public class WordIndexerTest {
// assertEquals(7420, ids.getWordIds()[1][10]);
assertEquals(2684, ids.getWordIds()[1][11]);
}
-
+
}
diff --git a/wikinews-importer/pom.xml b/wikinews-importer/pom.xml
index 4722d36..108c93c 100644
--- a/wikinews-importer/pom.xml
+++ b/wikinews-importer/pom.xml
@@ -62,11 +62,22 @@
<version>${uimaj.version}</version>
<scope>compile</scope>
</dependency>
-
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>