Package opennlp.tools.stemmer.snowball
Class SnowballStemmer
java.lang.Object
opennlp.tools.stemmer.snowball.SnowballStemmer
- All Implemented Interfaces:
Stemmer
A
Stemmer backed by the generated Snowball engines.
The generated engines hold mutable per-call buffers, so this class routes each call to a
per-thread engine, the same pattern the thread-safe *ME components use. A single
SnowballStemmer instance is therefore safe to share across threads.
As with the *ME components, long-running environments such as application
containers should call clearThreadLocalState() when a pooled thread no longer uses
this stemmer; otherwise the thread retains its engine until the instance is unreachable,
which can pin the defining classloader on redeploys.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSnowballStemmer(SnowballStemmer.ALGORITHM algorithm) Creates a stemmer for the given algorithm withrepeat = 1.SnowballStemmer(SnowballStemmer.ALGORITHM algorithm, int repeat) Creates a stemmer for the given algorithm and repeat count. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the calling thread's state to prevent classloader leaks in container environments: a per-thread engine is removed, and the owner engine stays referenced by this instance.(package private) static Supplier<AbstractSnowballStemmer> engineFor(SnowballStemmer.ALGORITHM algorithm) Returns a supplier of a fresh Snowball engine for the given algorithm, shared withSnowballStemmerFactorywhose products embed one engine directly.stem(CharSequence word) Stemsword.
-
Field Details
-
sharing
-
-
Constructor Details
-
SnowballStemmer
Creates a stemmer for the given algorithm and repeat count.- Parameters:
algorithm- The Snowball algorithm. Must not benull.repeat- How many times to apply the stemmer per word; must be positive.- Throws:
IllegalArgumentException- Thrown ifalgorithmisnullorrepeatis not positive.
-
SnowballStemmer
Creates a stemmer for the given algorithm withrepeat = 1.- Parameters:
algorithm- The Snowball algorithm. Must not benull.- Throws:
IllegalArgumentException- Thrown ifalgorithmisnull.
-
-
Method Details
-
engineFor
Returns a supplier of a fresh Snowball engine for the given algorithm, shared withSnowballStemmerFactorywhose products embed one engine directly.- Parameters:
algorithm- The Snowball algorithm.- Returns:
- a supplier that mints a new engine on each call.
-
stem
Stemsword. -
clearThreadLocalState
public void clearThreadLocalState()Clears the calling thread's state to prevent classloader leaks in container environments: a per-thread engine is removed, and the owner engine stays referenced by this instance. Call when the thread is returned to a pool or the stemmer is no longer needed, mirroringclearThreadLocalState()on the thread-safe*MEcomponents.
-