Package opennlp.tools.tokenize
Class TokenizerAnnotator
java.lang.Object
opennlp.tools.tokenize.TokenizerAnnotator
- All Implemented Interfaces:
DocumentAnnotator
Adapts a
Tokenizer to the document pipeline: provides Layers.TOKENS.
When Layers.SENTENCES is present, each sentence is tokenized separately and
the token spans are shifted back to document coordinates; a present-but-empty sentence
layer therefore yields a present-but-empty token layer. Only when the sentence layer
is absent is the whole text tokenized at once. Either way, every token span refers to
the original document text.
The adapter holds no per-call state; it is as thread-safe as the tokenizer it wraps.
- Since:
- 3.0.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddTokens(List<Annotation<String>> tokens, String text, int offset) Tokenizes one stretch of text and appends its tokens, shifted back into document coordinates.Tokenizes the document and adds theLayers.TOKENSlayer, sentence by sentence when a sentence layer is present and over the whole text otherwise.provides()toString()Returns the adapter's simple class name, which names it in pipeline validation messages.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface opennlp.tools.document.DocumentAnnotator
requires
-
Field Details
-
tokenizer
-
-
Constructor Details
-
TokenizerAnnotator
Initializes the adapter.- Parameters:
tokenizer- The tokenizer to delegate to. Must not benull.- Throws:
IllegalArgumentException- Thrown iftokenizerisnull.
-
-
Method Details
-
annotate
Tokenizes the document and adds theLayers.TOKENSlayer, sentence by sentence when a sentence layer is present and over the whole text otherwise.- Specified by:
annotatein interfaceDocumentAnnotator- Parameters:
document- The document to annotate. Must not benull.- Returns:
- A new
Documentwith theLayers.TOKENSlayer added. Nevernull. - Throws:
IllegalArgumentException- Thrown ifdocumentisnullor already carries theLayers.TOKENSlayer.
-
addTokens
Tokenizes one stretch of text and appends its tokens, shifted back into document coordinates.- Parameters:
tokens- The layer under construction.text- The stretch to tokenize.offset- The stretch's start offset in the document text.
-
provides
- Specified by:
providesin interfaceDocumentAnnotator- Returns:
- The keys of the layers this annotator adds. Never
null.
-
toString
Returns the adapter's simple class name, which names it in pipeline validation messages.
-