1Hunspell(3) User Contributed Perl Documentation Hunspell(3)
2
3
4
6 Text::Hunspell - Perl interface to the Hunspell library
7
9 use Text::Hunspell;
10
11 # You can use relative or absolute paths.
12 my $speller = Text::Hunspell->new(
13 "/usr/share/hunspell/en_US.aff", # Hunspell affix file
14 "/usr/share/hunspell/en_US.dic" # Hunspell dictionary file
15 );
16
17 die unless $speller;
18
19 # Check a word against the dictionary
20 my $word = 'opera';
21 print $speller->check($word)
22 ? "'$word' found in the dictionary\n"
23 : "'$word' not found in the dictionary!\n";
24
25 # Spell check suggestions
26 my $misspelled = 'programmng';
27 my @suggestions = $speller->suggest($misspelled);
28 print "\n", "You typed '$misspelled'. Did you mean?\n";
29 for (@suggestions) {
30 print " - $_\n";
31 }
32
33 # Add dictionaries later
34 $speller->add_dic('dictionary_file.dic');
35
37 This module provides a Perl interface to the Hunspell library. This
38 module is to meet the need of looking up many words, one at a time, in
39 a single session, such as spell-checking a document in memory.
40
41 The example code describes the interface on http://hunspell.sf.net
42
44 You MUST have installed the Hunspell library version 1.0 or higher on
45 your system before installing this "Text::Hunspell" Perl module.
46
47 Hunspell location is:
48
49 http://hunspell.sf.net
50
51 There have been a number of bug reports because people failed to
52 install hunspell before installing this module.
53
54 This is an interface to the hunspell library installed on your system,
55 not a replacement for hunspell.
56
57 You must also have one hunspell dictionary installed when running the
58 module's test suite.
59
60 Also, please see the README and Changes files. README may have
61 specific information about your platform.
62
64 The following methods are available:
65
66 Text::Hunspell->new($full_path_to_affix, $full_path_to_dic)
67 Creates a new speller object. Parameters are:
68
69 full path of affix (.aff) file
70 full path of dictionary (.dic) file
71
72 Returns "undef" if the object could not be created, which is unlikely.
73
74 add_dic($path_to_dic)
75 Adds a new dictionary to the current "Text::Hunspell" object. This
76 dictionary will use the same affix file as the original dictionary, so
77 this is like using a personal word list in a given language. To check
78 spellings in several different languages, use multiple "Text::Hunspell"
79 objects.
80
81 check($word)
82 Check the word. Returns 1 if the word is found, 0 otherwise.
83
84 suggest($misspelled_word)
85 Returns the list of suggestions for the misspelled word.
86
87 The following methods are used for morphological analysis, which is
88 looking at the structure of words; parts of speech, inflectional
89 suffixes and so on. However, most of the dictionaries that Hunspell
90 can use are missing this information and only contain affix flags which
91 allow, for example, 'cat' to turn into 'cats' but not 'catability'.
92 (Users of the French and Hungarian dictionaries will find that they
93 have more information available.)
94
95 analyze($word)
96 Returns the analysis list for the word. This will be a list of strings
97 that contain a stem word and the morphological information about the
98 changes that have taken place from the stem. This will most likely be
99 'fl:X' strings that indicate that affix flag 'X' was applied to the
100 stem. Words may have more than one stem, and each one will be returned
101 as a different item in the list.
102
103 However, with a French dictionary loaded, analyze('chanson') will
104 return
105
106 st:chanson po:nom is:fem is:sg
107
108 to tell you that "chanson" is a feminine singular noun, and
109 analyze('chansons') will return
110
111 st:chanson po:nom is:fem is:pl
112
113 to tell you that you've analyzed the plural of the same noun.
114
115 stem($word)
116 Returns the stem list for the word. This is a simpler version of the
117 results from analyze().
118
119 generate2($stem, \@suggestions)
120 Returns a morphologically modified stem as defined in @suggestions (got
121 by analysis).
122
123 With a French dictionary:
124
125 $feminine_form = 'chanteuse';
126 @ana = $speller->analyze($feminine_form);
127 $ana[0] =~ s/is:fem/is:mas/;
128 print $speller->generate2($feminine_form, \@ana)
129
130 will print 'chanteur'.
131
132 generate($stem, $word)
133 Returns morphologically modified stem like $word.
134
135 $french_speller->generate('danseuse', 'chanteur');
136
137 tells us that the masculine form of 'danseuse' is 'danseur'.
138
140 Note that Hunspell dictionaries often come in non-UTF-8 encodings. If
141 your code uses UTF-8, you need to encode the strings into the needed
142 encoding. For example Czech (files "cs_CZ.dic" and "cs_CZ.aff") uses
143 ISO-8859-2:
144
145 use utf8;
146 use Encode;
147
148 print $speller->check(encode('ISO-8859-2', "žluťoučký"))
149 ? "found.\n"
150 : "not found.\n";
151 }
152
154 Probably. Yes, definitely.
155
157 This library is free software; you can redistribute it and/or modify it
158 under the same terms as Perl itself.
159
161 Originally written by Eleonora, <eleonora46_at_gmx_dot_net>.
162
163 The current maintainer is Cosimo Streppone, <cosimo@cpan.org>
164
165 This module is based on Text::Aspell written by Bill Moseley moseley at
166 hank dot org.
167
168 Hunspell is written as myspell by Kevin B. Hendricks.
169
170 Hunspell is maintained by Németh László.
171
172 Please see:
173
174 http://hunspell.sf.net
175
176 For the dictionaries:
177
178 https://wiki.openoffice.org/wiki/Dictionaries
179 http://magyarispell.sf.net for Hungarian dictionary
180
181
182
183perl v5.38.0 2023-07-21 Hunspell(3)