Package opennlp.tools.postag

# Class ConfigurablePOSContextGenerator

java.lang.Object
opennlp.tools.postag.ConfigurablePOSContextGenerator

All Implemented Interfaces:
  `opennlp.tools.postag.POSContextGenerator`, `opennlp.tools.util.BeamSearchContextGenerator<String>`

@ThreadSafe public class ConfigurablePOSContextGenerator extends Object implements opennlp.tools.postag.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:
  - `POSTagger`
  - `POSTaggerME`
  - `DefaultPOSContextGenerator`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ConfigurablePOSContextGenerator(int cacheSize, opennlp.tools.util.featuregen.AdaptiveFeatureGenerator featureGenerator)`
  Initializes a `ConfigurablePOSContextGenerator` instance with an optional per-thread context cache.
  `ConfigurablePOSContextGenerator(opennlp.tools.util.featuregen.AdaptiveFeatureGenerator featureGenerator)`
  Initializes a `ConfigurablePOSContextGenerator` instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String[]`
  `getContext(int index, String[] tokens, String[] tags, Object[] additionalContext)`

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

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

- ## Constructor Details

  - ### ConfigurablePOSContextGenerator

    public ConfigurablePOSContextGenerator(opennlp.tools.util.featuregen.AdaptiveFeatureGenerator featureGenerator)
    Initializes a `ConfigurablePOSContextGenerator` instance. A cache size of `0` will be used as default.
    Parameters:
      `featureGenerator` - The `AdaptiveFeatureGenerator` to be used.

  - ### ConfigurablePOSContextGenerator

    public ConfigurablePOSContextGenerator(int cacheSize, opennlp.tools.util.featuregen.AdaptiveFeatureGenerator featureGenerator)
    Initializes a `ConfigurablePOSContextGenerator` instance with an optional per-thread context cache.
    Parameters:
      `cacheSize` - The size of the per-thread context cache. Use `0` to disable caching.
      `featureGenerator` - The `AdaptiveFeatureGenerator` to be used.

- ## Method Details

  - ### getContext

    public String[] getContext(int index, String[] tokens, String[] tags, Object[] additionalContext)
    Specified by:
      `getContext` in interface `opennlp.tools.util.BeamSearchContextGenerator<String>`
    Specified by:
      `getContext` in interface `opennlp.tools.postag.POSContextGenerator`