You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by co...@apache.org on 2011/08/20 07:08:10 UTC

svn commit: r1159848 - in /incubator/opennlp/trunk/opennlp-tools/src: main/java/opennlp/tools/cmdline/ test/java/opennlp/tools/chunker/ test/resources/opennlp/tools/chunker/

Author: colen
Date: Sat Aug 20 05:08:10 2011
New Revision: 1159848

URL: http://svn.apache.org/viewvc?rev=1159848&view=rev
Log:
OPENNLP-256 The unit test was failing because the output of string format changes according to the locale.
Added to DetailedFMeasureListener a method called createReport(Locale), where it is possible to specify the desired locale. It is overloaded by createReport(), that uses the default locale. The toString will use createReport() with the default locale.

Modified:
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/DetailedFMeasureListener.java
    incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/chunker/ChunkerDetailedFMeasureListenerTest.java
    incubator/opennlp/trunk/opennlp-tools/src/test/resources/opennlp/tools/chunker/detailedOutput.txt

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/DetailedFMeasureListener.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/DetailedFMeasureListener.java?rev=1159848&r1=1159847&r2=1159848&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/DetailedFMeasureListener.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/DetailedFMeasureListener.java Sat Aug 20 05:08:10 2011
@@ -21,6 +21,7 @@ import java.util.Arrays;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.SortedSet;
@@ -108,9 +109,12 @@ public abstract class DetailedFMeasureLi
       + ";  recall: " + PERCENT + "; F1: " + PERCENT + ".";
   private static final String FORMAT_EXTRA = FORMAT
       + " [target: %3d; tp: %3d; fp: %3d]";
-
-  @Override
-  public String toString() {
+  
+  public String createReport() {
+    return createReport(Locale.getDefault());
+  }
+  
+  public String createReport(Locale locale) {
     StringBuilder ret = new StringBuilder();
     int tp = generalStats.getTruePositives();
     int found = generalStats.getFalsePositives() + tp;
@@ -118,7 +122,7 @@ public abstract class DetailedFMeasureLi
         + generalStats.getTarget() + " entities; found: " + found
         + " entities; correct: " + tp + ".\n");
 
-    ret.append(String.format(FORMAT, "TOTAL",
+    ret.append(String.format(locale, FORMAT, "TOTAL",
         zeroOrPositive(generalStats.getPrecisionScore() * 100),
         zeroOrPositive(generalStats.getRecallScore() * 100),
         zeroOrPositive(generalStats.getFMeasure() * 100)));
@@ -127,7 +131,7 @@ public abstract class DetailedFMeasureLi
     set.addAll(statsForOutcome.keySet());
     for (String type : set) {
 
-      ret.append(String.format(FORMAT_EXTRA, type,
+      ret.append(String.format(locale, FORMAT_EXTRA, type,
           zeroOrPositive(statsForOutcome.get(type).getPrecisionScore() * 100),
           zeroOrPositive(statsForOutcome.get(type).getRecallScore() * 100),
           zeroOrPositive(statsForOutcome.get(type).getFMeasure() * 100),
@@ -138,7 +142,11 @@ public abstract class DetailedFMeasureLi
     }
 
     return ret.toString();
+  }
 
+  @Override
+  public String toString() {
+    return createReport();
   }
 
   private double zeroOrPositive(double v) {

Modified: incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/chunker/ChunkerDetailedFMeasureListenerTest.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/chunker/ChunkerDetailedFMeasureListenerTest.java?rev=1159848&r1=1159847&r2=1159848&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/chunker/ChunkerDetailedFMeasureListenerTest.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/chunker/ChunkerDetailedFMeasureListenerTest.java Sat Aug 20 05:08:10 2011
@@ -17,17 +17,17 @@
 
 package opennlp.tools.chunker;
 
-import static junit.framework.Assert.*;
+import static junit.framework.Assert.assertEquals;
 
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.Collections;
+import java.util.Locale;
 
 import opennlp.tools.cmdline.chunker.ChunkerDetailedFMeasureListener;
 import opennlp.tools.util.PlainTextByLineStream;
-import opennlp.tools.util.eval.EvaluationSampleListener;
 
 import org.junit.Test;
 
@@ -55,7 +55,7 @@ public class ChunkerDetailedFMeasureList
 
       Chunker dummyChunker = new DummyChunker(predictedSample);
 
-      EvaluationSampleListener<ChunkSample> listener = new ChunkerDetailedFMeasureListener();
+      ChunkerDetailedFMeasureListener listener = new ChunkerDetailedFMeasureListener();
       ChunkerEvaluator evaluator = new ChunkerEvaluator(dummyChunker,
           Collections.singletonList(listener));
 
@@ -70,7 +70,7 @@ public class ChunkerDetailedFMeasureList
         expected.append("\n");
         line = reader.readLine();
       }
-      assertEquals(expected.toString().trim(), listener.toString().trim());
+      assertEquals(expected.toString().trim(), listener.createReport(Locale.ENGLISH).trim());
     } finally {
       inPredicted.close();
       inExpected.close();

Modified: incubator/opennlp/trunk/opennlp-tools/src/test/resources/opennlp/tools/chunker/detailedOutput.txt
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/test/resources/opennlp/tools/chunker/detailedOutput.txt?rev=1159848&r1=1159847&r2=1159848&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/test/resources/opennlp/tools/chunker/detailedOutput.txt (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/test/resources/opennlp/tools/chunker/detailedOutput.txt Sat Aug 20 05:08:10 2011
@@ -1,6 +1,7 @@
 Evaluated 3 samples with 32 entities; found: 35 entities; correct: 28.
-       TOTAL: precision:   80,00%;  recall:   87,50%; F1:   83,58%.
-          NP: precision:   90,00%;  recall:   94,74%; F1:   92,31%. [target:  19; tp:  18; fp:   2]
-          VP: precision:   75,00%;  recall:   75,00%; F1:   75,00%. [target:   8; tp:   6; fp:   2]
-          PP: precision:   57,14%;  recall:  100,00%; F1:   72,73%. [target:   4; tp:   4; fp:   3]
-        SBAR: precision:    0,00%;  recall:    0,00%; F1:    0,00%. [target:   1; tp:   0; fp:   0]
\ No newline at end of file
+       TOTAL: precision:   80.00%;  recall:   87.50%; F1:   83.58%.
+          NP: precision:   90.00%;  recall:   94.74%; F1:   92.31%. [target:  19; tp:  18; fp:   2]
+          VP: precision:   75.00%;  recall:   75.00%; F1:   75.00%. [target:   8; tp:   6; fp:   2]
+          PP: precision:   57.14%;  recall:  100.00%; F1:   72.73%. [target:   4; tp:   4; fp:   3]
+        SBAR: precision:    0.00%;  recall:    0.00%; F1:    0.00%. [target:   1; tp:   0; fp:   0]
+