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, options => $options)
76           Send either the text or a serialized object to the constructor.
77           Optionally, the language of the text can also be passed.  If no
78           language is passed, $ENV{LANG} will be used, if it is set.  If it
79           is not set, the default language will be "en_US".
80
81           $options are checker-specific options (see below).
82
83       $checker = new_from_frozen($serialized_data)
84           This is provided separately, so that it may be overridden for
85           alternative serialization techniques.
86
87       $str=$checker->serialize
88           Represent the object in its current state.
89
90       $checker->reset
91           Reset the checker to the beginning of the text, and clear the list
92           of ignored words.
93
94       $word = $checker->next_word
95           Returns the next misspelled word.
96
97       $checker->current_word
98           Returns the most recently returned word.
99
100       $checker->replace(new_word => $word)
101           Replace the current word with $word.
102
103       $checker->ignore_all
104           Ignore all subsequent occurences of the current word.
105
106       $checker->replace_all(new_word => $new_word)
107           Replace all subsequent occurences of the current word with a new
108           word.
109
110       $checker->suggestions
111           Returns a reference to a list of alternatives to the current word
112           in a scalar context, or the list directly in a list context.
113
114       $checker->text
115           Returns the current text (with corrections that have been applied).
116
117       $checker->highlighted_text
118           Returns the text, but with the current word surrounded by
119           $Text::SpellChecker::pre_hl_word and
120           $Text::SpellChecker::post_hl_word.
121
122       $checker->set_options
123           Set checker-specific options.  Currently only aspell supports
124           setting options, e.g.
125
126               $checker->set_options(aspell => { "extra-dicts" => "nl" } );
127

CONFIGURATION OPTIONS

129       $Text::SpellChecker::pre_hl_word
130           Set this to control the highlighting of a misspelled word.
131
132       $Text::SpellChecker::post_hl_word
133           Set this to control the highlighting of a misspelled word.
134
135       $Text::SpellCheckerDictionaryPath{Hunspell}
136           Set this to the hunspell dictionary path.  By default
137           /usr/share/myspell.
138
139           This directory should have $lang.dic and $lang.aff files.
140

LICENSE

142       This library is free software; you can redistribute it and/or modify it
143       under the same terms as Perl itself.
144

TODO

146       Add word to custom dictionary
147

SEE ALSO

149       Text::Aspell, Text::Hunspell
150

AUTHOR

152       Brian Duggan <bduggan@matatu.org>
153
154
155
156perl v5.28.1                      2019-02-02             Text::SpellChecker(3)
Impressum