Class DictionaryFeatureGenerator
- All Implemented Interfaces:
AdaptiveFeatureGenerator
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:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDictionaryFeatureGenerator(String prefix, Dictionary dict) Initializes aDictionaryFeatureGeneratorwith the specified parameters.Initializes aDictionaryFeatureGeneratorwith the specifiedDictionary. -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateFeatures(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.voidsetDictionary(String name, Dictionary dict) voidsetDictionary(Dictionary dict) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface opennlp.tools.util.featuregen.AdaptiveFeatureGenerator
clearAdaptiveData, updateAdaptiveData
-
Field Details
-
isg
-
-
Constructor Details
-
DictionaryFeatureGenerator
Initializes aDictionaryFeatureGeneratorwith the specifiedDictionary.- Parameters:
dict- TheDictionaryto use. Must not benull.
-
DictionaryFeatureGenerator
Initializes aDictionaryFeatureGeneratorwith the specified parameters.- Parameters:
prefix- The prefix to set. Must not benullbut may be empty.dict- TheDictionaryto use. Must not benull.
-
-
Method Details
-
setDictionary
-
setDictionary
-
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.
-