CachedFeatureGenerator (Apache OpenNLP Tools 1.9.5 API)
Date: 2026-06-18

opennlp.tools.util.featuregen

## Class CachedFeatureGenerator

- java.lang.Object
- - opennlp.tools.util.featuregen.CachedFeatureGenerator

- All Implemented Interfaces:
    AdaptiveFeatureGenerator

      public class CachedFeatureGenerator
      extends Object
      implements AdaptiveFeatureGenerator

  Caches features of the aggregated `AdaptiveFeatureGenerator`s.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CachedFeatureGenerator(AdaptiveFeatureGenerator... generators)` Deprecated.
    `CachedFeatureGenerator(AdaptiveFeatureGenerator generator)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clearAdaptiveData()` Informs the feature generator that the context of the adaptive data (typically a document) is no longer valid.
    `void` | `createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes)` Adds the appropriate features for the token at the specified index with the specified array of previous outcomes to the specified list of features.
    `AdaptiveFeatureGenerator` | `getCachedFeatureGenerator()`
    `long` | `getNumberOfCacheHits()` Retrieves the number of times a cache hit occurred.
    `long` | `getNumberOfCacheMisses()` Retrieves the number of times a cache miss occurred.
    `String` | `toString()`
    `void` | `updateAdaptiveData(String[] tokens, String[] outcomes)` Informs the feature generator that the specified tokens have been classified with the corresponding set of specified outcomes.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### CachedFeatureGenerator

          @Deprecated
          public CachedFeatureGenerator(AdaptiveFeatureGenerator... generators)

      Deprecated.

    - #### CachedFeatureGenerator

          public CachedFeatureGenerator(AdaptiveFeatureGenerator generator)

  - ### Method Detail

    - #### createFeatures

          public void createFeatures(List<String> features,
                                     String[] tokens,
                                     int index,
                                     String[] previousOutcomes)

      Description copied from interface: `AdaptiveFeatureGenerator`
      Adds the appropriate features for the token at the specified index with the specified array of previous outcomes to the specified list of features.
      Specified by:
        `createFeatures` in interface `AdaptiveFeatureGenerator`
      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

          public void updateAdaptiveData(String[] tokens,
                                         String[] outcomes)

      Description copied from interface: `AdaptiveFeatureGenerator`
      Informs the feature generator that the specified tokens have been classified with the corresponding set of specified outcomes.
      Specified by:
        `updateAdaptiveData` in interface `AdaptiveFeatureGenerator`
      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: `AdaptiveFeatureGenerator`
      Informs the feature generator that the context of the adaptive data (typically a document) is no longer valid.
      Specified by:
        `clearAdaptiveData` in interface `AdaptiveFeatureGenerator`

    - #### getNumberOfCacheHits

          public long getNumberOfCacheHits()

      Retrieves the number of times a cache hit occurred.
      Returns:
        number of cache hits

    - #### getNumberOfCacheMisses

          public long getNumberOfCacheMisses()

      Retrieves the number of times a cache miss occurred.
      Returns:
        number of cache misses

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### getCachedFeatureGenerator

          public AdaptiveFeatureGenerator getCachedFeatureGenerator()

Copyright © 2026 The Apache Software Foundation. All rights reserved.