1Hunspell(3) User Contributed Perl Documentation Hunspell(3)
2
3
4
6 Text::Hunspell - Perl interface to the GNU Hunspell library
7
9 # For this example to work, you have to have
10 # the US english dictionary installed!
11
12 use strict;
13 use warnings;
14
15 use Data::Dumper ();
16 use Text::Hunspell;
17
18 # You can use relative or absolute paths.
19 my $speller = Text::Hunspell->new(
20 "/usr/share/hunspell/en_US.aff", # Hunspell affix file
21 "/usr/share/hunspell/en_US.dic" # Hunspell dictionary file
22 );
23
24 die unless $speller;
25
26 # Check a word against the dictionary
27 my $word = 'opera';
28 print $speller->check($word)
29 ? "'$word' found in the dictionary\n"
30 : "'$word' not found in the dictionary!\n";
31
32 # Spell check suggestions
33 my $misspelled = 'programmng';
34 my @suggestions = $speller->suggest($misspelled);
35 print "\n", "You typed '$misspelled'. Did you mean?\n";
36 for (@suggestions) {
37 print " - $_\n";
38 }
39
40 # Analysis of a word
41 $word = 'automatic';
42 my $analysis = $speller->analyze($word);
43 print "\n", "Analysis of '$word' returns '$analysis'\n";
44
45 # Word stemming
46 $word = 'development';
47 my @stemming = $speller->stem($word);
48 print "\n", "Stemming of '$word' returns:\n";
49 for (@stemming) {
50 print " - $_\n";
51 }
52
53
54 #------------------------------------------
55 # ADVANCED STUFF FROM HERE
56 # NOT SURE HOW IT SHOULD WORK
57 #------------------------------------------
58
59 #
60 # Test here generator for morphological modification (NOM->ACC)
61 #
62 $word = 'developer';
63 my $stem = 'computer';
64 @suggestions = $speller->analyze($stem);
65 # Modify analyze output for required class (ACC)
66 for (@suggestions) {
67 s/NOM/ACC/g;
68 }
69 # Generate ACC class of stem
70 @suggestions = $speller->generate2($stem, \@suggestions);
71 print "Morphological modification generator...\n";
72 print Data::Dumper::Dumper(\@suggestions);
73
74
75 #
76 # Test generator for morphological modification,
77 # modify $stem like $word
78 #
79 @suggestions = $speller->generate($stem, $word);
80 print "Morphological modification generator...\n";
81 print Data::Dumper::Dumper(\@suggestions);
82
83 # Deletes the underlying Hunspell C/C++ object
84 $speller->delete($speller);
85
87 This module provides a Perl interface to the OO Hunspell library. This
88 module is to meet the need of looking up many words, one at a time, in
89 a single session, such as spell-checking a document in memory.
90
91 The example code describes the interface on http://hunspell.sf.net
92
94 You MUST have installed GNU Hunspell library version 1.0 or higher on
95 your system before installing this "Text::Hunspell" Perl module.
96
97 Hunspell location is:
98
99 http://hunspell.sf.net
100
101 There have been a number of bug reports because people failed to
102 install hunspell before installing this module.
103
104 This is an interface to the hunspell library installed on your system,
105 not a replacement for hunspell.
106
107 You must also have one hunspell dictionary installed when running the
108 module's test suite.
109
110 Also, please see the README and Changes files. README may have
111 specific information about your platform.
112
114 The following methods are available:
115
116 $speller = Text::Hunspell->new($full_path_to_affix, $full_path_to_dic);
117 Creates a new speller object. New takes the parameters
118 full_path_of_affix file and full_path_of_dic file Returns "undef"
119 if the object could not be created, which is unlikely.
120
121 Internally, new() creates the hunspell class.
122
123 $speller->check($word);
124 Check the word. Passes back 1, if the word found, 0 otherwise.
125
126 $speller->suggest($misspelled_word);
127 Passes back the list of suggestions for the misspelled word.
128
129 $speller->analyze($word);
130 Passes back the analyzis list for the word.
131
132 $speller->stem($word);
133 Passes back the stem list for the word.
134
135 $speller->generate2($stem, \@suggestions);
136 Passes back morphologically modified stem as defined in
137 @suggestions (got by analyzis)
138
139 $speller->generate($stem, $word);
140 Passes back morphologically modified stem like $word
141
142 $string = $speller->delete($speller);
143 deletes the speller class.
144
146 Probably. Yes, definitely.
147
149 This library is free software; you can redistribute it and/or modify it
150 under the same terms as Perl itself.
151
153 Eleonora, E<lt>eleonora46_at_gmx_dot_netE<gt>
154
155 Current maintainer is:
156
157 Cosimo Streppone, E<lt>cosimo@cpan.orgE<gt>
158
159 This module is based on a Text::Aspell written by Bill Moseley moseley
160 at hank dot org.
161
162 Hunspell is written as myspell by Kevin B. Hendricks, Hunspell is
163 maintained by Nemeth Laszlo.
164
165 Please see:
166
167 http://hunspell.sf.net
168
169 For the dictionaries:
170
171 http://lingucomponent.openoffice.org/spell_dic.html
172 http://magyarispell.sf.net for Hungarian dictionary
173
174
175
176perl v5.12.2 2010-09-08 Hunspell(3)