View Source SpellChecker

A small Elixir library for checking English word spelling against a bundled ~70k-word dictionary, with suggestions, autocorrect, custom dictionaries, and whole-text checking.

Installation

The package can be installed by adding spell_checker to your list of dependencies in mix.exs:

def deps do
  [
    {:spell_checker, "~> 0.2.0"}
  ]
end

Documentation can be found at https://hexdocs.pm/spell_checker.

Usage

SpellChecker.is_correct("hello")
# {:ok, true}

SpellChecker.is_correct?(["hello", "worlld", "Programming"])
# ["Programming", "hello"]

SpellChecker.is_correct!("worlld")
# ["world", "worldly", "worlds", "wold", "word"]

SpellChecker.correct("Helo")
# {:corrected, "Hello"}

SpellChecker.check_text("hello wrold")
# [{"wrold", ["wold", "world", "worlds", "would", "word"]}]

# Extend the dictionary with your own words (kept for the life of the node)
SpellChecker.add_words(["hexdocs", "genserver"])
SpellChecker.is_correct("GenServer")
# {:ok, true}

SpellChecker.clear_custom_words()

# Or swap the bundled dictionary out entirely, e.g. for another language
SpellChecker.load_dictionary!(["ola", "bawo", "pele"])

The dictionary is read from disk once and cached in memory (via :persistent_term) for the life of the running node, so repeated lookups are cheap.