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 2011/08/27 20:57:39 UTC

svn commit: r1162418 - /incubator/opennlp/trunk/opennlp-maxent/src/test/java/opennlp/perceptron/PerceptronPrepAttachTest.java

Author: joern
Date: Sat Aug 27 18:57:39 2011
New Revision: 1162418

URL: http://svn.apache.org/viewvc?rev=1162418&view=rev
Log:
OPENNLP-200 Updated accuracy, moved readPpaFile to the top, and organized imports.

Modified:
    incubator/opennlp/trunk/opennlp-maxent/src/test/java/opennlp/perceptron/PerceptronPrepAttachTest.java

Modified: incubator/opennlp/trunk/opennlp-maxent/src/test/java/opennlp/perceptron/PerceptronPrepAttachTest.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/test/java/opennlp/perceptron/PerceptronPrepAttachTest.java?rev=1162418&r1=1162417&r2=1162418&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/test/java/opennlp/perceptron/PerceptronPrepAttachTest.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/test/java/opennlp/perceptron/PerceptronPrepAttachTest.java Sat Aug 27 18:57:39 2011
@@ -17,15 +17,43 @@
 
 package opennlp.perceptron;
 
-import opennlp.model.*;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
-import java.io.*;
-import java.util.*;
 import junit.framework.TestCase;
-
-// Test for perceptron training and use.
+import opennlp.model.AbstractModel;
+import opennlp.model.Event;
+import opennlp.model.EventStream;
+import opennlp.model.ListEventStream;
+import opennlp.model.TwoPassDataIndexer;
+
+/**
+ * Test for perceptron training and use with the ppa data.
+ */
 public class PerceptronPrepAttachTest extends TestCase {
 
+  private static List<Event> readPpaFile(String filename) throws IOException {
+
+    List<Event> events = new ArrayList<Event>();
+
+    BufferedReader in = new BufferedReader(new FileReader(filename));
+    String line;
+
+    while ((line = in.readLine()) != null) {
+      String[] items = line.split("\\s+");
+      String label = items[5];
+      String[] context = { "verb=" + items[1], "noun=" + items[2],
+          "prep=" + items[3], "prep_obj=" + items[4] };
+      events.add(new Event(label, context));
+    }
+    in.close();
+    
+    return events;
+  }
+  
   public void testPerceptronOnPrepAttachData() throws IOException {
     List<Event> trainingEvents = readPpaFile("src/test/resources/data/ppa/training");
 
@@ -57,26 +85,6 @@ public class PerceptronPrepAttachTest ex
     double accuracy = correct/(double)total;
     System.out.println("Accuracy on PPA devset: (" + correct + "/" + total + ") " + accuracy);
 
-    assertEquals(accuracy, 0.7813815300817034, .00001);
-  }
-
-  private static List<Event> readPpaFile (String filename) throws IOException {
-
-    List<Event> events = new ArrayList<Event>();
-
-    BufferedReader in = new BufferedReader(new FileReader(filename));
-    String line;
-    
-    while ( (line = in.readLine()) != null ) {
-      String[] items = line.split("\\s+");
-      String label = items[5];
-      String[] context = { "verb="+items[1], "noun="+items[2], "prep="+items[3], "prep_obj="+items[4] };
-      events.add(new Event(label, context));
-    }
-    in.close();
-    return events;
+    assertEquals(0.7613270611537509, accuracy, .00001);
   }
-
 }
-
-