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/11/01 10:16:12 UTC

opennlp git commit: Remove deprecated training API

Repository: opennlp
Updated Branches:
  refs/heads/trunk 9f0d4794b -> a8224a8ce


Remove deprecated training API

The removed methods and class have never been released in the
opennlp.tools.ml package without being deprecated. Therefore
it should have a minimal impact on our users to remeove them
now. The reason they have been there in the first place is
that we still had internal usage of them.

See issue OPENNLP-875


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

Branch: refs/heads/trunk
Commit: a8224a8ce8648c0f0193abdbd5db4091244299e9
Parents: 9f0d479
Author: J�rn Kottmann <jo...@apache.org>
Authored: Tue Nov 1 11:10:49 2016 +0100
Committer: J�rn Kottmann <jo...@apache.org>
Committed: Tue Nov 1 11:10:49 2016 +0100

----------------------------------------------------------------------
 .../java/opennlp/tools/ml/TrainerFactory.java   | 106 -------------------
 .../java/opennlp/tools/ml/model/TrainUtil.java  |  80 --------------
 .../opennlp/tools/ml/TrainerFactoryTest.java    |   9 +-
 3 files changed, 7 insertions(+), 188 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/opennlp/blob/a8224a8c/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java b/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java
index 8f8a604..19c9a79 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java
@@ -53,28 +53,6 @@ public class TrainerFactory {
     BUILTIN_TRAINERS = Collections.unmodifiableMap(_trainers);
   }
 
-  @Deprecated
-  private static String getPluggableTrainerType(String className) {
-    try {
-      Class<?> trainerClass = Class.forName(className);
-      if(trainerClass != null) {
-
-        if (EventTrainer.class.isAssignableFrom(trainerClass)) {
-          return EventTrainer.EVENT_VALUE;
-        }
-        else if (EventModelSequenceTrainer.class.isAssignableFrom(trainerClass)) {
-          return EventModelSequenceTrainer.SEQUENCE_VALUE;
-        }
-        else if (SequenceTrainer.class.isAssignableFrom(trainerClass)) {
-          return SequenceTrainer.SEQUENCE_VALUE;
-        }
-      }
-    } catch (ClassNotFoundException e) {
-    }
-
-    return null;
-  }
-
   /**
    * Determines the trainer type based on the ALGORITHM_PARAM value.
    *
@@ -131,84 +109,6 @@ public class TrainerFactory {
     return null;
   }
 
-  /**
-   * @deprecated use getTrainerType instead!
-   */
-  @Deprecated
-  public static boolean isSupportEvent(Map<String, String> trainParams) {
-
-    String trainerType = trainParams.get(AbstractTrainer.TRAINER_TYPE_PARAM);
-
-    if (trainerType == null) {
-      String alogrithmValue = trainParams.get(AbstractTrainer.ALGORITHM_PARAM);
-      if (alogrithmValue != null) {
-        trainerType = getPluggableTrainerType(trainParams.get(AbstractTrainer.ALGORITHM_PARAM));
-      }
-    }
-
-    if (trainerType != null) {
-      return EventTrainer.EVENT_VALUE.equals(trainerType);
-    }
-
-    return true;
-  }
-
-  /**
-   * @deprecated use getTrainerType instead!
-   */
-  @Deprecated
-  public static boolean isSupportSequence(Map<String, String> trainParams) {
-    return isSupportEventModelSequenceTraining(trainParams);
-  }
-
-  /**
-   * @deprecated use getTrainerType instead!
-   */
-  @Deprecated
-  public static boolean isSupportEventModelSequenceTraining(Map<String, String> trainParams) {
-
-    String trainerType = trainParams.get(AbstractTrainer.TRAINER_TYPE_PARAM);
-
-    if (trainerType == null) {
-      String alogrithmValue = trainParams.get(AbstractTrainer.ALGORITHM_PARAM);
-      if (alogrithmValue != null) {
-        trainerType = getPluggableTrainerType(trainParams.get(AbstractTrainer.ALGORITHM_PARAM));
-      }
-    }
-
-    return EventModelSequenceTrainer.SEQUENCE_VALUE.equals(trainerType);
-  }
-
-  /**
-   * @deprecated use getTrainerType instead!
-   */
-  @Deprecated
-  public static boolean isSupportSequenceTraining(Map<String, String> trainParams) {
-    String trainerType = trainParams.get(AbstractTrainer.TRAINER_TYPE_PARAM);
-
-    if (trainerType == null) {
-      String alogrithmValue = trainParams.get(AbstractTrainer.ALGORITHM_PARAM);
-      if (alogrithmValue != null) {
-        trainerType = getPluggableTrainerType(trainParams.get(AbstractTrainer.ALGORITHM_PARAM));
-      }
-    }
-
-    return SequenceTrainer.SEQUENCE_VALUE.equals(trainerType);
-  }
-
-  // TODO: How to do the testing ?!
-  // is support event sequence ?
-  // is support sequence ?
-
-  /**
-   * @deprecated use getTrainerType instead!
-   */
-  @Deprecated
-  public static boolean isSequenceTraining(Map<String, String> trainParams) {
-    return SimplePerceptronSequenceTrainer.PERCEPTRON_SEQUENCE_VALUE
-        .equals(trainParams.get(AbstractTrainer.ALGORITHM_PARAM));
-  }
-
   public static SequenceTrainer getSequenceModelTrainer(Map<String, String> trainParams,
       Map<String, String> reportMap) {
     String trainerType = trainParams.get(AbstractTrainer.ALGORITHM_PARAM);
@@ -251,12 +151,6 @@ public class TrainerFactory {
     }
   }
 
-  @Deprecated
-  public static EventModelSequenceTrainer getSequenceTrainer(
-      Map<String, String> trainParams, Map<String, String> reportMap) {
-    return getEventModelSequenceTrainer(trainParams, reportMap);
-  }
-
   public static EventTrainer getEventTrainer(Map<String, String> trainParams,
       Map<String, String> reportMap) {
     String trainerType = trainParams.get(AbstractTrainer.ALGORITHM_PARAM);

http://git-wip-us.apache.org/repos/asf/opennlp/blob/a8224a8c/opennlp-tools/src/main/java/opennlp/tools/ml/model/TrainUtil.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/TrainUtil.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/TrainUtil.java
deleted file mode 100644
index f1b4cd3..0000000
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/TrainUtil.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.
- */
-
-package opennlp.tools.ml.model;
-
-import java.io.IOException;
-import java.util.Map;
-
-import opennlp.tools.ml.EventModelSequenceTrainer;
-import opennlp.tools.ml.EventTrainer;
-import opennlp.tools.ml.TrainerFactory;
-import opennlp.tools.util.ObjectStream;
-
-public class TrainUtil {
-
-  /**
-   * @deprecated Use {@link TrainerFactory#isValid(Map)} instead.
-   */
-  public static boolean isValid(Map<String, String> trainParams) {
-    return TrainerFactory.isValid(trainParams);
-  }
-
-  // TODO: Need a way to report results and settings back for inclusion in model ...
-
-  /**
-   * @deprecated Use {@link TrainerFactory#getEventTrainer(Map, Map)} to get an
-   *             {@link EventTrainer} instead.
-   */
-  public static MaxentModel train(ObjectStream<Event> events, Map<String, String> trainParams, Map<String, String> reportMap)
-      throws IOException {
-
-    if(!TrainerFactory.isSupportEvent(trainParams)) {
-      throw new IllegalArgumentException("EventTrain is not supported");
-    }
-    EventTrainer trainer = TrainerFactory.getEventTrainer(trainParams, reportMap);
-
-    return trainer.train(events);
-  }
-
-  /**
-   * Detects if the training algorithm requires sequence based feature
-   * generation or not.
-   *
-   * @deprecated Use {@link TrainerFactory#isSequenceTraining(Map)} instead.
-   */
-  public static boolean isSequenceTraining(Map<String, String> trainParams) {
-	return TrainerFactory.isSupportSequence(trainParams);
-  }
-
-  /**
-   * @deprecated Use {@link TrainerFactory#getSequenceTrainer(Map, Map)} to get an
-   *             {@link EventModelSequenceTrainer} instead.
-   */
-  public static MaxentModel train(SequenceStream events, Map<String, String> trainParams,
-      Map<String, String> reportMap) throws IOException {
-
-    if(!TrainerFactory.isSupportSequence(trainParams)) {
-      throw new IllegalArgumentException("EventTrain is not supported");
-    }
-    EventModelSequenceTrainer trainer = TrainerFactory.getEventModelSequenceTrainer(trainParams, reportMap);
-
-    return trainer.train(events);
-  }
-}

http://git-wip-us.apache.org/repos/asf/opennlp/blob/a8224a8c/opennlp-tools/src/test/java/opennlp/tools/ml/TrainerFactoryTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/ml/TrainerFactoryTest.java b/opennlp-tools/src/test/java/opennlp/tools/ml/TrainerFactoryTest.java
index ee2e790..47cb0d7 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/ml/TrainerFactoryTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/ml/TrainerFactoryTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertTrue;
 import opennlp.tools.ml.maxent.GIS;
 import opennlp.tools.ml.perceptron.SimplePerceptronSequenceTrainer;
 import opennlp.tools.util.TrainingParameters;
+import opennlp.tools.ml.TrainerFactory.TrainerType;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -66,7 +67,9 @@ public class TrainerFactoryTest {
     mlParams.put(AbstractTrainer.ALGORITHM_PARAM,
         SimplePerceptronSequenceTrainer.PERCEPTRON_SEQUENCE_VALUE);
 
-    assertTrue(TrainerFactory.isSequenceTraining(mlParams.getSettings()));
+    TrainerType trainerType = TrainerFactory.getTrainerType(mlParams.getSettings());
+
+    assertTrue(TrainerType.EVENT_MODEL_SEQUENCE_TRAINER.equals(trainerType));
   }
 
   @Test
@@ -74,7 +77,9 @@ public class TrainerFactoryTest {
     mlParams.put(AbstractTrainer.ALGORITHM_PARAM,
         GIS.MAXENT_VALUE);
 
-    assertFalse(TrainerFactory.isSequenceTraining(mlParams.getSettings()));
+    TrainerType trainerType = TrainerFactory.getTrainerType(mlParams.getSettings());
+
+    assertFalse(TrainerType.EVENT_MODEL_SEQUENCE_TRAINER.equals(trainerType));
   }
 
 }