Class Hunspell

  • public class Hunspell
    extends Object
    A spell checker based on Hunspell dictionaries. This class can be used in place of native Hunspell for many languages for spell-checking and suggesting purposes. Note that not all languages are supported yet. For example:
    • Hungarian (as it doesn't only rely on dictionaries, but has some logic directly in the source code
    • Languages with Unicode characters outside of the Basic Multilingual Plane
    • PHONE affix file option for suggestions

    The objects of this class are thread-safe.

    • Constructor Detail

      • Hunspell

        public Hunspell​(Dictionary dictionary)
      • Hunspell

        public Hunspell​(Dictionary dictionary,
                        TimeoutPolicy policy,
                        Runnable checkCanceled)
        policy - a strategy determining what to do when API calls take too much time
        checkCanceled - an object that's periodically called, allowing to interrupt spell-checking or suggestion generation by throwing an exception
    • Method Detail

      • spell

        public boolean spell​(String word)
        whether the given word's spelling is considered correct according to Hunspell rules
      • getRoots

        public List<String> getRoots​(String word)
        Find all roots that could result in the given word after case conversion and adding affixes. This corresponds to the original hunspell -s (stemming) functionality.

        Some affix rules are relaxed in this stemming process: e.g. explicitly forbidden words are still returned. Some of the returned roots may be synthetic and not directly occur in the *.dic file (but differ from some existing entries in case). No roots are returned for compound words.

        The returned roots may be used to retrieve morphological data via Dictionary.lookupEntries(java.lang.String).