Class TermVectorAnnotator
- All Implemented Interfaces:
DocumentAnnotator
TermVector per distinct term, carrying the term string, its occurrence count,
and (in full mode) the occurrence offsets.
Term identity comes from the configured normalizer: without one, the term is the
token's covered text; with a CharSequenceNormalizer, each token is normalized
on its own; with an OffsetAwareNormalizer, the document is normalized once and
each token span is mapped into the normalized text. Occurrence spans always point into
the original text. A token whose term is empty is omitted.
The layer is document-scoped: each TermVector
is a whole-document statistic, so the annotations carry no span of their own and the
occurrence offsets live inside the payload. The layer preserves first-occurrence
order: the first token of a term fixes its position in the layer.
The annotator holds no per-call state; it is as thread-safe as the normalizer it was built with.
- Since:
- 3.0.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TermVectorAnnotator.Modeprivate final OffsetAwareNormalizerstatic final LayerKey<TermVector> The key of the term vector layer this annotator provides: a document-scoped layer ofTermVectorvalues, one per distinct term.private final CharSequenceNormalizer -
Constructor Summary
ConstructorsConstructorDescriptionInitializes afull modeannotator that groups tokens by their covered text as-is.Initializes an annotator that groups tokens by their covered text as-is.TermVectorAnnotator(CharSequenceNormalizer normalizer) Initializes afull modeannotator that groups tokens by their per-token normalized form.TermVectorAnnotator(CharSequenceNormalizer normalizer, TermVectorAnnotator.Mode mode) Initializes an annotator that groups tokens by their per-token normalized form.TermVectorAnnotator(OffsetAwareNormalizer normalizer) Initializes afull modeannotator that groups tokens by their normalized form through a whole-document alignment.TermVectorAnnotator(OffsetAwareNormalizer normalizer, TermVectorAnnotator.Mode mode) Initializes an annotator that groups tokens by their normalized form through a whole-document alignment. -
Method Summary
Modifier and TypeMethodDescriptionAggregates the token layer into theTERM_VECTORSlayer.private List<Annotation<TermVector>> countVectors(List<Annotation<String>> tokens, AlignedText aligned, String normalized) Aggregates the tokens into scoring-only term vectors, so no offset storage is ever allocated.private List<Annotation<TermVector>> fullVectors(List<Annotation<String>> tokens, AlignedText aligned, String normalized) Aggregates the tokens into full term vectors, keeping every occurrence span.provides()requires()private StringtermOf(Annotation<String> token, AlignedText aligned, String normalized) Determines the term one token groups under: its covered text as-is, its covered text normalized on its own when a plain per-token normalizer is present, or the covered text of its span mapped into the normalized form when an offset-aware normalizer is present.toString()Returns the adapter's simple class name, which names it in pipeline validation messages.
-
Field Details
-
TERM_VECTORS
The key of the term vector layer this annotator provides: a document-scoped layer ofTermVectorvalues, one per distinct term. -
normalizer
-
tokenNormalizer
-
mode
-
-
Constructor Details
-
TermVectorAnnotator
public TermVectorAnnotator()Initializes afull modeannotator that groups tokens by their covered text as-is. -
TermVectorAnnotator
Initializes an annotator that groups tokens by their covered text as-is.- Parameters:
mode- How much eachTermVectorrecords. Must not benull.- Throws:
IllegalArgumentException- Thrown ifmodeisnull.
-
TermVectorAnnotator
Initializes afull modeannotator that groups tokens by their per-token normalized form. This is the general path: the normalizer is applied to each token's covered text on its own, so anyCharSequenceNormalizerworks, including the folds that cannot report an alignment (case folding, NFC, accent folding, stemmer-backed normalizers). The occurrence spans stay the tokens' own spans in the original text.- Parameters:
normalizer- The normalizer that defines term identity, applied to each token's covered text. Must not benull.- Throws:
IllegalArgumentException- Thrown ifnormalizerisnull.
-
TermVectorAnnotator
Initializes an annotator that groups tokens by their per-token normalized form. This is the general path: the normalizer is applied to each token's covered text on its own, so anyCharSequenceNormalizerworks, including the folds that cannot report an alignment (case folding, NFC, accent folding, stemmer-backed normalizers). The occurrence spans stay the tokens' own spans in the original text.- Parameters:
normalizer- The normalizer that defines term identity, applied to each token's covered text. Must not benull.mode- How much eachTermVectorrecords. Must not benull.- Throws:
IllegalArgumentException- Thrown ifnormalizerormodeisnull.
-
TermVectorAnnotator
Initializes afull modeannotator that groups tokens by their normalized form through a whole-document alignment. Prefer theplain-normalizer constructoras the general path; this one only accepts alignment-reporting normalizers but can see across token boundaries, for example a whitespace collapse spanning two tokens.- Parameters:
normalizer- The normalizer that defines term identity, applied to the whole document text so token spans can be mapped into the normalized form through its alignment. Must not benull.- Throws:
IllegalArgumentException- Thrown ifnormalizerisnull.
-
TermVectorAnnotator
Initializes an annotator that groups tokens by their normalized form through a whole-document alignment. Prefer theplain-normalizer constructoras the general path; this one only accepts alignment-reporting normalizers but can see across token boundaries, for example a whitespace collapse spanning two tokens.- Parameters:
normalizer- The normalizer that defines term identity, applied to the whole document text so token spans can be mapped into the normalized form through its alignment. Must not benull.mode- How much eachTermVectorrecords. Must not benull.- Throws:
IllegalArgumentException- Thrown ifnormalizerormodeisnull.
-
-
Method Details
-
annotate
Aggregates the token layer into theTERM_VECTORSlayer. A present-but-empty token layer yields a present-but-empty term vector layer.- Specified by:
annotatein interfaceDocumentAnnotator- Parameters:
document- The document to annotate. Must not benulland must contain theLayers.TOKENSlayer.- Returns:
- A new
Documentwith theTERM_VECTORSlayer added. Nevernull. - Throws:
IllegalArgumentException- Thrown ifdocumentisnull, lacks theLayers.TOKENSlayer, or already carries theTERM_VECTORSlayer.
-
fullVectors
private List<Annotation<TermVector>> fullVectors(List<Annotation<String>> tokens, AlignedText aligned, String normalized) Aggregates the tokens into full term vectors, keeping every occurrence span.- Parameters:
tokens- The token layer.aligned- The normalized document text with its alignment, ornullwhen no normalizer is present.normalized- The normalized document text, ornullwhen no normalizer is present.- Returns:
- One annotation per distinct term, in first-occurrence order.
-
countVectors
private List<Annotation<TermVector>> countVectors(List<Annotation<String>> tokens, AlignedText aligned, String normalized) Aggregates the tokens into scoring-only term vectors, so no offset storage is ever allocated.- Parameters:
tokens- The token layer.aligned- The normalized document text with its alignment, ornullwhen no normalizer is present.normalized- The normalized document text, ornullwhen no normalizer is present.- Returns:
- One annotation per distinct term, in first-occurrence order.
-
requires
- Specified by:
requiresin interfaceDocumentAnnotator- Returns:
- The keys of the layers this annotator reads. Never
null.
-
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. -
termOf
Determines the term one token groups under: its covered text as-is, its covered text normalized on its own when a plain per-token normalizer is present, or the covered text of its span mapped into the normalized form when an offset-aware normalizer is present.- Parameters:
token- The token annotation.aligned- The normalized document text with its alignment, ornullwhen no offset-aware normalizer is present.normalized- The normalized document text, ornullwhen no offset-aware normalizer is present.- Returns:
- The term string. Never
null, possibly empty.
-