Class LemmatizerAnnotator
java.lang.Object
opennlp.tools.lemmatizer.LemmatizerAnnotator
- All Implemented Interfaces:
opennlp.tools.document.DocumentAnnotator
public final class LemmatizerAnnotator
extends Object
implements opennlp.tools.document.DocumentAnnotator
Adapts a
Lemmatizer to the document pipeline: reads Layers.SENTENCES,
Layers.TOKENS, and Layers.POS_TAGS and provides LEMMAS, one
annotation per token on the token's span.
Each sentence is lemmatized separately, the way the lemmatizer contract expects its
input, so lemmatization decisions never cross a sentence boundary. Token spans already
refer to the original document text, so only the token and tag sequences handed to the
lemmatizer are sliced per sentence; the produced lemma layer stays aligned with
Layers.TOKENS by position.
- Since:
- 3.0.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLemmatizerAnnotator(opennlp.tools.lemmatizer.Lemmatizer lemmatizer) Initializes the adapter. -
Method Summary
Modifier and TypeMethodDescriptionopennlp.tools.document.Documentannotate(opennlp.tools.document.Document document) Lemmatizes the document sentence by sentence and adds theLEMMASlayer.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
-
LEMMAS
The lemma layer. It is aligned with the token layer by position, and each annotation carries the lemma of its token on that token's span.
-
-
Constructor Details
-
LemmatizerAnnotator
public LemmatizerAnnotator(opennlp.tools.lemmatizer.Lemmatizer lemmatizer) Initializes the adapter.- Parameters:
lemmatizer- The lemmatizer to delegate to. Must not benull.- Throws:
IllegalArgumentException- Thrown iflemmatizerisnull.
-
-
Method Details
-
annotate
public opennlp.tools.document.Document annotate(opennlp.tools.document.Document document) Lemmatizes the document sentence by sentence and adds theLEMMASlayer.For every sentence, the tokens whose spans lie inside the sentence span are lemmatized as one sequence together with their tags, and each lemma 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 lemma 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 and aLayers.POS_TAGSlayer with exactly one tag per token, with every token lying inside a sentence.- Returns:
- A new
Documentwith theLEMMASlayer added. Nevernull. - Throws:
IllegalArgumentException- Thrown ifdocumentisnull, the sentence layer, the token layer, or the tag layer is absent, the tag layer does not have exactly one tag per token, a token lies outside every sentence, or the lemmatizer does not return one lemma per token of a sentence.
-
requires
- Specified by:
requiresin interfaceopennlp.tools.document.DocumentAnnotator
-
provides
- Specified by:
providesin interfaceopennlp.tools.document.DocumentAnnotator
-
toString
-