Class TermAnalyzer
Terms by segmenting text and applying a configured stack of normalization
Dimensions to each token. The analyzer is the configuration; each Term is the
layered result for one token, with the configured dimensions computed eagerly and any other
dimension computed lazily on first request.
Segmentation uses the Unicode UAX #29 word tokenizer, so the
input does not need to be pre-tokenized. The character-level dimensions (Dimension.NFC
through Dimension.CONFUSABLE_FOLD) have built-in defaults; Dimension.STEM and
Dimension.LEMMA are enabled by supplying a Stemmer or Lemmatizer.
An instance is immutable and is thread-safe when its configured transforms are. The built-in
character normalizers are stateless and the Snowball stemmers are thread-safe. When
Dimension.STEM is enabled through TermAnalyzer.Builder.stem(StemmerFactory), stemming is
routed through a CachingStemmer: the analyzer is safe to share across threads even when
the factory mints stateful stemmers, and repeated words resolve from a bounded per-thread cache
instead of being re-stemmed. A raw Stemmer passed to TermAnalyzer.Builder.stem(Stemmer) is
only safe when that stemmer is itself thread-safe or the analyzer is confined to one thread.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionanalyze(CharSequence text) Segmentstextwith the UAX #29 word tokenizer and returns oneTermper word token, in order.Returns oneTermper supplied token, attaching the matching part-of-speech tag so thatDimension.LEMMAcan be computed.static TermAnalyzer.Builderbuilder()Returns a newTermAnalyzer.Builder.Returns the configured dimensions that are computed eagerly, in pipeline order.
-
Method Details
-
builder
Returns a newTermAnalyzer.Builder. The builder starts with no dimensions enabled and the default UAX #29 word tokenizer; enable dimensions and set a stemmer, lemmatizer, or tokenizer on it, then callTermAnalyzer.Builder.build().- Returns:
- a new
TermAnalyzer.Builder
-
analyze
Segmentstextwith the UAX #29 word tokenizer and returns oneTermper word token, in order. The terms carry no part-of-speech tag, soDimension.LEMMAcannot be computed from this entry point: if a lemmatizer is configured, this method throws -- useanalyze(String[], String[])when lemmas are needed.- Parameters:
text- The text to analyze. Must not benull.- Returns:
- The terms.
- Throws:
IllegalArgumentException- iftextisnull.IllegalStateException- ifDimension.LEMMAis configured, because no part-of-speech tags are available from raw text.
-
analyze
Returns oneTermper supplied token, attaching the matching part-of-speech tag so thatDimension.LEMMAcan be computed. The terms have no source span.- Parameters:
tokens- The tokens. Must not benullor containnullelements.tags- The part-of-speech tag for each token; must be the same length astokensand must not benull. Anulltag is only acceptable whenDimension.LEMMAis not computed for that token.- Returns:
- The terms.
- Throws:
IllegalArgumentException- iftokensortagsisnull, if they differ in length, or iftokenscontains anullelement.
-
dimensions
Returns the configured dimensions that are computed eagerly, in pipeline order. The list never includesDimension.ORIGINAL, which is always present.- Returns:
- the configured dimensions that are computed eagerly, in pipeline order
-