Class CachedFeatureGenerator
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanstatic final StringSystem property to disable the feature cache globally.private final AdaptiveFeatureGeneratorprivate final ThreadLocal<CachedFeatureGenerator.CacheState> -
Constructor Summary
ConstructorsConstructorDescriptionCachedFeatureGenerator(AdaptiveFeatureGenerator generator) CachedFeatureGenerator(AdaptiveFeatureGenerator... generators) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidInforms a feature generator that the context of the adaptive data (typically a document) is no longer valid.voidcreateFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) Adds the appropriate features for the token at the specifiedindexwith the specified array ofpreviousOutcomesto the specified list of features.longDeprecated.Cache statistics are no longer tracked.longDeprecated.Cache statistics are no longer tracked.voidupdateAdaptiveData(String[] tokens, String[] outcomes) Informs a feature generator that the specified tokens have been classified with the corresponding set of specifiedoutcomes.
-
Field Details
-
DISABLE_CACHE_PROPERTY
System property to disable the feature cache globally. Set to"true"to bypass caching (useful for benchmarking).- See Also:
-
generator
-
cacheEnabled
private final boolean cacheEnabled -
threadState
-
-
Constructor Details
-
CachedFeatureGenerator
Deprecated.UseCachedFeatureGenerator(AdaptiveFeatureGenerator)instead. -
CachedFeatureGenerator
-
-
Method Details
-
createFeatures
public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) Description copied from interface:AdaptiveFeatureGeneratorAdds the appropriate features for the token at the specifiedindexwith the specified array ofpreviousOutcomesto the specified list of features.- Specified by:
createFeaturesin interfaceAdaptiveFeatureGenerator- Parameters:
features- The list of features to be added to.tokens- The tokens of the sentence or other text unit being processed.index- The index of the token which is currently being processed.previousOutcomes- The outcomes for the tokens prior to the specified index.
-
updateAdaptiveData
Description copied from interface:AdaptiveFeatureGeneratorInforms a feature generator that the specified tokens have been classified with the corresponding set of specifiedoutcomes.- Specified by:
updateAdaptiveDatain interfaceAdaptiveFeatureGenerator- Parameters:
tokens- The tokens of the sentence or other text unit which has been processed.outcomes- The outcomes associated with the specified tokens.
-
clearAdaptiveData
public void clearAdaptiveData()Description copied from interface:AdaptiveFeatureGeneratorInforms a feature generator that the context of the adaptive data (typically a document) is no longer valid.- Specified by:
clearAdaptiveDatain interfaceAdaptiveFeatureGenerator
-
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
-
CachedFeatureGenerator(AdaptiveFeatureGenerator)instead.