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 -
Constructor Summary
ConstructorsConstructorDescriptionChunkerAnnotator(opennlp.tools.chunker.Chunker chunker) Initializes the adapter. -
Method Summary
Modifier and TypeMethodDescriptionopennlp.tools.document.Documentannotate(opennlp.tools.document.Document document) Chunks the document sentence by sentence and adds theCHUNKSlayer.Set<opennlp.tools.document.LayerKey<?>> provides()Set<opennlp.tools.document.LayerKey<?>> requires()toString()Returns the adapter's simple class name, which names it in pipeline validation messages.
-
Field Details
-
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 benull.- Throws:
IllegalArgumentException- Thrown ifchunkerisnull.
-
-
Method Details
-
annotate
public opennlp.tools.document.Document annotate(opennlp.tools.document.Document document) Chunks the document sentence by sentence and adds theCHUNKSlayer.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:
annotatein interfaceopennlp.tools.document.DocumentAnnotator- Parameters:
document- The document to annotate. Must not benulland must carry theLayers.SENTENCES,Layers.TOKENS, andLayers.POS_TAGSlayers, with every token lying inside a sentence.- Returns:
- A new
Documentwith theCHUNKSlayer added. Nevernull. - Throws:
IllegalArgumentException- Thrown ifdocumentisnull, 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
- Specified by:
requiresin interfaceopennlp.tools.document.DocumentAnnotator
-
provides
- Specified by:
providesin interfaceopennlp.tools.document.DocumentAnnotator
-
toString
-