opennlp-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject [2/2] opennlp git commit: OPENNLP-891: Making the TokenClassFeatureGenerator configurable.
Date Tue, 13 Dec 2016 23:46:30 GMT
OPENNLP-891: Making the TokenClassFeatureGenerator configurable.


Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo
Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/08065623
Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/08065623
Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/08065623

Branch: refs/heads/trunk
Commit: 080656237bb56d52ca97f4da4171b0ce1ec42e4a
Parents: d62cc41
Author: jzonthemtn <jeffrey@mtnfog.com>
Authored: Mon Dec 12 19:55:57 2016 -0500
Committer: Jörn Kottmann <joern@apache.org>
Committed: Wed Dec 14 00:42:24 2016 +0100

----------------------------------------------------------------------
 .../tools/util/featuregen/GeneratorFactory.java | 16 +++++++++++--
 .../featuregen/TokenClassFeatureGenerator.java  |  4 ++--
 .../util/featuregen/GeneratorFactoryTest.java   | 17 ++++++++++++++
 .../TestTokenClassFeatureGeneratorConfig.xml    | 24 ++++++++++++++++++++
 4 files changed, 57 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/opennlp/blob/08065623/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
index d943381..f6cf702 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
@@ -427,8 +427,20 @@ public class GeneratorFactory {
 
     public AdaptiveFeatureGenerator create(Element generatorElement,
         FeatureGeneratorResourceProvider resourceManager) {
-      // TODO: Make it configurable ...
-      return new TokenClassFeatureGenerator(true);
+
+      String attribute = generatorElement.getAttribute("wordAndClass");
+    	
+      // Default to true.
+      boolean generateWordAndClassFeature = true;
+      
+      if(attribute != "") {
+          // Anything other than "true" sets it to false.
+    	  if(!"true".equalsIgnoreCase(attribute)) {
+        	  generateWordAndClassFeature = false;
+          }
+      }
+    	
+      return new TokenClassFeatureGenerator(generateWordAndClassFeature);
     }
 
     static void register(Map<String, XmlFeatureGeneratorFactory> factoryMap) {

http://git-wip-us.apache.org/repos/asf/opennlp/blob/08065623/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/TokenClassFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/TokenClassFeatureGenerator.java
b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/TokenClassFeatureGenerator.java
index 1a810e0..4aad40c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/TokenClassFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/TokenClassFeatureGenerator.java
@@ -36,8 +36,8 @@ public class TokenClassFeatureGenerator extends FeatureGeneratorAdapter
{
     this(false);
   }
 
-  public TokenClassFeatureGenerator(boolean genearteWordAndClassFeature) {
-    this.generateWordAndClassFeature = genearteWordAndClassFeature;
+  public TokenClassFeatureGenerator(boolean generateWordAndClassFeature) {
+    this.generateWordAndClassFeature = generateWordAndClassFeature;
   }
 
   public void createFeatures(List<String> features, String[] tokens, int index, String[]
preds) {

http://git-wip-us.apache.org/repos/asf/opennlp/blob/08065623/opennlp-tools/src/test/java/opennlp/tools/util/featuregen/GeneratorFactoryTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/util/featuregen/GeneratorFactoryTest.java
b/opennlp-tools/src/test/java/opennlp/tools/util/featuregen/GeneratorFactoryTest.java
index b0a1500..9a28588 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/util/featuregen/GeneratorFactoryTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/util/featuregen/GeneratorFactoryTest.java
@@ -35,6 +35,23 @@ import opennlp.tools.util.model.ArtifactSerializer;
 import org.junit.Test;
 
 public class GeneratorFactoryTest {
+	
+  @Test
+  public void testCreationWithTokenClassFeatureGenerator() throws Exception {
+    InputStream generatorDescriptorIn = getClass().getResourceAsStream(
+        "/opennlp/tools/util/featuregen/TestTokenClassFeatureGeneratorConfig.xml");
+
+    // If this fails the generator descriptor could not be found
+    // at the expected location
+    assertNotNull(generatorDescriptorIn);
+
+    AggregatedFeatureGenerator aggregatedGenerator =
+      (AggregatedFeatureGenerator) GeneratorFactory.create(generatorDescriptorIn, null);
+
+    assertEquals(1, aggregatedGenerator.getGenerators().size());
+    assertEquals(TokenClassFeatureGenerator.class.getName(), aggregatedGenerator.getGenerators().iterator().next().getClass().getName());
+    
+  }
 
   @Test
   public void testCreationWihtSimpleDescriptor() throws Exception {

http://git-wip-us.apache.org/repos/asf/opennlp/blob/08065623/opennlp-tools/src/test/resources/opennlp/tools/util/featuregen/TestTokenClassFeatureGeneratorConfig.xml
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/resources/opennlp/tools/util/featuregen/TestTokenClassFeatureGeneratorConfig.xml
b/opennlp-tools/src/test/resources/opennlp/tools/util/featuregen/TestTokenClassFeatureGeneratorConfig.xml
new file mode 100644
index 0000000..e384a7e
--- /dev/null
+++ b/opennlp-tools/src/test/resources/opennlp/tools/util/featuregen/TestTokenClassFeatureGeneratorConfig.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements.  See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership.  The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License.  You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied.  See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+
+<generators>
+	<tokenclass wordAndClass="true"/>
+</generators>
\ No newline at end of file


Mime
View raw message