opennlp-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject svn commit: r1145813 - in /incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools: cmdline/sentdetect/ sentdetect/
Date Tue, 12 Jul 2011 23:16:50 GMT
Author: colen
Date: Tue Jul 12 23:16:50 2011
New Revision: 1145813

URL: http://svn.apache.org/viewvc?rev=1145813&view=rev
Log:
OPENNLP-220 Added printError to SentenceDetector evaluation tools

Modified:
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorCrossValidatorTool.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorEvaluatorTool.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorEvaluator.java

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorCrossValidatorTool.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorCrossValidatorTool.java?rev=1145813&r1=1145812&r2=1145813&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorCrossValidatorTool.java
(original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorCrossValidatorTool.java
Tue Jul 12 23:16:50 2011
@@ -76,7 +76,7 @@ public final class SentenceDetectorCross
     }
     
     try {
-      validator.evaluate(sampleStream, 10);
+      validator.evaluate(sampleStream, 10, params.getPrintErrors());
     }
     catch (IOException e) {
       CmdLineUtil.printTrainingIoError(e);

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorEvaluatorTool.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorEvaluatorTool.java?rev=1145813&r1=1145812&r2=1145813&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorEvaluatorTool.java
(original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorEvaluatorTool.java
Tue Jul 12 23:16:50 2011
@@ -62,8 +62,8 @@ public final class SentenceDetectorEvalu
     File trainingDataInFile = params.getData();
     CmdLineUtil.checkInputFile("Training Data", trainingDataInFile);
     
-    opennlp.tools.sentdetect.SentenceDetectorEvaluator evaluator = 
-        new opennlp.tools.sentdetect.SentenceDetectorEvaluator(new SentenceDetectorME(model));
+    opennlp.tools.sentdetect.SentenceDetectorEvaluator evaluator = new opennlp.tools.sentdetect.SentenceDetectorEvaluator(
+        new SentenceDetectorME(model), params.getPrintErrors());
     
     System.out.print("Evaluating ... ");
       ObjectStream<SentenceSample> sampleStream = SentenceDetectorTrainerTool.openSampleData("Test",

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java?rev=1145813&r1=1145812&r2=1145813&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java
(original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java
Tue Jul 12 23:16:50 2011
@@ -58,8 +58,36 @@ public class SDCrossValidator {
     this(languageCode, 5, 100);
   }
   
-  public void evaluate(ObjectStream<SentenceSample> samples, int nFolds) throws IOException
{
-    
+  /**
+   * Starts the evaluation.
+   * 
+   * @param samples
+   *          the data to train and test
+   * @param nFolds
+   *          number of folds
+   * 
+   * @throws IOException
+   */
+  public void evaluate(ObjectStream<SentenceSample> samples, int nFolds)
+      throws IOException {
+    evaluate(samples, nFolds, false);
+  }
+  
+  /**
+   * Starts the evaluation.
+   * 
+   * @param samples
+   *          the data to train and test
+   * @param nFolds
+   *          number of folds
+   * @param printErrors
+   *          if true will print errors
+   * 
+   * @throws IOException
+   */
+  public void evaluate(ObjectStream<SentenceSample> samples, int nFolds,
+      boolean printErrors) throws IOException {
+
     CrossValidationPartitioner<SentenceSample> partitioner = 
         new CrossValidationPartitioner<SentenceSample>(samples, nFolds);
     
@@ -79,7 +107,7 @@ public class SDCrossValidator {
       
       // do testing
       SentenceDetectorEvaluator evaluator = new SentenceDetectorEvaluator(
-          new SentenceDetectorME(model));
+          new SentenceDetectorME(model), printErrors);
 
       evaluator.evaluate(trainingSampleStream.getTestSampleStream());
       

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorEvaluator.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorEvaluator.java?rev=1145813&r1=1145812&r2=1145813&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorEvaluator.java
(original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorEvaluator.java
Tue Jul 12 23:16:50 2011
@@ -43,16 +43,34 @@ public class SentenceDetectorEvaluator e
    * Initializes the current instance.
    *
    * @param sentenceDetector
+   * @param isPrintErrors if should print false positives and negatives
+   */
+  public SentenceDetectorEvaluator(SentenceDetector sentenceDetector, boolean isPrintErrors)
{
+    super(isPrintErrors);
+    this.sentenceDetector = sentenceDetector;
+  }
+  
+  /**
+   * Initializes the current instance.
+   *
+   * @param sentenceDetector
    */
   public SentenceDetectorEvaluator(SentenceDetector sentenceDetector) {
+    super();
     this.sentenceDetector = sentenceDetector;
   }
 
   public void evaluateSample(SentenceSample sample) {
 
-    Span starts[] = sentenceDetector.sentPosDetect(sample.getDocument());
+    Span predictions[] = sentenceDetector.sentPosDetect(sample.getDocument());
+    Span[] references = sample.getSentences();
+    if (isPrintError()) {
+      String doc = sample.getDocument();
+      printErrors(references, predictions, sample, new SentenceSample(doc,
+          predictions), doc);
+    }
 
-    fmeasure.updateScores(sample.getSentences(), starts);
+    fmeasure.updateScores(references, predictions);
   }
   
   public FMeasure getFMeasure() {



Mime
View raw message