Package opennlp.tools.stemmer
Class SharingStemmer
- All Implemented Interfaces:
Stemmer
A
Stemmer that is safe to share across threads by routing each call to a per-thread
delegate minted from a StemmerFactory. Use it to share a stemmer whose implementation is
not itself thread-safe, such as PorterStemmer; thread-safe implementations like
SnowballStemmer do not need this wrapper.
The first thread uses a single owner delegate without touching ThreadLocal until a
second thread appears, matching the OwnerOrPerThreadState pattern used by the
thread-safe *ME components.
-
Field Summary
Fields inherited from class opennlp.tools.stemmer.DelegatingStemmer
state -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstem(CharSequence word) Stemsword.stemAll(CharSequence word) Returns all stem forms forword.Methods inherited from class opennlp.tools.stemmer.DelegatingStemmer
clearThreadLocalState, requireFactory
-
Constructor Details
-
SharingStemmer
Creates a sharing stemmer.- Parameters:
factory- The factory that mints per-thread delegates. Must not benull.- Throws:
IllegalArgumentException- Thrown iffactoryisnull.
-
-
Method Details
-
stem
Stemsword.- Parameters:
word- The input word. Must not benull.- Returns:
- The stemmed form.
-
stemAll
Returns all stem forms forword. Defaults to a single-element list fromStemmer.stem(CharSequence). Dictionary-based engines may override this to return multiple roots; delegating wrappers must forward it to preserve the full list.- Parameters:
word- The input word. Must not benull.- Returns:
- all stem forms for
word
-