Package opennlp.tools.postag
Class ConfigurablePOSContextGenerator
java.lang.Object
opennlp.tools.postag.ConfigurablePOSContextGenerator
- All Implemented Interfaces:
POSContextGenerator,BeamSearchContextGenerator<String>
@ThreadSafe
public class ConfigurablePOSContextGenerator
extends Object
implements POSContextGenerator
A configurable
context generator for a POSTagger.
This implementation makes use of AdaptiveFeatureGenerator.
The per-sentence context cache is maintained per-thread via ThreadLocal,
making this class safe for concurrent use.
Note: In container environments with classloader isolation (e.g. Jakarta EE),
ThreadLocal state may pin the classloader. Ensure instances do not outlive
the application's lifecycle, or call ThreadLocal.remove() on pooled threads.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final AdaptiveFeatureGeneratorprivate final ThreadLocal<ConfigurablePOSContextGenerator.CacheState> -
Constructor Summary
ConstructorsConstructorDescriptionConfigurablePOSContextGenerator(int cacheSize, AdaptiveFeatureGenerator featureGenerator) Initializes aConfigurablePOSContextGeneratorinstance with an optional per-thread context cache.ConfigurablePOSContextGenerator(AdaptiveFeatureGenerator featureGenerator) Initializes aConfigurablePOSContextGeneratorinstance. -
Method Summary
Modifier and TypeMethodDescriptionprivate String[]createContextFeatures(int index, String[] tokens, String[] tags) String[]getContext(int index, String[] tokens, String[] tags, Object[] additionalContext) Returns the context for making a postag decision at the specified tokenindexgiven the specifiedtokensand previoustags.
-
Field Details
-
featureGenerator
-
cacheSize
private final int cacheSize -
threadState
-
-
Constructor Details
-
ConfigurablePOSContextGenerator
Initializes aConfigurablePOSContextGeneratorinstance. A cache size of0will be used as default.- Parameters:
featureGenerator- TheAdaptiveFeatureGeneratorto be used.- Throws:
IllegalArgumentException- Thrown iffeatureGeneratorisnull.
-
ConfigurablePOSContextGenerator
Initializes aConfigurablePOSContextGeneratorinstance with an optional per-thread context cache.- Parameters:
cacheSize- The size of the per-thread context cache. Use0to disable caching.featureGenerator- TheAdaptiveFeatureGeneratorto be used.- Throws:
IllegalArgumentException- Thrown iffeatureGeneratorisnull.
-
-
Method Details
-
createContextFeatures
-
getContext
Returns the context for making a postag decision at the specified tokenindexgiven the specifiedtokensand previoustags.- Specified by:
getContextin interfaceBeamSearchContextGenerator<String>- Specified by:
getContextin interfacePOSContextGenerator- Parameters:
index- The index of the token for which the context is provided.tokens- The token sequence representing a sentence.tags- The tags assigned to the previous words in the sentence.additionalContext- The context for additional information.- Returns:
- The context for making a postag decision at the specified token
indexgiven the specifiedtokensand previoustags.
-