Class HunspellStemmer

java.lang.Object
opennlp.tools.stemmer.hunspell.HunspellStemmer
All Implemented Interfaces:
opennlp.tools.stemmer.Stemmer

@ThreadSafe public final class HunspellStemmer extends Object implements opennlp.tools.stemmer.Stemmer
A dictionary-backed Stemmer over a HunspellDictionary: a surface form is reduced to the dictionary words it can be derived from by removing one suffix, one prefix, a cross-product combination of both, or an additional suffix licensed by a continuation class.

stem(CharSequence) returns the first analysis, preferring the word's own dictionary entry; stemAll(CharSequence) returns every distinct analysis. A word with no analysis is returned unchanged, so the stemmer degrades to identity on unknown vocabulary. A form containing uppercase characters is also analyzed in its lowercase variant, so sentence-initial capitalization does not hide an entry. Entries the dictionary marks as virtual stems (NEEDAFFIX), compound-only parts (ONLYINCOMPOUND), or forbidden words (FORBIDDENWORD) never count as standalone analyses, matching how hunspell reads those flags.

Compound part search is capped at 2048 part-licensing attempts per input word; beyond that budget further compound analyses are skipped. The Stemmer interface leaves thread safety to the implementation. This implementation reads only the immutable dictionary state, so a single instance is safe to share between threads.

Since:
3.0.0
  • Constructor Details

    • HunspellStemmer

      public HunspellStemmer(HunspellDictionary dictionary)
      Initializes the stemmer.
      Parameters:
      dictionary - The dictionary to analyze against. Must not be null.
      Throws:
      IllegalArgumentException - Thrown if dictionary is null.
  • Method Details

    • stem

      public CharSequence stem(CharSequence word)

      Returns the first analysis, which prefers the word's own dictionary entry.

      Specified by:
      stem in interface opennlp.tools.stemmer.Stemmer
    • stemAll

      public List<CharSequence> stemAll(CharSequence word)

      Returns every distinct analysis, or a single-element list of the unchanged word when it has none.

      Specified by:
      stemAll in interface opennlp.tools.stemmer.Stemmer