I am looking for a relatively quick way to check whether words are misspelled, either using a gem or API.
I’ve tried using several gems — raspell, ffi-aspell, hunspell-ffi, spell_cheker, and spellchecker — and each has a different error.
I’m pretty new to ruby and hoping for a simple solution (I’m processing a lot of short text files and want to calculate the % of words mis-spelled) that doesn’t include building something from scratch.
When trying ffi-aspell, I get the following error:
/Users/ntaylorthompson/.rvm/gems/ruby-1.9.2-p320/gems/ffi-aspell-0.0.3/lib/ffi/aspell/speller.rb:121: [BUG] Segmentation fault
ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-darwin11.4.0]
-- control frame ----------
c:0005 p:---- s:0019 b:0019 l:000018 d:000018 CFUNC :speller_check
c:0004 p:0113 s:0013 b:0013 l:000012 d:000012 METHOD /Users/ntaylorthompson/.rvm/gems/ruby-1.9.2-p320/gems/ffi-aspell-0.0.3/lib/ffi/aspell/speller.rb:121
c:0003 p:0049 s:0007 b:0007 l:0005a8 d:0005d0 EVAL ffi-aspell_test.rb:5
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:0005a8 d:0005a8 TOP
---------------------------
-- Ruby level backtrace information ----------------------------------------
ffi-aspell_test.rb:5:in `<main>'
/Users/ntaylorthompson/.rvm/gems/ruby-1.9.2-p320/gems/ffi-aspell-0.0.3/lib/ffi/aspell/speller.rb:121:in `correct?'
/Users/ntaylorthompson/.rvm/gems/ruby-1.9.2-p320/gems/ffi-aspell-0.0.3/lib/ffi/aspell/speller.rb:121:in `speller_check'
-- C level backtrace information -------------------------------------------
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
Abort trap: 6
I’d appreciate either (1) a suggestion of an alternative approach to those above or (2) a recommendation of which to use of the 5 gems above — so I can at least spend time debugging the best option.
raspell is no longer maintained, so ffi-aspell is a good option if you have the libaspell headers available.
If you can’t get the libraries to work, you can just shell out to the
aspellbinary. The following method will do just that (unit tests included):spellcheck()assumes you havecat,wc, andaspellon your path, and that the default dictionary is what you want to use. The unit test is for Ruby 1.9 only — if you’re running 1.8, just delete it.