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/12/21 09:54:45 UTC
(opennlp) branch OPENNLP-1369-NPE-when-serializing-a-TokenNameFinder-model-trained-with-POSTaggerNameFeatureGeneratorFactory created (now f6adbff9)
This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a change to branch OPENNLP-1369-NPE-when-serializing-a-TokenNameFinder-model-trained-with-POSTaggerNameFeatureGeneratorFactory
in repository https://gitbox.apache.org/repos/asf/opennlp.git
at f6adbff9 OPENNLP-1369 NPE when serializing a TokenNameFinder model trained with POSTaggerNameFeatureGeneratorFactory - adds first reproducer to check if 1369 is broken => yes it is - confirms basic workaround is curing the issue, however this is not pretty.
This branch includes the following new commits:
new f6adbff9 OPENNLP-1369 NPE when serializing a TokenNameFinder model trained with POSTaggerNameFeatureGeneratorFactory - adds first reproducer to check if 1369 is broken => yes it is - confirms basic workaround is curing the issue, however this is not pretty.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(opennlp) 01/01: OPENNLP-1369 NPE when serializing a TokenNameFinder model trained with POSTaggerNameFeatureGeneratorFactory - adds first reproducer to check if 1369 is broken => yes it is - confirms basic workaround is curing the issue, however this is not pretty.
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a commit to branch OPENNLP-1369-NPE-when-serializing-a-TokenNameFinder-model-trained-with-POSTaggerNameFeatureGeneratorFactory
in repository https://gitbox.apache.org/repos/asf/opennlp.git
commit f6adbff931725d8f7b88e3606d0fea8f4eb11c00
Author: Martin Wiesner <ma...@hs-heilbronn.de>
AuthorDate: Thu Dec 21 10:54:36 2023 +0100
OPENNLP-1369 NPE when serializing a TokenNameFinder model trained with POSTaggerNameFeatureGeneratorFactory
- adds first reproducer to check if 1369 is broken => yes it is
- confirms basic workaround is curing the issue, however this is not pretty.
---
.../src/main/java/opennlp/tools/util/model/BaseModel.java | 5 +++++
.../java/opennlp/tools/namefind/TokenNameFinderModelTest.java | 8 ++++++--
.../test/resources/opennlp/tools/namefind/ner-pos-features.xml | 3 ++-
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java b/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java
index b9382670..e2409e95 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java
@@ -596,6 +596,11 @@ public abstract class BaseModel implements ArtifactProvider, Serializable {
zip.putNextEntry(new ZipEntry(name));
Object artifact = entry.getValue();
+ // TODO Discuss if this is the correct location to have this workaround in place
+ if ("generator.featuregen".equals(name) && artifact == null) {
+ // An old model format was detected, skipping the process for this entry, see: OPENNLP-1369
+ continue;
+ }
ArtifactSerializer serializer = getArtifactSerializer(name);
diff --git a/opennlp-tools/src/test/java/opennlp/tools/namefind/TokenNameFinderModelTest.java b/opennlp-tools/src/test/java/opennlp/tools/namefind/TokenNameFinderModelTest.java
index 1aa8837c..30a331ec 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/namefind/TokenNameFinderModelTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/namefind/TokenNameFinderModelTest.java
@@ -51,13 +51,17 @@ public class TokenNameFinderModelTest {
// create a resources folder
Path resourcesFolder = Files.createTempDirectory("resources").toAbsolutePath();
+ // TODO Restore old test and provide a separate one which does it with the pt-pos-perceptron.bin
// save a POS model there
POSModel posModel = POSTaggerMETest.trainPOSModel(ModelType.MAXENT);
- File posModelFile = new File(resourcesFolder.toFile(), "pos-model.bin");
+ File posModelFile = new File("pt-pos-perceptron.bin");
+ Files.copy(posModelFile.toPath(), resourcesFolder.resolve("pt-pos-perceptron.bin"));
- posModel.serialize(posModelFile);
+ // posModel.serialize(posModelFile);
Assertions.assertTrue(posModelFile.exists());
+ Assertions.assertTrue(resourcesFolder.resolve("pt-pos-perceptron.bin").toFile().exists());
+ // end TODO
// load feature generator xml bytes
InputStream fgInputStream = this.getClass().getResourceAsStream("ner-pos-features.xml");
diff --git a/opennlp-tools/src/test/resources/opennlp/tools/namefind/ner-pos-features.xml b/opennlp-tools/src/test/resources/opennlp/tools/namefind/ner-pos-features.xml
index c8b5887a..2ecb694d 100644
--- a/opennlp-tools/src/test/resources/opennlp/tools/namefind/ner-pos-features.xml
+++ b/opennlp-tools/src/test/resources/opennlp/tools/namefind/ner-pos-features.xml
@@ -30,7 +30,8 @@
<int name="prevLength">2</int>
<int name="nextLength">2</int>
<generator class="opennlp.tools.util.featuregen.POSTaggerNameFeatureGeneratorFactory">
- <str name="model">pos-model.bin</str>
+ <!-- FIXME Restore old state for TokenNameFinderModelTest -->
+ <str name="model">pt-pos-perceptron.bin</str>
</generator>
</generator>
<generator class="opennlp.tools.util.featuregen.PreviousMapFeatureGeneratorFactory"/>