diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/DefaultNameContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/DefaultNameContextGenerator.java index 5e13f9756..f07e97887 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/DefaultNameContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/DefaultNameContextGenerator.java @@ -116,4 +116,9 @@ public String[] getContext(int index, String[] tokens, String[] preds, Object[] return features.toArray(new String[0]); } + + @Override + public String toString() { + return featureGenerators[0] .toString(); + } } diff --git a/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderMETest.java b/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderMETest.java index 7038d6645..95b3c64b3 100644 --- a/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderMETest.java +++ b/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderMETest.java @@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets; import java.util.Collections; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -54,6 +55,19 @@ public class NameFinderMETest { private static final String TYPE_OVERRIDE = "aType"; private static final String DEFAULT = "default"; + // SUT + private NameFinderME nameFinder; + + @AfterEach + public void tearDown() { + if (nameFinder != null) { + // print cache statistics + System.out.println(nameFinder.contextGenerator); + // clear instance for potential next test run + nameFinder = null; + } + } + @Test void testNameFinder() throws Exception { @@ -72,7 +86,7 @@ void testNameFinder() throws Exception { TokenNameFinderModel nameFinderModel = NameFinderME.train("eng", null, sampleStream, params, TokenNameFinderFactory.create(null, null, Collections.emptyMap(), new BioCodec())); - TokenNameFinder nameFinder = new NameFinderME(nameFinderModel); + nameFinder = new NameFinderME(nameFinderModel); // now test if it can detect the sample sentences @@ -130,7 +144,7 @@ void testNameFinderWithTypes() throws Exception { TokenNameFinderModel nameFinderModel = NameFinderME.train("eng", null, sampleStream, params, TokenNameFinderFactory.create(null, null, Collections.emptyMap(), new BioCodec())); - NameFinderME nameFinder = new NameFinderME(nameFinderModel); + nameFinder = new NameFinderME(nameFinderModel); // now test if it can detect the sample sentences @@ -174,7 +188,7 @@ void testOnlyWithNames() throws Exception { TokenNameFinderModel nameFinderModel = NameFinderME.train("eng", null, sampleStream, params, TokenNameFinderFactory.create(null, null, Collections.emptyMap(), new BioCodec())); - NameFinderME nameFinder = new NameFinderME(nameFinderModel); + nameFinder = new NameFinderME(nameFinderModel); // now test if it can detect the sample sentences @@ -204,7 +218,7 @@ void testOnlyWithNamesTypeOverride() throws Exception { TokenNameFinderModel nameFinderModel = NameFinderME.train("eng", TYPE_OVERRIDE, sampleStream, params, TokenNameFinderFactory.create(null, null, Collections.emptyMap(), new BioCodec())); - NameFinderME nameFinder = new NameFinderME(nameFinderModel); + nameFinder = new NameFinderME(nameFinderModel); // now test if it can detect the sample sentences @@ -239,7 +253,7 @@ void testOnlyWithNamesWithTypes() throws Exception { TokenNameFinderModel nameFinderModel = NameFinderME.train("eng", null, sampleStream, params, TokenNameFinderFactory.create(null, null, Collections.emptyMap(), new BioCodec())); - NameFinderME nameFinder = new NameFinderME(nameFinderModel); + nameFinder = new NameFinderME(nameFinderModel); // now test if it can detect the sample sentences @@ -275,7 +289,7 @@ void testOnlyWithEntitiesWithTypes() throws Exception { TokenNameFinderModel nameFinderModel = NameFinderME.train("eng", null, sampleStream, params, TokenNameFinderFactory.create(null, null, Collections.emptyMap(), new BioCodec())); - NameFinderME nameFinder = new NameFinderME(nameFinderModel); + nameFinder = new NameFinderME(nameFinderModel); // now test if it can detect the sample sentences @@ -326,7 +340,7 @@ void testNameFinderWithMultipleTypes() throws Exception { TokenNameFinderModel nameFinderModel = NameFinderME.train("eng", null, sampleStream, params, TokenNameFinderFactory.create(null, null, Collections.emptyMap(), new BioCodec())); - NameFinderME nameFinder = new NameFinderME(nameFinderModel); + nameFinder = new NameFinderME(nameFinderModel); // now test if it can detect the sample sentences