Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
add English spellcheck goodie with suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
crazedpsyc committed Jun 16, 2012
1 parent bb8a18e commit 830c780
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions dist.ini
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Convert::Color::Library = 0.03
Math::Round = 0.06 Math::Round = 0.06
Convert::Morse = 0.05 Convert::Morse = 0.05
Net::IDN::Encode = 2.003 Net::IDN::Encode = 2.003
Text::Aspell = 0.09


[Prereqs / TestRequires] [Prereqs / TestRequires]
Test::More = 0.98 Test::More = 0.98
Expand Down
20 changes: 20 additions & 0 deletions lib/DDG/Goodie/Spell.pm
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,20 @@
package DDG::Goodie::Spell;

use DDG::Goodie;
use Text::Aspell;

triggers start => "spell", "how to spell", "how do i spell", "spellcheck";

my $speller = Text::Aspell->new;
$speller->set_option('lang','en_US');
$speller->set_option('sug-mode','fast');

handle remainder => sub {
return unless /^[\w']+$/; # only accept letters and ' (aspell handles contractions)
my $correct = $speller->check($_) ? "'\u$_' appears to be spelled right!" : "'\u$_' does not appear to be spelled correctly.";
my @suggestions = $speller->suggest($_);
my $sug = @suggestions ? "Suggestions: " . join(', ', @suggestions[0..5]) : "No suggestions.";
return "$correct $sug", html => "$correct<br/>$sug";
};

1;

0 comments on commit 830c780

Please sign in to comment.