Package opennlp.tools.chunker
Class ThreadSafeChunkerME
java.lang.Object
opennlp.tools.chunker.ThreadSafeChunkerME
- All Implemented Interfaces:
- AutoCloseable,- Chunker,- Probabilistic
@ThreadSafe
public class ThreadSafeChunkerME
extends Object
implements Chunker, Probabilistic, AutoCloseable
A thread-safe version of the 
ChunkerME. 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 SummaryConstructorsConstructorDescriptionThreadSafeChunkerME(ChunkerModel model) Initializes aThreadSafeChunkerMEwith the specifiedmodel.
- 
Method SummaryModifier and TypeMethodDescriptionString[]Generates chunk tags for the given sequence returning the result in an array.Span[]chunkAsSpans(String[] toks, String[] tags) voidclose()double[]probs()Retrieves the probabilities of the last decoded sequence.Sequence[]topKSequences(String[] sentence, String[] tags) Computes the top k chunksequencesfor the specified sentence with the specified pos-tags.Sequence[]topKSequences(String[] sentence, String[] tags, double minSequenceScore) Computes the top k chunksequencesfor the specified sentence with the specified pos-tags.
- 
Constructor Details- 
ThreadSafeChunkerMEInitializes aThreadSafeChunkerMEwith the specifiedmodel.- Parameters:
- model- A valid- ChunkerModel.
 
 
- 
- 
Method Details- 
chunkDescription copied from interface:ChunkerGenerates chunk tags for the given sequence returning the result in an array.
- 
chunkAsSpansDescription copied from interface:Chunker- Specified by:
- chunkAsSpansin interface- Chunker
- Parameters:
- toks- an array of the tokens or words of the sequence.
- tags- an array of the pos tags of the sequence.
- Returns:
- an array of spanswith chunk tags for each chunk in the sequence.
 
- 
topKSequencesDescription copied from interface:ChunkerComputes the top k chunksequencesfor the specified sentence with the specified pos-tags.- Specified by:
- topKSequencesin interface- Chunker
- Parameters:
- sentence- The tokens of the sentence.
- tags- The pos-tags for the specified sentence.
- Returns:
- the top k chunk sequencesfor the specified sentence.
 
- 
topKSequencesDescription copied from interface:ChunkerComputes the top k chunksequencesfor the specified sentence with the specified pos-tags.- Specified by:
- topKSequencesin interface- Chunker
- Parameters:
- sentence- The tokens of the sentence.
- tags- The pos-tags for the specified sentence.
- minSequenceScore- A lower bound on the score of a returned sequence.
- Returns:
- the top k chunk sequencesfor the specified sentence.
 
- 
closepublic void close()- Specified by:
- closein interface- AutoCloseable
 
- 
probspublic double[] probs()Description copied from interface:ProbabilisticRetrieves the probabilities of the last decoded sequence.- Specified by:
- probsin interface- Probabilistic
- Returns:
- An array with the same number of probabilities as tokens were sent to the computational method when it was last called.
 
 
-