You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by co...@apache.org on 2012/05/20 21:26:23 UTC

svn commit: r1340809 - in /opennlp/trunk/opennlp-tools/src: main/java/opennlp/tools/cmdline/postag/ main/java/opennlp/tools/postag/ test/java/opennlp/tools/postag/

Author: colen
Date: Sun May 20 19:26:22 2012
New Revision: 1340809

URL: http://svn.apache.org/viewvc?rev=1340809&view=rev
Log:
OPENNLP-309 Replaced POSDictionary reference by the TagDictionary interface wherever possible.

Modified:
    opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTrainerTool.java
    opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/DefaultPOSSequenceValidator.java
    opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
    opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerCrossValidator.java
    opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerFactory.java
    opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java
    opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/DummyPOSTaggerFactory.java
    opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/POSTaggerFactoryTest.java

Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTrainerTool.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTrainerTool.java?rev=1340809&r1=1340808&r2=1340809&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTrainerTool.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTrainerTool.java Sun May 20 19:26:22 2012
@@ -33,6 +33,7 @@ import opennlp.tools.postag.POSModel;
 import opennlp.tools.postag.POSSample;
 import opennlp.tools.postag.POSTaggerFactory;
 import opennlp.tools.postag.POSTaggerME;
+import opennlp.tools.postag.TagDictionary;
 import opennlp.tools.util.InvalidFormatException;
 import opennlp.tools.util.TrainingParameters;
 import opennlp.tools.util.model.ModelType;
@@ -94,8 +95,8 @@ public final class POSTaggerTrainerTool
 
     if (params.getDict() != null) {
       try {
-        postaggerFactory.setPOSDictionary(postaggerFactory
-            .createPOSDictionary(params.getDict()));
+        postaggerFactory.setTagDictionary(postaggerFactory
+            .createTagDictionary(params.getDict()));
       } catch (IOException e) {
         throw new TerminateToolException(-1,
             "IO error while loading POS Dictionary: " + e.getMessage());
@@ -104,13 +105,13 @@ public final class POSTaggerTrainerTool
 
     if (params.getTagDictCutoff() != null) {
       try {
-        POSDictionary dict = postaggerFactory.getPOSDictionary();
+        TagDictionary dict = postaggerFactory.getTagDictionary();
         if (dict == null) {
-          dict = postaggerFactory.createEmptyPOSDictionary();
-          postaggerFactory.setPOSDictionary(dict);
+          dict = postaggerFactory.createEmptyTagDictionary();
+          postaggerFactory.setTagDictionary(dict);
         }
         if (dict instanceof MutableTagDictionary) {
-          POSTaggerME.populatePOSDictionary(sampleStream, dict,
+          POSTaggerME.populatePOSDictionary(sampleStream, (MutableTagDictionary)dict,
               params.getTagDictCutoff());
         } else {
           throw new IllegalArgumentException(

Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/DefaultPOSSequenceValidator.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/DefaultPOSSequenceValidator.java?rev=1340809&r1=1340808&r2=1340809&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/DefaultPOSSequenceValidator.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/DefaultPOSSequenceValidator.java Sun May 20 19:26:22 2012
@@ -23,9 +23,9 @@ import opennlp.tools.util.SequenceValida
 
 public class DefaultPOSSequenceValidator implements SequenceValidator<String> {
 
-  private POSDictionary tagDictionary;
+  private TagDictionary tagDictionary;
 
-  public DefaultPOSSequenceValidator(POSDictionary tagDictionary) {
+  public DefaultPOSSequenceValidator(TagDictionary tagDictionary) {
     this.tagDictionary = tagDictionary;
   }
 

Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java?rev=1340809&r1=1340808&r2=1340809&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java Sun May 20 19:26:22 2012
@@ -111,9 +111,9 @@ public final class POSModel extends Base
    *
    * @return tag dictionary or null if not used
    */
-  public POSDictionary getTagDictionary() {
+  public TagDictionary getTagDictionary() {
     if(getFactory() != null)
-      return getFactory().getPOSDictionary();
+      return getFactory().getTagDictionary();
     return null;
   }
   

Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerCrossValidator.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerCrossValidator.java?rev=1340809&r1=1340808&r2=1340809&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerCrossValidator.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerCrossValidator.java Sun May 20 19:26:22 2012
@@ -175,22 +175,22 @@ public class POSTaggerCrossValidator {
       }
       
       if (this.tagDictionaryFile != null
-          && this.factory.getPOSDictionary() == null) {
-        this.factory.setPOSDictionary(this.factory
-            .createPOSDictionary(tagDictionaryFile));
+          && this.factory.getTagDictionary() == null) {
+        this.factory.setTagDictionary(this.factory
+            .createTagDictionary(tagDictionaryFile));
       }
       if (this.tagdicCutoff != null) {
-        POSDictionary dict = this.factory.getPOSDictionary();
+        TagDictionary dict = this.factory.getTagDictionary();
         if (dict == null) {
-          dict = this.factory.createEmptyPOSDictionary();
-          this.factory.setPOSDictionary(dict);
+          dict = this.factory.createEmptyTagDictionary();
+          this.factory.setTagDictionary(dict);
         }
         if (dict instanceof MutableTagDictionary) {
-          POSTaggerME.populatePOSDictionary(trainingSampleStream, dict,
+          POSTaggerME.populatePOSDictionary(trainingSampleStream, (MutableTagDictionary)dict,
               this.tagdicCutoff);
         } else {
           throw new IllegalArgumentException(
-              "Can't extend a POSDictionary that does not implement MutableTagDictionary.");
+              "Can't extend a TagDictionary that does not implement MutableTagDictionary.");
         }
         trainingSampleStream.reset();
       }
@@ -205,7 +205,7 @@ public class POSTaggerCrossValidator {
       wordAccuracy.add(evaluator.getWordAccuracy(), evaluator.getWordCount());
 
       if (this.tagdicCutoff != null) {
-        this.factory.setPOSDictionary(null);
+        this.factory.setTagDictionary(null);
       }
 
     }
@@ -237,7 +237,7 @@ public class POSTaggerCrossValidator {
     return params;
   }
   
-  private static POSTaggerFactory create(Dictionary ngram, POSDictionary pos) {
+  private static POSTaggerFactory create(Dictionary ngram, TagDictionary pos) {
     return new POSTaggerFactory(ngram, pos);
   }
 }

Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerFactory.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerFactory.java?rev=1340809&r1=1340808&r2=1340809&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerFactory.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerFactory.java Sun May 20 19:26:22 2012
@@ -47,7 +47,7 @@ public class POSTaggerFactory extends Ba
   private static final String NGRAM_DICTIONARY_ENTRY_NAME = "ngram.dictionary";
 
   protected Dictionary ngramDictionary;
-  protected POSDictionary posDictionary;
+  protected TagDictionary posDictionary;
 
   /**
    * Creates a {@link POSTaggerFactory} that provides the default implementation
@@ -78,7 +78,7 @@ public class POSTaggerFactory extends Ba
    * @param posDictionary
    */
   public POSTaggerFactory(Dictionary ngramDictionary,
-      POSDictionary posDictionary) {
+      TagDictionary posDictionary) {
     this.ngramDictionary = ngramDictionary;
     this.posDictionary = posDictionary;
   }
@@ -105,17 +105,17 @@ public class POSTaggerFactory extends Ba
     return artifactMap;
   }
 
-  public POSDictionary createPOSDictionary(File dictionary)
+  public TagDictionary createTagDictionary(File dictionary)
       throws InvalidFormatException, FileNotFoundException, IOException {
-    return createPOSDictionary(new FileInputStream(dictionary));
+    return createTagDictionary(new FileInputStream(dictionary));
   }
 
-  public POSDictionary createPOSDictionary(InputStream in)
+  public TagDictionary createTagDictionary(InputStream in)
       throws InvalidFormatException, IOException {
     return POSDictionary.create(in);
   }
 
-  public void setPOSDictionary(POSDictionary dictionary) {
+  public void setTagDictionary(TagDictionary dictionary) {
     if (artifactProvider != null) {
       throw new IllegalStateException(
           "Can not set tag dictionary while using artifact provider.");
@@ -123,7 +123,7 @@ public class POSTaggerFactory extends Ba
     this.posDictionary = dictionary;
   }
 
-  public POSDictionary getPOSDictionary() {
+  public TagDictionary getTagDictionary() {
     if(this.posDictionary == null && artifactProvider != null)
       this.posDictionary = artifactProvider.getArtifact(TAG_DICTIONARY_ENTRY_NAME);
     return this.posDictionary;
@@ -152,7 +152,7 @@ public class POSTaggerFactory extends Ba
   }
 
   public SequenceValidator<String> getSequenceValidator() {
-    return new DefaultPOSSequenceValidator(getPOSDictionary());
+    return new DefaultPOSSequenceValidator(getTagDictionary());
   }
   
   static class POSDictionarySerializer implements ArtifactSerializer<POSDictionary> {
@@ -226,7 +226,7 @@ public class POSTaggerFactory extends Ba
   }
   
   public static POSTaggerFactory create(String subclassName,
-      Dictionary ngramDictionary, POSDictionary posDictionary)
+      Dictionary ngramDictionary, TagDictionary posDictionary)
       throws InvalidFormatException {
     if (subclassName == null) {
       // will create the default factory
@@ -238,19 +238,19 @@ public class POSTaggerFactory extends Ba
       try {
         Constructor<?> constructor = null;
         constructor = factoryClass.getConstructor(Dictionary.class,
-            POSDictionary.class);
+            TagDictionary.class);
         theFactory = (POSTaggerFactory) constructor.newInstance(
             ngramDictionary, posDictionary);
       } catch (NoSuchMethodException e) {
         String msg = "Could not instantiate the "
             + subclassName
-            + ". The mandatory constructor (Dictionary, POSDictionary) is missing.";
+            + ". The mandatory constructor (Dictionary, TagDictionary) is missing.";
         System.err.println(msg);
         throw new IllegalArgumentException(msg);
       } catch (Exception e) {
         String msg = "Could not instantiate the "
             + subclassName
-            + ". The constructor (Dictionary, POSDictionary) throw an exception.";
+            + ". The constructor (Dictionary, TagDictionary) throw an exception.";
         System.err.println(msg);
         e.printStackTrace();
         throw new InvalidFormatException(msg);
@@ -259,7 +259,7 @@ public class POSTaggerFactory extends Ba
     return theFactory;
   }
 
-  public POSDictionary createEmptyPOSDictionary() {
+  public TagDictionary createEmptyTagDictionary() {
     this.posDictionary = new POSDictionary(true);
     return this.posDictionary;
   }

Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java?rev=1340809&r1=1340808&r2=1340809&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java (original)
+++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java Sun May 20 19:26:22 2012
@@ -96,7 +96,7 @@ public class POSTaggerME implements POST
     POSTaggerFactory factory = model.getFactory();
     posModel = model.getPosModel();
     contextGen = factory.getPOSContextGenerator(beamSize);
-    tagDictionary = factory.getPOSDictionary();
+    tagDictionary = factory.getTagDictionary();
     size = beamSize;
     beam = new BeamSearch<String>(size, contextGen, posModel,
         sequenceValidator, cacheSize);
@@ -113,7 +113,7 @@ public class POSTaggerME implements POST
     POSTaggerFactory factory = model.getFactory();
     posModel = model.getPosModel();
     contextGen = factory.getPOSContextGenerator(beamSize);
-    tagDictionary = factory.getPOSDictionary();
+    tagDictionary = factory.getTagDictionary();
     size = beamSize;
     beam = new BeamSearch<String>(size, contextGen, posModel,
         factory.getSequenceValidator(), cacheSize);

Modified: opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/DummyPOSTaggerFactory.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/DummyPOSTaggerFactory.java?rev=1340809&r1=1340808&r2=1340809&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/DummyPOSTaggerFactory.java (original)
+++ opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/DummyPOSTaggerFactory.java Sun May 20 19:26:22 2012
@@ -49,8 +49,9 @@ public class DummyPOSTaggerFactory exten
     return new DummyPOSSequenceValidator();
   }
   
-  public POSDictionary getPOSDictionary() {
-    return (POSDictionary) artifactProvider.getArtifact(DUMMY_POSDICT);
+  @Override
+  public DummyPOSDictionary getTagDictionary() {
+    return (DummyPOSDictionary) artifactProvider.getArtifact(DUMMY_POSDICT);
   }
   
   @Override

Modified: opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/POSTaggerFactoryTest.java
URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/POSTaggerFactoryTest.java?rev=1340809&r1=1340808&r2=1340809&view=diff
==============================================================================
--- opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/POSTaggerFactoryTest.java (original)
+++ opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/postag/POSTaggerFactoryTest.java Sun May 20 19:26:22 2012
@@ -67,7 +67,7 @@ public class POSTaggerFactoryTest {
         new DummyPOSTaggerFactory(dic, posDict));
 
     POSTaggerFactory factory = posModel.getFactory();
-    assertTrue(factory.getPOSDictionary() instanceof DummyPOSDictionary);
+    assertTrue(factory.getTagDictionary() instanceof DummyPOSDictionary);
     assertTrue(factory.getPOSContextGenerator() instanceof DummyPOSContextGenerator);
     assertTrue(factory.getSequenceValidator() instanceof DummyPOSSequenceValidator);
 
@@ -78,7 +78,7 @@ public class POSTaggerFactoryTest {
     POSModel fromSerialized = new POSModel(in);
 
     factory = fromSerialized.getFactory();
-    assertTrue(factory.getPOSDictionary() instanceof DummyPOSDictionary);
+    assertTrue(factory.getTagDictionary() instanceof DummyPOSDictionary);
     assertTrue(factory.getPOSContextGenerator() instanceof DummyPOSContextGenerator);
     assertTrue(factory.getSequenceValidator() instanceof DummyPOSSequenceValidator);
     assertTrue(factory.getDictionary() instanceof Dictionary);
@@ -94,7 +94,7 @@ public class POSTaggerFactoryTest {
         new POSTaggerFactory(dic, posDict));
 
     POSTaggerFactory factory = posModel.getFactory();
-    assertTrue(factory.getPOSDictionary() instanceof POSDictionary);
+    assertTrue(factory.getTagDictionary() instanceof POSDictionary);
     assertTrue(factory.getPOSContextGenerator() instanceof POSContextGenerator);
     assertTrue(factory.getSequenceValidator() instanceof DefaultPOSSequenceValidator);
     assertTrue(factory.getDictionary() instanceof Dictionary);
@@ -106,7 +106,7 @@ public class POSTaggerFactoryTest {
     POSModel fromSerialized = new POSModel(in);
 
     factory = fromSerialized.getFactory();
-    assertTrue(factory.getPOSDictionary() instanceof POSDictionary);
+    assertTrue(factory.getTagDictionary() instanceof POSDictionary);
     assertTrue(factory.getPOSContextGenerator() instanceof POSContextGenerator);
     assertTrue(factory.getSequenceValidator() instanceof DefaultPOSSequenceValidator);
     assertTrue(factory.getDictionary() instanceof Dictionary);