Class HunspellDictionary

java.lang.Object
opennlp.tools.stemmer.hunspell.HunspellDictionary

@ThreadSafe public final class HunspellDictionary extends Object
An immutable, in-memory Hunspell-format dictionary loaded from user-supplied .aff and .dic files. OpenNLP includes no dictionary data.

Supported affix features are PFX and SFX rules with strip strings, character-class conditions, cross-product combinations, and a double suffix connected by continuation classes; FLAG modes char, UTF-8, long, and num; the AF alias table; and the SET encoding declaration. Compound decomposition supports COMPOUNDFLAG, COMPOUNDBEGIN, COMPOUNDMIDDLE, COMPOUNDEND, COMPOUNDMIN, COMPOUNDWORDMAX, COMPOUNDPERMITFLAG, COMPOUNDFORBIDFLAG, CHECKCOMPOUNDDUP, CHECKCOMPOUNDCASE, and CHECKCOMPOUNDTRIPLE. The blocking flags NEEDAFFIX (also named PSEUDOROOT), ONLYINCOMPOUND, and FORBIDDENWORD, plus CIRCUMFIX and FULLSTRIP, are also applied.

Other directives are skipped. Their spelling, conversion, suggestion, or advanced compound behavior is not applied by this affix stemmer. Dictionary morphology fields are also ignored.

Instances are immutable and safe to share between threads.

Since:
3.0.0
See Also:
  • Field Details

  • Method Details

    • load

      public static HunspellDictionary load(Path affixFile, Path dictionaryFile) throws IOException
      Loads a dictionary from its two files.
      Parameters:
      affixFile - The .aff affix file. Must not be null.
      dictionaryFile - The .dic word list. Must not be null.
      Returns:
      The loaded dictionary. Never null.
      Throws:
      IOException - Thrown if reading fails or a file is malformed.
      IllegalArgumentException - Thrown if a parameter is null.
    • load

      public static HunspellDictionary load(InputStream affixStream, InputStream dictionaryStream) throws IOException
      Loads a dictionary from its two streams. Each stream is buffered up to MAX_STREAM_BYTES bytes; a larger stream fails with IOException.
      Parameters:
      affixStream - The .aff affix content. Must not be null. Not closed.
      dictionaryStream - The .dic word list content. Must not be null. Not closed.
      Returns:
      The loaded dictionary. Never null.
      Throws:
      IOException - Thrown if reading fails, a stream exceeds MAX_STREAM_BYTES, or the content is malformed.
      IllegalArgumentException - Thrown if a parameter is null.