Class ThreadSafePOSTaggerME
java.lang.Object
opennlp.tools.postag.ThreadSafePOSTaggerME
- All Implemented Interfaces:
AutoCloseable, opennlp.tools.ml.Probabilistic, opennlp.tools.postag.POSTagger
@ThreadSafe
public class ThreadSafePOSTaggerME
extends Object
implements opennlp.tools.postag.POSTagger, opennlp.tools.ml.Probabilistic, AutoCloseable
A thread-safe version of the
POSTaggerME. Using it is completely transparent.
You can use it in a single-threaded context as well, it only incurs a minimal overhead.
Note:
This implementation uses a ThreadLocal. Although the implementation is
lightweight because the model is not duplicated, if you have many long-running threads,
you may run into memory problems.
Be careful when using this in a Jakarta EE application, for example.
The user is responsible for clearing theThreadLocal
via calling close().- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionThreadSafePOSTaggerME(String language) Initializes aThreadSafePOSTaggerMEby downloading a default model for a givenlanguage.ThreadSafePOSTaggerME(String language, POSTagFormat format) Initializes aThreadSafePOSTaggerMEby downloading a default model for a givenlanguage.ThreadSafePOSTaggerME(POSModel model) Initializes aThreadSafePOSTaggerMEwith the specifiedmodel.ThreadSafePOSTaggerME(POSModel model, POSTagFormat format) Initializes aThreadSafePOSTaggerMEwith the specifiedmodel. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()double[]probs()String[]String[]opennlp.tools.util.Sequence[]topKSequences(String[] sentence) opennlp.tools.util.Sequence[]topKSequences(String[] sentence, Object[] additionaContext)
-
Constructor Details
-
ThreadSafePOSTaggerME
Initializes aThreadSafePOSTaggerMEby downloading a default model for a givenlanguage.- Parameters:
language- An ISO conform language code.- Throws:
IOException- Thrown if the model could not be downloaded or saved.
-
ThreadSafePOSTaggerME
Initializes aThreadSafePOSTaggerMEby downloading a default model for a givenlanguage.- Parameters:
language- An ISO conform language code.format- A validPOSTagFormat.- Throws:
IOException- Thrown if the model could not be downloaded or saved.
-
ThreadSafePOSTaggerME
Initializes aThreadSafePOSTaggerMEwith the specifiedmodel.- Parameters:
model- A validPOSModel.
-
ThreadSafePOSTaggerME
Initializes aThreadSafePOSTaggerMEwith the specifiedmodel.- Parameters:
model- A validPOSModel.format- A validPOSTagFormat.
-
-
Method Details
-
tag
-
tag
-
topKSequences
- Specified by:
topKSequencesin interfaceopennlp.tools.postag.POSTagger
-
topKSequences
-
probs
public double[] probs()- Specified by:
probsin interfaceopennlp.tools.ml.Probabilistic
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-