Haskell implementation (outlined in a blog post) of the simple spelling corrector spell.py
by Peter Norvig, which he describes in detail in the excellent essay "How to Write a Spelling Corrector". Any credit should go to him!
git clone https://github.com/doersino/spell.git
cd spell
cabal sandbox init
cabal install
If you prefer using Stack, run stack install
instead of that Cabal nonsense.
For taking a first look, run cabal repl
or stack ghci
. Some examples:
*Spell> correction "scandinaiva"
"scandinavia"
*Spell> correction "inndeed"
"indeed"
*Spell> correction "photograf"
"photograph"
- Performance is somewhat lacking. If you manage to significantly improve performance or reduce dependencies without major structural modifications (or just add more unit tests), please don't hesitate before filing an issue or sending a pull request.
- Haskell is lazy, so it won't parse the
big.txt
file until you callcorrection
. As a result, the first correction might take a few seconds -- subsequent ones will be faster. - If you want, you can use this Cabal package as a dependency in your project (of course, there are better spell checkers). Since it's not on Hackage, run
cabal sandbox add-source <path to local clone of spell package>
in your project directory before addingspell
to thebuild-depends
list in your.cabal
file. - In case you modify or replace
big.txt
: the changes may not take effect until you re-runcabal install
. That's because it's listed in thedata-files
field ofspell.cabal
, enabling Cabal to provide an absolute path tobig.txt
at runtime, which is helpful if you want to use thespell
package as a library or from any path on your system. - If you want to be able to run the included Hspec unit tests, replace the
cabal install
step above withcabal install --enable-tests
. Run the tests by means ofcabal test
or, for incremental and more colorful output,cabal exec -- runhaskell -isrc -itest test/Spec.hs
. If you're using Stack, simply runstack test
. - Run
cabal haddock
orstack haddock
to generate documentation.