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 2016/12/26 13:34:02 UTC

[08/50] [abbrv] opennlp git commit: Remove deprecated methods from Doccat

Remove deprecated methods from Doccat

See issue OPENNLP-885


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

Branch: refs/heads/889
Commit: bbc5a34a8968dc39abcd24bdbc50b69851c6caa5
Parents: 0806562
Author: J�rn Kottmann <jo...@apache.org>
Authored: Thu Dec 15 17:52:26 2016 +0100
Committer: J�rn Kottmann <jo...@apache.org>
Committed: Thu Dec 15 17:52:26 2016 +0100

----------------------------------------------------------------------
 .../java/opennlp/tools/doccat/DoccatModel.java  | 26 -------------
 .../tools/doccat/DocumentCategorizerME.java     | 40 --------------------
 .../opennlp/tools/doccat/DoccatFactoryTest.java |  2 +-
 .../tools/doccat/DocumentCategorizerMETest.java |  2 +-
 .../tools/doccat/DocumentCategorizerNBTest.java |  2 +-
 .../uima/doccat/DocumentCategorizerTrainer.java | 11 +++++-
 6 files changed, 12 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbc5a34a/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java b/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java
index e8c59fd..2bbaace 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java
@@ -45,25 +45,6 @@ public class DoccatModel extends BaseModel {
     checkArtifactMap();
   }
 
-  /**
-   * @deprecated Use
-   *             {@link #DoccatModel(String, MaxentModel, Map, DoccatFactory)}
-   *             instead and pass in a {@link DoccatFactory}
-   */
-  protected DoccatModel(String languageCode, MaxentModel doccatModel,
-      Map<String, String> manifestInfoEntries) {
-    this(languageCode, doccatModel, manifestInfoEntries, new DoccatFactory());
-  }
-
-  /**
-   * @deprecated Use
-   *             {@link #DoccatModel(String, MaxentModel, Map, DoccatFactory)}
-   *             instead and pass in a {@link DoccatFactory}
-   */
-  public DoccatModel(String languageCode, MaxentModel doccatModel) {
-    this(languageCode, doccatModel, null);
-  }
-
   public DoccatModel(InputStream in) throws IOException, InvalidFormatException {
     super(COMPONENT_NAME, in);
   }
@@ -94,13 +75,6 @@ public class DoccatModel extends BaseModel {
     return DoccatFactory.class;
   }
 
-  /**
-   * @deprecated Use {@link #getMaxentModel()} instead.
-   */
-  public MaxentModel getChunkerModel() {
-    return (MaxentModel) artifactMap.get(DOCCAT_MODEL_ENTRY_NAME);
-  }
-
   public MaxentModel getMaxentModel() {
     return (MaxentModel) artifactMap.get(DOCCAT_MODEL_ENTRY_NAME);
   }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbc5a34a/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java b/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java
index 6ba4e08..2c31345 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java
@@ -176,30 +176,6 @@ public class DocumentCategorizerME implements DocumentCategorizer {
     return model.getMaxentModel().getAllOutcomes(results);
   }
 
-  /**
-   * @deprecated Use
-   * {@link #train(String, ObjectStream, TrainingParameters, DoccatFactory)}
-   * instead.
-   */
-  public static DoccatModel train(String languageCode, ObjectStream<DocumentSample> samples,
-                                  TrainingParameters mlParams, FeatureGenerator... featureGenerators)
-      throws IOException {
-
-    if (featureGenerators.length == 0) {
-      featureGenerators = new FeatureGenerator[]{defaultFeatureGenerator};
-    }
-
-    Map<String, String> manifestInfoEntries = new HashMap<String, String>();
-
-    EventTrainer trainer = TrainerFactory.getEventTrainer(
-            mlParams.getSettings(), manifestInfoEntries);
-
-    MaxentModel model = trainer.train(
-        new DocumentCategorizerEventStream(samples, featureGenerators));
-
-    return new DoccatModel(languageCode, model, manifestInfoEntries);
-  }
-
   public static DoccatModel train(String languageCode, ObjectStream<DocumentSample> samples,
                                   TrainingParameters mlParams, DoccatFactory factory)
       throws IOException {
@@ -214,20 +190,4 @@ public class DocumentCategorizerME implements DocumentCategorizer {
 
     return new DoccatModel(languageCode, model, manifestInfoEntries, factory);
   }
-
-  /**
-   * Trains a doccat model with default feature generation.
-   *
-   * @param languageCode the language code
-   * @param samples      the samples
-   * @return the trained doccat model
-   * @throws IOException
-   * @throws ObjectStreamException
-   * @deprecated Use
-   * {@link #train(String, ObjectStream, TrainingParameters, DoccatFactory)}
-   * instead.
-   */
-  public static DoccatModel train(String languageCode, ObjectStream<DocumentSample> samples) throws IOException {
-    return train(languageCode, samples, ModelUtil.createDefaultTrainingParameters(), defaultFeatureGenerator);
-  }
 }

http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbc5a34a/opennlp-tools/src/test/java/opennlp/tools/doccat/DoccatFactoryTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/doccat/DoccatFactoryTest.java b/opennlp-tools/src/test/java/opennlp/tools/doccat/DoccatFactoryTest.java
index 786e708..8062762 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/doccat/DoccatFactoryTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/doccat/DoccatFactoryTest.java
@@ -49,7 +49,7 @@ public class DoccatFactoryTest {
 
   private static DoccatModel train() throws IOException {
     return DocumentCategorizerME.train("x-unspecified", createSampleStream(),
-        TrainingParameters.defaultParams());
+        TrainingParameters.defaultParams(), new DoccatFactory());
   }
 
   private static DoccatModel train(DoccatFactory factory) throws IOException {

http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbc5a34a/opennlp-tools/src/test/java/opennlp/tools/doccat/DocumentCategorizerMETest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/doccat/DocumentCategorizerMETest.java b/opennlp-tools/src/test/java/opennlp/tools/doccat/DocumentCategorizerMETest.java
index 523772a..673198a 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/doccat/DocumentCategorizerMETest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/doccat/DocumentCategorizerMETest.java
@@ -48,7 +48,7 @@ public class DocumentCategorizerMETest {
     params.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(0));
 
     DoccatModel model = DocumentCategorizerME.train("x-unspecified", samples,
-            params, new BagOfWordsFeatureGenerator());
+            params, new DoccatFactory());
 
     DocumentCategorizer doccat = new DocumentCategorizerME(model);
 

http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbc5a34a/opennlp-tools/src/test/java/opennlp/tools/doccat/DocumentCategorizerNBTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/doccat/DocumentCategorizerNBTest.java b/opennlp-tools/src/test/java/opennlp/tools/doccat/DocumentCategorizerNBTest.java
index a6e48de..67347de 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/doccat/DocumentCategorizerNBTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/doccat/DocumentCategorizerNBTest.java
@@ -48,7 +48,7 @@ public class DocumentCategorizerNBTest {
     params.put(AbstractTrainer.ALGORITHM_PARAM, NaiveBayesTrainer.NAIVE_BAYES_VALUE);
 
     DoccatModel model = DocumentCategorizerME.train("x-unspecified", samples,
-        params, new BagOfWordsFeatureGenerator());
+        params, new DoccatFactory());
 
     DocumentCategorizer doccat = new DocumentCategorizerME(model);
 

http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbc5a34a/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizerTrainer.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizerTrainer.java b/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizerTrainer.java
index 1c266ad..31c6392 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizerTrainer.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizerTrainer.java
@@ -22,11 +22,13 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
+import opennlp.tools.doccat.DoccatFactory;
 import opennlp.tools.doccat.DoccatModel;
 import opennlp.tools.doccat.DocumentCategorizerME;
 import opennlp.tools.doccat.DocumentSample;
 import opennlp.tools.ml.maxent.GIS;
 import opennlp.tools.util.ObjectStreamUtils;
+import opennlp.tools.util.TrainingParameters;
 import opennlp.uima.util.CasConsumerUtil;
 import opennlp.uima.util.OpennlpUtil;
 import opennlp.uima.util.UimaUtil;
@@ -130,7 +132,12 @@ public class DocumentCategorizerTrainer extends CasConsumer_ImplBase {
 
     GIS.PRINT_MESSAGES = false;
 
-    DoccatModel categoryModel = DocumentCategorizerME.train(language, ObjectStreamUtils.createObjectStream(documentSamples));
+    TrainingParameters params = new TrainingParameters();
+    params.put(TrainingParameters.ITERATIONS_PARAM, Integer.toString(100));
+    params.put(TrainingParameters.CUTOFF_PARAM, Integer.toString(0));
+
+    DoccatModel categoryModel = DocumentCategorizerME.train(language,
+            ObjectStreamUtils.createObjectStream(documentSamples), params, new DoccatFactory());
 
     File modelFile = new File(getUimaContextAdmin().getResourceManager()
         .getDataPath() + File.separatorChar + mModelName);
@@ -152,4 +159,4 @@ public class DocumentCategorizerTrainer extends CasConsumer_ImplBase {
     // dereference to allow garbage collection
     documentSamples = null;
   }
-}
\ No newline at end of file
+}