Class CachedFeatureGenerator
- All Implemented Interfaces:
opennlp.tools.util.featuregen.AdaptiveFeatureGenerator
generators.
The cache is maintained per-thread via ThreadLocal, making this class safe for
concurrent use from multiple threads. Each thread gets its own independent cache that is
cleared when a new sentence (token array) is encountered.
Cache key is reference identity, not content. The "is this still the same sentence?" check
uses tokens == state.prevTokens; passing a freshly allocated String[] with the same
contents is treated as a new sentence and triggers a cache miss + clear. Reuse the same tokens
array across calls when you need the cache to hit.
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSystem property to disable the feature cache globally. -
Constructor Summary
ConstructorsConstructorDescriptionCachedFeatureGenerator(opennlp.tools.util.featuregen.AdaptiveFeatureGenerator generator) CachedFeatureGenerator(opennlp.tools.util.featuregen.AdaptiveFeatureGenerator... generators) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidcreateFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) opennlp.tools.util.featuregen.AdaptiveFeatureGeneratorlongDeprecated.Cache statistics are no longer tracked.longDeprecated.Cache statistics are no longer tracked.voidupdateAdaptiveData(String[] tokens, String[] outcomes)
-
Field Details
-
DISABLE_CACHE_PROPERTY
System property to disable the feature cache globally. Set to"true"to bypass caching (useful for benchmarking).- See Also:
-
-
Constructor Details
-
CachedFeatureGenerator
@Deprecated public CachedFeatureGenerator(opennlp.tools.util.featuregen.AdaptiveFeatureGenerator... generators) Deprecated.UseCachedFeatureGenerator(AdaptiveFeatureGenerator)instead. -
CachedFeatureGenerator
public CachedFeatureGenerator(opennlp.tools.util.featuregen.AdaptiveFeatureGenerator generator)
-
-
Method Details
-
createFeatures
public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) - Specified by:
createFeaturesin interfaceopennlp.tools.util.featuregen.AdaptiveFeatureGenerator
-
updateAdaptiveData
- Specified by:
updateAdaptiveDatain interfaceopennlp.tools.util.featuregen.AdaptiveFeatureGenerator
-
clearAdaptiveData
public void clearAdaptiveData()- Specified by:
clearAdaptiveDatain interfaceopennlp.tools.util.featuregen.AdaptiveFeatureGenerator
-
getNumberOfCacheHits
Deprecated.Cache statistics are no longer tracked.- Returns:
- Retrieves the number of cache hits for the current thread.
-
getNumberOfCacheMisses
Deprecated.Cache statistics are no longer tracked.- Returns:
- Retrieves the number of cache misses for the current thread.
-
getCachedFeatureGenerator
public opennlp.tools.util.featuregen.AdaptiveFeatureGenerator getCachedFeatureGenerator()
-
CachedFeatureGenerator(AdaptiveFeatureGenerator)instead.