Skip to content

postmodern/hunspell.cr

Repository files navigation

hunspell.cr

Crystal bindings for Hunspell. Crystal port of the Ruby ffi-hunspell gem and should be API compatible.

Installation

  1. Install libhunspell

    • Debian / Ubuntu:

      $ sudo apt install libhunspell-dev hunspell-en-us
      
    • RedHat / Fedora:

      $ sudo dnf install hunspell-devel hunspell-en
      
    • macOS:

      $ brew install hunspell
      
  2. Add the dependency to your shard.yml:

    dependencies:
      hunspell:
        github: your-github-user/hunspell.cr
  3. Run shards install

Examples

Open a dictionary:

require "hunspell"
    
Hunspell.dict do |dict|
  # ...
end

Hunspell.dict("en_GB") do |dict|
  # ...
end

dict = Hunspell.dict("en_GB")
# ...
dict.close

Check if a word is valid:

dict.check?("dog")
# => true

dict.check?("d0g")
# => false

Find the stems of a word:

dict.stem("dogs")
# => ["dog"]

Suggest alternate spellings for a word:

dict.suggest("arbitrage")
# => ["arbitrage", "arbitrages", "arbitrager", "arbitraged", "arbitrate"]

Development

After installing libhunspell (see Installation):

$ shards install
$ crystal spec

Contributing

  1. Fork it (https://github.com/postmodern/hunspell.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

About

Crystal bindings for libhunspell. Crystal port of the Ruby ffi-hunspell gem.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project