You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2014/04/28 15:06:02 UTC
svn commit: r1590621 -
/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java
Author: joern
Date: Mon Apr 28 13:06:01 2014
New Revision: 1590621
URL: http://svn.apache.org/r1590621
Log:
OPENNLP-677 Now headrules serializer for 1.5.x models is mapped correctly
Modified:
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java
Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java?rev=1590621&r1=1590620&r2=1590621&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java Mon Apr 28 13:06:01 2014
@@ -69,6 +69,21 @@ public class ParserModel extends BaseMod
}
}
+ private static class HeadRulesSerializer implements
+ ArtifactSerializer<opennlp.tools.parser.lang.en.HeadRules> {
+
+ public opennlp.tools.parser.lang.en.HeadRules create(InputStream in)
+ throws IOException, InvalidFormatException {
+ return new opennlp.tools.parser.lang.en.HeadRules(new BufferedReader(
+ new InputStreamReader(in, "UTF-8")));
+ }
+
+ public void serialize(opennlp.tools.parser.lang.en.HeadRules artifact,
+ OutputStream out) throws IOException {
+ artifact.serialize(new OutputStreamWriter(out, "UTF-8"));
+ }
+ }
+
private static final String COMPONENT_NAME = "Parser";
private static final String BUILD_MODEL_ENTRY_NAME = "build.model";
@@ -154,6 +169,16 @@ public class ParserModel extends BaseMod
super.createArtifactSerializers(serializers);
+ // In 1.6.x the headrules artifact is serialized with the new API
+ // which uses the Serializeable interface
+ // This change is not backward compatible with the 1.5.x models.
+ // In order to laod 1.5.x model the English headrules serializer must be
+ // put on the serializer map.
+
+ if (getVersion().getMajor() == 1 && getVersion().getMinor() == 5) {
+ serializers.put("headrules", new HeadRulesSerializer());
+ }
+
serializers.put("postagger", new POSModelSerializer());
serializers.put("chunker", new ChunkerModelSerializer());
}