Ruby Spellchecker
Fast ruby spelling and grammar checker that can be used for autocorrection. Used by SiteInspector.
Installation
Add this line to your application's Gemfile:
gem 'ruby-spellchecker'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install ruby-spellchecker
Usage
Get list of errors
Spellchecker.check(text)
Autocorrection
text = "I started my schooling as the majority did in my area, at the local\nprimarry school. I then went to the local secondarry school and\nrecieved grades in English, Maths, Phisics, Biology, Geography,\nArt, Graphical Comunication and Philosophy of Religeon. I'll not\nbore you with the 'A' levels and above.\n\nNotice the ambigous English qualification above. It was, in truth,\na cource dedicated to reading \"Lord of the flies\" and other gems,\nand a weak atempt at getting us to commprehend them. Luckilly my\nmiddle-class upbringing gave me a head start as I was was already\naquainted with that sort of langauge these books used (and not just\nthe Peter and Jane books) and had read simillar books before. I will\nnever be able to put that paticular course down as much as I desire\nto because, for all its faults, it introduced me to Steinbeck,\nMalkovich and the wonders of Lenny, mice and pockets.\n\nMy education never included one iota of grammar. Lynn Truss points\nout in \"Eats, shoots and leaves\" that many people were excused from\nthe rigours of learning English grammar during their schooling over\nthe last 30 or so years because the majority or decision-makers\ndecided one day that it might hinder imagination and expresion (so\nwhat, I ask, happened to all those expresive and imaginative people\nbefore the ruling?).\n"
corrected = Spellchecker.correct(text)
Wdiff:
require 'wdiff'
Wdiff.diff(text, corrected)
Result:
I started my schooling as the majority did in my area, at the local
[-primarry-] {+primary+} school. I then went to the local [-secondarry-] {+secondary+} school and
[-recieved-] {+received+} grades in English, Maths, [-Phisics,-] {+Physics,+} Biology, Geography,
Art, Graphical Comunication and Philosophy of [-Religeon.-] {+Religion.+} I'll not
bore you with the 'A' levels and above.
Notice the [-ambigous-] {+ambiguous+} English qualification above. It was, in truth,
a [-cource-] {+course+} dedicated to reading "Lord of the flies" and other gems,
and a weak [-atempt-] {+attempt+} at getting us to [-commprehend-] {+comprehend+} them. [-Luckilly-] {+Luckily+} my
middle-class upbringing gave me a head start as I was [-was-] already
[-aquainted-] {+acquainted+} with that sort of [-langauge-] {+language+} these books used (and not just
the Peter and Jane books) and had read [-simillar-] {+similar+} books before. I will
never be able to put that [-paticular-] {+particular+} course down as much as I desire
to because, for all its faults, it introduced me to Steinbeck,
Malkovich and the wonders of Lenny, mice and pockets.
My education never included one iota of grammar. Lynn Truss points
out in "Eats, shoots and leaves" that many people were excused from
the rigours of learning English grammar during their schooling over
the last 30 or so years because the majority or decision-makers
decided one day that it might hinder imagination and [-expresion-] {+expression+} (so
what, I ask, happened to all those [-expresive-] {+expressive+} and imaginative people
before the ruling?).