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 2015/11/04 15:34:24 UTC
svn commit: r1712553 -
/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderFactory.java
Author: joern
Date: Wed Nov 4 14:34:24 2015
New Revision: 1712553
URL: http://svn.apache.org/viewvc?rev=1712553&view=rev
Log:
OPENNLP-822 Fixed a bug which prevented custom configuration from being included in the model.
Modified:
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderFactory.java
Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderFactory.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderFactory.java?rev=1712553&r1=1712552&r2=1712553&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderFactory.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderFactory.java Wed Nov 4 14:34:24 2015
@@ -49,7 +49,6 @@ public class TokenNameFinderFactory exte
*/
public TokenNameFinderFactory() {
this.seqCodec = new BioCodec();
- featureGeneratorBytes = loadDefaultFeatureGeneratorBytes();
}
public TokenNameFinderFactory(byte[] featureGeneratorBytes, final Map<String, Object> resources,
@@ -61,10 +60,6 @@ public class TokenNameFinderFactory exte
this.featureGeneratorBytes = featureGeneratorBytes;
this.resources = resources;
this.seqCodec = seqCodec;
-
- if (this.featureGeneratorBytes == null) {
- this.featureGeneratorBytes = loadDefaultFeatureGeneratorBytes();
- }
}
private static byte[] loadDefaultFeatureGeneratorBytes() {
@@ -162,56 +157,50 @@ public class TokenNameFinderFactory exte
*
* @return the feature generator or null if there is no descriptor in the model
*/
- // TODO: During training time the resources need to be loaded from the resources map!
public AdaptiveFeatureGenerator createFeatureGenerators() {
- byte descriptorBytes[] = null;
if (featureGeneratorBytes == null && artifactProvider != null) {
- descriptorBytes = (byte[]) artifactProvider.getArtifact(
+ featureGeneratorBytes = (byte[]) artifactProvider.getArtifact(
TokenNameFinderModel.GENERATOR_DESCRIPTOR_ENTRY_NAME);
}
- else {
- descriptorBytes = featureGeneratorBytes;
+
+ if (featureGeneratorBytes == null) {
+ featureGeneratorBytes = loadDefaultFeatureGeneratorBytes();
}
- if (descriptorBytes != null) {
- InputStream descriptorIn = new ByteArrayInputStream(descriptorBytes);
+ InputStream descriptorIn = new ByteArrayInputStream(featureGeneratorBytes);
- AdaptiveFeatureGenerator generator = null;
- try {
- generator = GeneratorFactory.create(descriptorIn, new FeatureGeneratorResourceProvider() {
+ AdaptiveFeatureGenerator generator = null;
+ try {
+ generator = GeneratorFactory.create(descriptorIn, new FeatureGeneratorResourceProvider() {
- public Object getResource(String key) {
- if (artifactProvider != null) {
- return artifactProvider.getArtifact(key);
- }
- else {
- return resources.get(key);
- }
+ public Object getResource(String key) {
+ if (artifactProvider != null) {
+ return artifactProvider.getArtifact(key);
}
- });
- } catch (InvalidFormatException e) {
- // It is assumed that the creation of the feature generation does not
- // fail after it succeeded once during model loading.
-
- // But it might still be possible that such an exception is thrown,
- // in this case the caller should not be forced to handle the exception
- // and a Runtime Exception is thrown instead.
-
- // If the re-creation of the feature generation fails it is assumed
- // that this can only be caused by a programming mistake and therefore
- // throwing a Runtime Exception is reasonable
-
- throw new FeatureGeneratorCreationError(e);
- } catch (IOException e) {
- throw new IllegalStateException("Reading from mem cannot result in an I/O error", e);
- }
-
- return generator;
- }
- else {
- return null;
+ else {
+ return resources.get(key);
+ }
+ }
+ });
+ } catch (InvalidFormatException e) {
+ // It is assumed that the creation of the feature generation does not
+ // fail after it succeeded once during model loading.
+
+ // But it might still be possible that such an exception is thrown,
+ // in this case the caller should not be forced to handle the exception
+ // and a Runtime Exception is thrown instead.
+
+ // If the re-creation of the feature generation fails it is assumed
+ // that this can only be caused by a programming mistake and therefore
+ // throwing a Runtime Exception is reasonable
+
+ throw new FeatureGeneratorCreationError(e);
+ } catch (IOException e) {
+ throw new IllegalStateException("Reading from mem cannot result in an I/O error", e);
}
+
+ return generator;
}
public static SequenceCodec<String> instantiateSequenceCodec(