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:
  • Constructor Details

  • 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