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/26 00:06:44 UTC

svn commit: r1063508 - in /incubator/opennlp/trunk/opennlp-tools/src: main/java/opennlp/tools/chunker/Chunker.java main/java/opennlp/tools/chunker/ChunkerME.java test/java/opennlp/tools/chunker/DummyChunker.java

Author: colen
Date: Tue Jan 25 23:06:44 2011
New Revision: 1063508

URL: http://svn.apache.org/viewvc?rev=1063508&view=rev
Log:
OPENNLP-62 added chunkAsSpans method to Chunker

Modified:
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/Chunker.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java
    incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/chunker/DummyChunker.java

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/Chunker.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/Chunker.java?rev=1063508&r1=1063507&r2=1063508&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/Chunker.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/Chunker.java Tue Jan 25 23:06:44 2011
@@ -20,6 +20,7 @@ package opennlp.tools.chunker;
 import java.util.List;
 
 import opennlp.tools.util.Sequence;
+import opennlp.tools.util.Span;
 
 /**
  * The interface for chunkers which provide chunk tags for a sequence of tokens.
@@ -48,6 +49,16 @@ public interface Chunker {
    * @return an array of chunk tags for each token in the sequence.
    */
   public String[] chunk(String[] toks, String tags[]);
+  
+  /**
+   * Generates tagged chunk spans for the given sequence returning the result in a span array.
+   *
+   * @param toks an array of the tokens or words of the sequence.
+   * @param tags an array of the pos tags of the sequence.
+   * 
+   * @return an array of spans with chunk tags for each chunk in the sequence.
+   */
+  public Span[] chunkAsSpans(String[] toks, String tags[]);
 
   /**
    * Returns the top k chunk sequences for the specified sentence with the specified pos-tags

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java?rev=1063508&r1=1063507&r2=1063508&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java Tue Jan 25 23:06:44 2011
@@ -37,6 +37,7 @@ import opennlp.tools.util.ObjectStream;
 import opennlp.tools.util.PlainTextByLineStream;
 import opennlp.tools.util.Sequence;
 import opennlp.tools.util.SequenceValidator;
+import opennlp.tools.util.Span;
 import opennlp.tools.util.model.BaseModel;
 import opennlp.tools.util.model.ModelUtil;
 
@@ -161,6 +162,11 @@ public class ChunkerME implements Chunke
     List<String> c = bestSequence.getOutcomes();
     return c.toArray(new String[c.size()]);
   }
+  
+  public Span[] chunkAsSpans(String[] toks, String[] tags) {
+    String[] preds = chunk(toks, tags);
+    return ChunkSample.phrasesAsSpanList(toks, tags, preds);
+  }
 
   public Sequence[] topKSequences(List<String> sentence, List<String> tags) {
     return beam.bestSequences(DEFAULT_BEAM_SIZE, sentence.toArray(new String[sentence.size()]), new Object[] { tags });

Modified: incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/chunker/DummyChunker.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/chunker/DummyChunker.java?rev=1063508&r1=1063507&r2=1063508&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/chunker/DummyChunker.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/chunker/DummyChunker.java Tue Jan 25 23:06:44 2011
@@ -22,6 +22,7 @@ import java.util.Arrays;
 import java.util.List;
 
 import opennlp.tools.util.Sequence;
+import opennlp.tools.util.Span;
 
 /**
  * This dummy chunker implementation reads a file formatted as described at
@@ -76,4 +77,8 @@ public class DummyChunker implements Chu
 		return null;
 	}
 
+	public Span[] chunkAsSpans(String[] toks, String[] tags) {
+		return null;
+	}
+
 }