[ 
https://issues.apache.org/jira/browse/OPENNLP-1195?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16475550#comment-16475550
 ] 

ASF GitHub Bot commented on OPENNLP-1195:
-----------------------------------------

kojisekig closed pull request #313: OPENNLP-1195: move maxIndex method to 
AbstractEventTrainer
URL: https://github.com/apache/opennlp/pull/313
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java 
b/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java
index dc75ffe27..a54499943 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractEventTrainer.java
@@ -92,4 +92,12 @@ public final MaxentModel train(ObjectStream<Event> events) 
throws IOException {
     addToReport("Training-Eventhash", hses.calculateHashSum().toString(16));
     return train(indexer);
   }
+
+  public static int maxIndex(double[] values) {
+    int max = 0;
+    for (int i = 1; i < values.length; i++)
+      if (values[i] > values[max])
+        max = i;
+    return max;
+  }
 }
diff --git 
a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java
 
b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java
index 63c3244b5..8f3714af0 100644
--- 
a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java
+++ 
b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java
@@ -199,12 +199,4 @@ private double trainingStats(EvalParameters evalParams) {
     return trainingAccuracy;
   }
 
-
-  private int maxIndex(double[] values) {
-    int max = 0;
-    for (int i = 1; i < values.length; i++)
-      if (values[i] > values[max])
-        max = i;
-    return max;
-  }
 }
diff --git 
a/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PerceptronTrainer.java
 
b/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PerceptronTrainer.java
index b73eacaf7..4d91e6c58 100644
--- 
a/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PerceptronTrainer.java
+++ 
b/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PerceptronTrainer.java
@@ -398,15 +398,6 @@ private double trainingStats(EvalParameters evalParams) {
     return trainingAccuracy;
   }
 
-
-  private int maxIndex(double[] values) {
-    int max = 0;
-    for (int i = 1; i < values.length; i++)
-      if (values[i] > values[max])
-        max = i;
-    return max;
-  }
-
   private void displayIteration(int i) {
     if (i > 10 && (i % 10) != 0)
       return;
diff --git 
a/opennlp-tools/src/test/java/opennlp/tools/ml/AbstractEventTrainerTest.java 
b/opennlp-tools/src/test/java/opennlp/tools/ml/AbstractEventTrainerTest.java
new file mode 100644
index 000000000..8397dd320
--- /dev/null
+++ b/opennlp-tools/src/test/java/opennlp/tools/ml/AbstractEventTrainerTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class AbstractEventTrainerTest {
+
+  @Test
+  public void testMaxIndex() throws Exception {
+    Assert.assertEquals(0, AbstractEventTrainer.maxIndex(new double[]{0}));
+    Assert.assertEquals(0, AbstractEventTrainer.maxIndex(new double[]{0, 0, 
0}));
+    Assert.assertEquals(2, AbstractEventTrainer.maxIndex(new double[]{0, 1, 
2}));
+    Assert.assertEquals(1, AbstractEventTrainer.maxIndex(new double[]{100, 
200, 2}));
+    Assert.assertEquals(2, AbstractEventTrainer.maxIndex(new double[]{100, 
200, 300, -10, -20}));
+  }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> move maxIndex method to AbstractEventTrainer
> --------------------------------------------
>
>                 Key: OPENNLP-1195
>                 URL: https://issues.apache.org/jira/browse/OPENNLP-1195
>             Project: OpenNLP
>          Issue Type: Improvement
>    Affects Versions: 1.8.4
>            Reporter: Koji Sekiguchi
>            Assignee: Koji Sekiguchi
>            Priority: Trivial
>
> PerceptronTrainer and NaiveBayesTrainer have their own private maxIndex() 
> method and they are identical.
> Why don't we move it to their parent class?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to