This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch OPENNLP-1589
in repository https://gitbox.apache.org/repos/asf/opennlp.git


The following commit(s) were added to refs/heads/OPENNLP-1589 by this push:
     new 6123b8c1 OPENNLP-1589 - Adds Cache Printing by Martin
6123b8c1 is described below

commit 6123b8c1b49847c77ad6208f2e16a07848f6add3
Author: Richard Zowalla <[email protected]>
AuthorDate: Thu Jul 4 14:54:06 2024 +0200

    OPENNLP-1589 - Adds Cache Printing by Martin
---
 .../namefind/DefaultNameContextGenerator.java      |  5 ++++
 .../opennlp/tools/namefind/NameFinderMETest.java   | 28 ++++++++++++++++------
 2 files changed, 26 insertions(+), 7 deletions(-)

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 5e13f975..f07e9788 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 class DefaultNameContextGenerator implements 
NameContextGenerator {
 
     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 7038d664..95b3c64b 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.io.File;
 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 @@ public class NameFinderMETest {
     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 @@ public class NameFinderMETest {
     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 @@ public class NameFinderMETest {
     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 @@ public class NameFinderMETest {
     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 @@ public class NameFinderMETest {
     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 @@ public class NameFinderMETest {
     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 @@ public class NameFinderMETest {
     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
 

Reply via email to