Skip to content

Commit

Permalink
OPENNLP-1589 - Adds Cache Printing by Martin
Browse files Browse the repository at this point in the history
  • Loading branch information
rzo1 committed Jul 4, 2024
1 parent 9bac8a7 commit 6123b8c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 6123b8c

Please sign in to comment.