Add the following code to your project's shard.yml under:
dependencies
to use in production
- OR -
development_dependencies
to use in development
Crystal bindings for Hunspell.
Before installing crystal-hunspell
ensure you have hunspell already installed:
Add the dependency to your shard.yml
:
dependencies:
hunspell:
github: mamantoha/crystal-hunspell
Run shards install
require "hunspell"
Open a dictionary:
hunspell = Hunspell.new("/usr/share/hunspell/en_US.aff", "/usr/share/hunspell/en_US.dic")
or
hunspell = Hunspell.new("en_US")
Check if a word is valid:
hunspell.spellcheck("crystal")
# => true
hunspell.spellcheck("cristal")
# => false
Find the stems of a word:
hunsell.stem("fishing")
# => ["fishing", "fish"]
Suggest alternate spellings for a word:
hunspell.suggest("arbitrage")
# => ["arbitrage", "arbitrages", "arbitrager", "arbitraged", "arbitrate"]
Ensure to close Hunspell
instance after using.
hunspell.close
sudo apt install libclang-dev libhunspell-dev
Generate new bindings for Hunspell
crystal ./lib/crystal_lib/src/main.cr src/hunspell/lib_hunspell.cr.in > src/hunspell/lib_hunspell.cr
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)