Class Term
original() form is the source of
truth; the other layers are derived, increasingly aggressive Dimensions tuned for
matching. The dimensions configured on the producing TermAnalyzer are
computed eagerly and cached; any other dimension is computed on first request, applied on top of
the configured form, and then cached.
Because the original is always retained, aggressive folding is safe: a match on a derived layer
can always be reported in original coordinates through span(). Querying a configured
layer, or peeling the last-applied one, is O(1); adding an unconfigured dimension
costs one transform on first touch and is O(1) thereafter.
Instances are created by TermAnalyzer and are thread-safe as long as the analyzer's
configured transforms are (see TermAnalyzer for the stemmer caveat). Concurrent first
requests for the same unconfigured dimension may run its transform more than once, but every
thread observes the same cached value.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the token atdimension.Returns the token at the analyzer's final configured dimension; equal tooriginal()when no dimensions were configured.original()Returns the original token text.peel()Returns the token at the dimension just below the final configured one.opennlp.tools.util.Spanspan()Returns the source span of this token, ornullif it was supplied as a pre-tokenized string.
-
Method Details
-
span
public opennlp.tools.util.Span span()Returns the source span of this token, ornullif it was supplied as a pre-tokenized string. The span indexes into the text passed toTermAnalyzer.analyze(CharSequence).- Returns:
- the source span of this token, or
nullif it was supplied as a pre-tokenized string
-
original
Returns the original token text.- Returns:
- the original token text
-
normalized
Returns the token at the analyzer's final configured dimension; equal tooriginal()when no dimensions were configured.- Returns:
- the token at the analyzer's final configured dimension; equal to
original()when no dimensions were configured
-
at
Returns the token atdimension. Configured dimensions are cached; an unconfigured dimension is computed by applying its transform tonormalized()and then cached.Note: an unconfigured dimension is applied on top of
normalized()(the most aggressive configured layer), not spliced into pipeline order. Because the transforms do not commute (seeDimension), requesting a dimension that ranks earlier than the configured ones can differ from having configured it. For example, asking forDimension.CASE_FOLDon an analyzer configured only throughDimension.ACCENT_FOLDcase-folds the already accent-folded text, which is not the same as case-folding first. Configure the dimension on the analyzer when pipeline order matters.- Parameters:
dimension- The dimension to project to. Must not benull.- Returns:
- The token at that dimension.
- Throws:
IllegalArgumentException- ifdimensionisnull.IllegalStateException- if the dimension needs an engine or tag that was not configured (seeDimension.STEMandDimension.LEMMA).
-
peel
Returns the token at the dimension just below the final configured one. This is the last-applied layer removed (for example the form before stemming whenDimension.STEMis the final dimension); equal tooriginal()when at most one dimension is configured.- Returns:
- the token at the dimension just below the final configured one
-