Class MorfologikTagDictionary

java.lang.Object
opennlp.morfologik.tagdict.MorfologikTagDictionary
All Implemented Interfaces:
TagDictionary

public class MorfologikTagDictionary extends Object implements TagDictionary
A TagDictionary implementation based on Morfologik binary dictionaries.

This implementation is thread-safe: the immutable Dictionary is shared and each thread looks words up through its own DictionaryLookup, held in a ThreadLocal, as DictionaryLookup instances are stateful and must not be used concurrently. Call clearThreadLocalState() to release the lookup of the current thread.

  • Field Details

    • dictLookup

      private final ThreadLocal<morfologik.stemming.IStemmer> dictLookup
    • isCaseSensitive

      private final boolean isCaseSensitive
  • Constructor Details

    • MorfologikTagDictionary

      public MorfologikTagDictionary(morfologik.stemming.Dictionary dict) throws IllegalArgumentException
      Initializes a case sensitive MorfologikTagDictionary
      Parameters:
      dict - A Morfologik FSA Dictionary.
      Throws:
      IllegalArgumentException - Thrown if FSA's root node cannot be acquired (dictionary is empty).
    • MorfologikTagDictionary

      public MorfologikTagDictionary(morfologik.stemming.Dictionary dict, boolean caseSensitive) throws IllegalArgumentException
      Parameters:
      dict - A Morfologik FSA Dictionary.
      caseSensitive - If true it performs case-sensitive lookup
      Throws:
      IllegalArgumentException - Thrown if FSA's root node cannot be acquired (dictionary is empty).
  • Method Details

    • getTags

      public String[] getTags(String word)
      Description copied from interface: TagDictionary
      Retrieves a list of valid tags for the specified word.
      Specified by:
      getTags in interface TagDictionary
      Parameters:
      word - The word.
      Returns:
      An array of valid tags for the specified word or null if no information is available for that word.
    • isCaseSensitive

      public boolean isCaseSensitive()
      Description copied from interface: TagDictionary
      Whether the dictionary is case-sensitive or not.
      Specified by:
      isCaseSensitive in interface TagDictionary
      Returns:
      true if the dictionary is case-sensitive, else false.
    • clearThreadLocalState

      public void clearThreadLocalState()
      Removes the DictionaryLookup of the current thread to prevent classloader leaks in container environments. Call when the thread is returned to a pool or the dictionary is no longer needed; a later lookup on the same thread creates a new one.