Package opennlp.tools.stemmer
Class SharingStemmer
java.lang.Object
opennlp.tools.stemmer.SharingStemmer
- All Implemented Interfaces:
opennlp.tools.stemmer.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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidRemoves this thread's payload to prevent classloader leaks in container environments.stem(CharSequence word) stemAll(CharSequence word)
-
Constructor Details
-
SharingStemmer
public SharingStemmer(opennlp.tools.stemmer.StemmerFactory factory) - Parameters:
factory- The factory that mints per-thread delegates. Must not benull.- Throws:
IllegalArgumentException- iffactoryisnull.
-
-
Method Details
-
stem
-
stemAll
-
clearThreadLocalState
public void clearThreadLocalState()Removes this thread's payload to prevent classloader leaks in container environments. Call when the thread is returned to a pool or the stemmer is no longer needed, mirroringclearThreadLocalState()on the thread-safe*MEcomponents.
-