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/01/07 19:16:21 UTC

svn commit: r1056438 - in /incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools: chunker/ChunkSample.java cmdline/chunker/ChunkerMETool.java

Author: colen
Date: Fri Jan  7 18:16:21 2011
New Revision: 1056438

URL: http://svn.apache.org/viewvc?rev=1056438&view=rev
Log:
OPENNLP-60 Fixed the ChunkSample.nicePrint. ChunkerMETool should use nicePrint to display the results

Modified:
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerMETool.java

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java?rev=1056438&r1=1056437&r2=1056438&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java Fri Jan  7 18:16:21 2011
@@ -92,21 +92,35 @@ public class ChunkSample {
   
   
   public String nicePrint() {
+  	
+  	Span[] spans = getPhrasesAsSpanList();
+ 	
+  	StringBuilder result = new StringBuilder(" ");
     
-    StringBuilder chunkString = new StringBuilder();
-    
-    for (int ci=0, cn = preds.size(); ci < cn; ci++) {
-      if (ci > 0 && !preds.get(ci).startsWith("I-") && !preds.get(ci - 1).equals("O")) {
-        chunkString.append(" ]");
-      }
-      if (preds.get(ci).startsWith("B-")) {
-        chunkString.append(" [" + preds.get(ci).substring(2));
+    for (int tokenIndex = 0; tokenIndex < sentence.size(); tokenIndex++) {
+      for (int nameIndex = 0; nameIndex < spans.length; nameIndex++) {
+        if (spans[nameIndex].getStart() == tokenIndex) {
+          result.append( "[" + spans[nameIndex].getType()).append(" ");
+        }
+
+        if (spans[nameIndex].getEnd() == tokenIndex) {
+          result.append("]").append(' ');
+        }
       }
 
-      chunkString.append(" " + getSentence()[ci] + "_" + getTags()[ci]);
+      result.append(sentence.get(tokenIndex) + "_" + tags.get(tokenIndex) + ' ');
     }
+
+    if (sentence.size() > 1)
+      result.setLength(result.length() - 1);
     
-    return chunkString.toString();
+    for (int nameIndex = 0; nameIndex < spans.length; nameIndex++) {
+      if (spans[nameIndex].getEnd() == sentence.size()) {
+        result.append(']');
+      }
+    }
+
+    return result.toString();
   }
   
   @Override

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerMETool.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerMETool.java?rev=1056438&r1=1056437&r2=1056438&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerMETool.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerMETool.java Fri Jan  7 18:16:21 2011
@@ -83,7 +83,7 @@ public class ChunkerMETool implements Cm
             posSample.getTags());
         
         System.out.println(new ChunkSample(posSample.getSentence(),
-            posSample.getTags(), chunks).toString());
+            posSample.getTags(), chunks).nicePrint());
         
         perfMon.incrementCounter();
       }