This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add English spellcheck goodie with suggestions
- Loading branch information
1 parent
bb8a18e
commit 830c780
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |