1Text::SpellChecker(3) User Contributed Perl DocumentationText::SpellChecker(3)
2
3
4

NAME

6       Text::SpellChecker - OO interface for spell-checking a block of text
7

SYNOPSIS

9           use Text::SpellChecker;
10           ($Text::SpellChecker::pre_hl_word,
11            $Text::SpellChecker::post_hl_word) = (qw([ ]));
12
13           my $checker = Text::SpellChecker->new(text => "Foor score and seven yeers ago");
14
15           while (my $word = $checker->next_word) {
16               print $checker->highlighted_text,
17                   "\n",
18                   "$word : ",
19                   (join "\t", @{$checker->suggestions}),
20                   "\nChoose a new word : ";
21               chomp (my $new_word = <STDIN>);
22               $checker->replace(new_word => $new_word) if $new_word;
23           }
24
25           print "New text : ".$checker->text."\n";
26
27       --or--
28
29           use CGI;
30           use Text::SpellChecker;
31           my $q = new CGI;
32           print $q->header,
33                 $q->start_html,
34                 $q->start_form(-method=>'POST',-action=>$ENV{SCRIPT_NAME});
35
36           my $checker = Text::SpellChecker->new(
37               text => "Foor score and seven yeers ago",
38               from_frozen => $q->param('frozen') # will be false the first time.
39           );
40
41           $checker->replace(new_word => $q->param('replacement'))
42               if $q->param('replace');
43
44           if (my $word = $checker->next_word) {
45               print $q->p($checker->highlighted_text),
46                   $q->br,
47                   qq|Next word : "$word"|,
48                   $q->br,
49                   $q->submit(-name=>'replace',-value=>'replace with:'),
50                   $q->popup_menu(-name=>'replacement',-values=>$checker->suggestions),
51                   $q->submit(-name=>'skip');
52           } else {
53               print "Done.  New text : ".$checker->text;
54           }
55
56           print $q->hidden(-name => 'frozen',
57                            -value => $checker->serialize,
58                            -override => 1),
59                 $q->end_form,
60                 $q->end_html;
61

DESCRIPTION

63       This module is a thin layer above either Text::Aspell or Text::Hunspell
64       (preferring the latter if available), and allows one to spellcheck a
65       body of text.
66
67       Whereas Text::(Hu|A)spell deals with words, Text::Spellchecker deals
68       with blocks of text.  For instance, we provide methods for iterating
69       through the text, serializing the object (thus remembering where we
70       left off), and highlighting the current misspelled word within the
71       text.
72

METHODS

74       $checker = Text::SpellChecker->new(text => $text, from_frozen =>
75       $serialized_data, lang => $lang)
76           Send either the text or a serialized object to the constructor.
77           Optionally, the language of the text can also be passed.
78
79       $checker = new_from_frozen($serialized_data)
80           This is provided separately, so that it may be overridden for
81           alternative serialization techniques.
82
83       $str=$checker->serialize
84           Represent the object in its current state.
85
86       $checker->reset
87           Reset the checker to the beginning of the text, and clear the list
88           of ignored words.
89
90       $word = $checker->next_word
91           Returns the next misspelled word.
92
93       $checker->current_word
94           Returns the most recently returned word.
95
96       $checker->replace(new_word => $word)
97           Replace the current word with $word.
98
99       $checker->ignore_all
100           Ignore all subsequent occurences of the current word.
101
102       $checker->replace_all(new_word => $new_word)
103           Replace all subsequent occurences of the current word with a new
104           word.
105
106       $checker->suggestions
107           Returns a reference to a list of alternatives to the current word
108           in a scalar context, or the list directly in a list context.
109
110       $checker->text
111           Returns the current text (with corrections that have been applied).
112
113       $checker->highlighted_text
114           Returns the text, but with the current word surrounded by
115           $Text::SpellChecker::pre_hl_word and
116           $Text::SpellChecker::post_hl_word.
117

CONFIGURATION OPTIONS

119       $Text::SpellChecker::pre_hl_word
120           Set this to control the highlighting of a misspelled word.
121
122       $Text::SpellChecker::post_hl_word
123           Set this to control the highlighting of a misspelled word.
124
125       $Text::SpellCheckerDictionaryPath{Hunspell}
126           Set this to the hunspell dictionary path.  By default
127           /usr/share/myspell.
128
129           This directory should have $lang.dic and $lang.aff files.
130

LICENSE

132       This library is free software; you can redistribute it and/or modify it
133       under the same terms as Perl itself.
134

TODO

136       Add word to custom dictionary
137

SEE ALSO

139       Text::Aspell, Text::Hunspell
140

AUTHOR

142       Brian Duggan <bduggan@matatu.org>
143

POD ERRORS

145       Hey! The above document had some coding errors, which are explained
146       below:
147
148       Around line 129:
149           You forgot a '=back' before '=head1'
150
151       Around line 131:
152           '=item' outside of any '=over'
153
154
155
156perl v5.12.2                      2010-10-04             Text::SpellChecker(3)
Impressum