DictionaryFeatureGenerator (Apache OpenNLP :: Core :: Runtime 3.0.0-M4 API)
Description: declaration: package: opennlp.tools.util.featuregen, class: DictionaryFeatureGenerator

Package opennlp.tools.util.featuregen

# Class DictionaryFeatureGenerator

java.lang.Object
opennlp.tools.util.featuregen.DictionaryFeatureGenerator

All Implemented Interfaces:
  `opennlp.tools.util.featuregen.AdaptiveFeatureGenerator`

@ThreadSafe public class DictionaryFeatureGenerator extends Object implements opennlp.tools.util.featuregen.AdaptiveFeatureGenerator
The `DictionaryFeatureGenerator` uses a `DictionaryNameFinder` to generate features for detected names based on the `InSpanGenerator`.

Thread safety: in normal use the underlying `InSpanGenerator` is configured once at construction time and never replaced, after which `createFeatures(java.util.List<java.lang.String>, java.lang.String[], int, java.lang.String[])` is safe to call from many threads concurrently (it delegates to a thread-safe `InSpanGenerator`). The `isg` field is `volatile` to give safe publication for both that one-shot constructor write and any later `setDictionary` call.

`setDictionary` replaces the in-flight dictionary; it is intended for setup time and is not for hot-path use while `createFeatures(java.util.List<java.lang.String>, java.lang.String[], int, java.lang.String[])` is running on other threads — it does not coordinate with in-flight reads beyond the volatile publish, so a caller racing dictionary replacement against feature generation may observe either the old or the new dictionary's features for any given call.

See Also:
  - `Dictionary`
  - `DictionaryNameFinder`
  - `InSpanGenerator`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DictionaryFeatureGenerator(String prefix, Dictionary dict)`
  Initializes a `DictionaryFeatureGenerator` with the specified parameters.
  `DictionaryFeatureGenerator(Dictionary dict)`
  Initializes a `DictionaryFeatureGenerator` with the specified `Dictionary`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes)`
  `void`
  `setDictionary(String name, Dictionary dict)`
  `void`
  `setDictionary(Dictionary dict)`

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

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

  ### Methods inherited from interface opennlp.tools.util.featuregen.AdaptiveFeatureGenerator

  `clearAdaptiveData, updateAdaptiveData`

- ## Constructor Details

  - ### DictionaryFeatureGenerator

    public DictionaryFeatureGenerator(Dictionary dict)
    Initializes a `DictionaryFeatureGenerator` with the specified `Dictionary`.
    Parameters:
      `dict` - The `Dictionary` to use. Must not be `null`.

  - ### DictionaryFeatureGenerator

    public DictionaryFeatureGenerator(String prefix, Dictionary dict)
    Initializes a `DictionaryFeatureGenerator` with the specified parameters.
    Parameters:
      `prefix` - The prefix to set. Must not be `null` but may be empty.
      `dict` - The `Dictionary` to use. Must not be `null`.

- ## Method Details

  - ### setDictionary

    public void setDictionary(Dictionary dict)

  - ### setDictionary

    public void setDictionary(String name, Dictionary dict)

  - ### createFeatures

    public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes)
    Specified by:
      `createFeatures` in interface `opennlp.tools.util.featuregen.AdaptiveFeatureGenerator`