Class ChunkerAnnotator

java.lang.Object
opennlp.tools.chunker.ChunkerAnnotator
All Implemented Interfaces:
opennlp.tools.document.DocumentAnnotator

public final class ChunkerAnnotator extends Object implements opennlp.tools.document.DocumentAnnotator
Adapts a Chunker to the document pipeline: reads Layers.SENTENCES, Layers.TOKENS, and Layers.POS_TAGS and provides CHUNKS, one annotation per phrase chunk carrying the chunk type, for example NP or VP, on the span from its first to its last token.

Each sentence is chunked separately with its tokens and tags as one sequence, the way the chunker contract expects its input. A chunker's spans index tokens within the sentence; the adapter maps them onto the token spans, which already refer to the original text, so a chunk covers exactly the text of its tokens. Chunks are emitted in text order.

The adapter holds no per-call state; it is as thread-safe as the chunker it wraps.

Since:
3.0.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final opennlp.tools.document.LayerKey<String>
    Phrase chunks; each annotation covers one chunk and carries its type, ordered by text position.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ChunkerAnnotator(opennlp.tools.chunker.Chunker chunker)
    Initializes the adapter.
  • Method Summary

    Modifier and Type
    Method
    Description
    opennlp.tools.document.Document
    annotate(opennlp.tools.document.Document document)
    Chunks the document sentence by sentence and adds the CHUNKS layer.
    Set<opennlp.tools.document.LayerKey<?>>
    Set<opennlp.tools.document.LayerKey<?>>
    Returns the adapter's simple class name, which names it in pipeline validation messages.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • CHUNKS

      public static final opennlp.tools.document.LayerKey<String> CHUNKS
      Phrase chunks; each annotation covers one chunk and carries its type, ordered by text position.
  • Constructor Details

    • ChunkerAnnotator

      public ChunkerAnnotator(opennlp.tools.chunker.Chunker chunker)
      Initializes the adapter.
      Parameters:
      chunker - The chunker to delegate to. Must not be null.
      Throws:
      IllegalArgumentException - Thrown if chunker is null.
  • Method Details

    • annotate

      public opennlp.tools.document.Document annotate(opennlp.tools.document.Document document)
      Chunks the document sentence by sentence and adds the CHUNKS layer.

      The required layers must be present, but they may be empty: a document without sentences or tokens yields a present-but-empty chunk layer. The token and tag layers must be aligned one to one.

      Specified by:
      annotate in interface opennlp.tools.document.DocumentAnnotator
      Parameters:
      document - The document to annotate. Must not be null and must carry the Layers.SENTENCES, Layers.TOKENS, and Layers.POS_TAGS layers, with every token lying inside a sentence.
      Returns:
      A new Document with the CHUNKS layer added. Never null.
      Throws:
      IllegalArgumentException - Thrown if document is null, a required layer is absent, the token and tag layers differ in size, a token lies outside every sentence, or the chunker returns a span outside the sentence, an empty span, or a span without a type.
    • requires

      public Set<opennlp.tools.document.LayerKey<?>> requires()
      Specified by:
      requires in interface opennlp.tools.document.DocumentAnnotator
    • provides

      public Set<opennlp.tools.document.LayerKey<?>> provides()
      Specified by:
      provides in interface opennlp.tools.document.DocumentAnnotator
    • toString

      public String toString()
      Returns the adapter's simple class name, which names it in pipeline validation messages.
      Overrides:
      toString in class Object
      Returns:
      the adapter's simple class name, which names it in pipeline validation messages