I cleaned up the raspell gem a little bit and put it on Rubyforge. It’s a Ruby interface to the GNU Aspell spellcheck library:
instalnation
Mac people:
sudo port install aspell aspell-dict-en
Or, Ubuntu people:
sudo apt-get install aspell libaspell-dev aspell-en
Then:
sudo gem install raspell
Of course you shouldn’t install the gem without trusting me and/or auditing the source code, and also making sure your DNS isn’t poisoned with regard to the Rubyforge mirrors, and that the Rubyforge mirrors themselves haven’t been hacked.
Yeah.
usige
The above spell.rb
file for your app:
require 'rubygems'
require 'raspell'
module Spell
SP = Aspell.new("en")
SP.suggestion_mode = Aspell::NORMAL
SP.set_option("ignore-case", "false")
def self.correct string
string.gsub(/[\w\']+/) do |word|
not SP.check(word) and SP.suggest(word).first or word
end
end
end
thuoghts
If you just need a “did you mean X” method, this is a great start. Of course sometimes Aspell gets it wrong. However, there are lots of options you can set, and different ways you can report the word possibilities, so you might be able to tune it to your specific situation.
Aspell supports custom wordlists and custom stemming and all kinds of cool stuff. Check the gem’s README
and Aspell’s manual for more details.
Very cool. Great to see a “did you mean X” example right away to get me started!
Very cool!
On my Mac I had to install it with
opt
directory specified:$ sudo gem in raspell -- --with-opt-dir=/opt/local
Likewise, Kent, today I had some troubles installing it on RHEL because the
aspell.h
header from/opt/aspell/include
wasn’t getting picked up.To anyone else having trouble, remember that for any extension gem, you can run the
gem install
and thencd
to the gem’s/ext
directory and handhold themake
process to get everything built.Wow, this looks just like the thing I need for Instiki.
Too bad that my RoR skills still suck.
Any chance that I could get you to create a lil’ howto on integrating this with Instiki?
I’ve never used Instiki… it shouldn’t be too hard to integrate, though. I would recommend hiring someone if you are not comfortable doing it yourself.