Class POSTaggerAnnotator
java.lang.Object
opennlp.tools.postag.POSTaggerAnnotator
- All Implemented Interfaces:
opennlp.tools.document.DocumentAnnotator
public final class POSTaggerAnnotator
extends Object
implements opennlp.tools.document.DocumentAnnotator
Adapts a
POSTagger to the document pipeline: reads Layers.SENTENCES
and Layers.TOKENS and provides Layers.POS_TAGS, one tag annotation per
token on the token's span.
Each sentence is tagged separately, the way the tagger contract expects its input,
so tagging decisions never cross a sentence boundary. Token spans already refer to the
original document text, so only the token sequence handed to the tagger is sliced per
sentence; the produced tag layer stays aligned with Layers.TOKENS by
position.
- Since:
- 3.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionPOSTaggerAnnotator(opennlp.tools.postag.POSTagger tagger) Initializes the adapter. -
Method Summary
Modifier and TypeMethodDescriptionopennlp.tools.document.Documentannotate(opennlp.tools.document.Document document) Tags the document sentence by sentence and adds theLayers.POS_TAGSlayer.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.
-
Constructor Details
-
POSTaggerAnnotator
public POSTaggerAnnotator(opennlp.tools.postag.POSTagger tagger) Initializes the adapter.- Parameters:
tagger- The tagger to delegate to. Must not benull.- Throws:
IllegalArgumentException- Thrown iftaggerisnull.
-
-
Method Details
-
annotate
public opennlp.tools.document.Document annotate(opennlp.tools.document.Document document) Tags the document sentence by sentence and adds theLayers.POS_TAGSlayer.For every sentence, the tokens whose spans lie inside the sentence span are tagged as one sequence, and each tag is emitted on its token's span. The required layers must be present, but they may be empty: a document without sentences or tokens yields a present-but-empty tag layer, and a sentence containing no tokens contributes nothing.
- Specified by:
annotatein interfaceopennlp.tools.document.DocumentAnnotator- Parameters:
document- The document to annotate. Must not benulland must carry theLayers.SENTENCESandLayers.TOKENSlayers, with every token lying inside a sentence.- Returns:
- A new
Documentwith theLayers.POS_TAGSlayer added. Nevernull. - Throws:
IllegalArgumentException- Thrown ifdocumentisnull, the sentence layer or the token layer is absent, a token lies outside every sentence, or the tagger does not return one tag per token of a sentence.
-
requires
- Specified by:
requiresin interfaceopennlp.tools.document.DocumentAnnotator
-
provides
- Specified by:
providesin interfaceopennlp.tools.document.DocumentAnnotator
-
toString
-