7 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
8 |
|
|
9 |
use Exporter; |
use Exporter; |
10 |
$VERSION = '0.01'; |
$VERSION = '0.02'; |
11 |
@ISA = ('Exporter'); |
@ISA = ('Exporter'); |
12 |
|
|
13 |
#@EXPORT = qw(); |
#@EXPORT = qw(); |
14 |
@EXPORT_OK = qw( |
@EXPORT_OK = qw( |
15 |
&alternatives |
&alternatives |
|
&load_affix |
|
16 |
); |
); |
17 |
|
|
18 |
my $debug=0; |
my $debug=0; |
151 |
return @out; |
return @out; |
152 |
} |
} |
153 |
|
|
154 |
|
# |
155 |
|
# function which return minimal word of all alternatives |
156 |
|
# |
157 |
|
|
158 |
|
sub minimal { |
159 |
|
my $self = shift; |
160 |
|
my @out; |
161 |
|
foreach my $word (@_) { |
162 |
|
my @alt = $self->alternatives($word); |
163 |
|
my $minimal = shift @alt; |
164 |
|
foreach (@alt) { |
165 |
|
$minimal=$_ if (length($_) < length($minimal)); |
166 |
|
} |
167 |
|
push @out,$minimal; |
168 |
|
} |
169 |
|
return @out; |
170 |
|
} |
171 |
|
|
172 |
############################################################################### |
############################################################################### |
173 |
1; |
1; |
174 |
__END__ |
__END__ |
179 |
|
|
180 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
181 |
|
|
182 |
use Lingua::Spelling:Alternative; |
use Lingua::Spelling::Alternative; |
183 |
|
|
184 |
my $en = new Alternative; |
my $en = new Lingua::Spelling::Alternative; |
185 |
$en->load_affix('/usr/lib/ispell/english.aff') or die $!; |
$en->load_affix('/usr/lib/ispell/default.aff') or die $!; |
186 |
print $en->alternatives("cars"); |
print join(" ",$en->alternatives("cars")),"\n"; |
187 |
|
|
188 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
189 |
|
|
190 |
This module is designed to return all valid forms of a given word |
This module is designed to return all forms of a given word |
191 |
(for example when you want to see all possible forms of some word |
(for example when you want to see all possible forms of some word |
192 |
entered in search engine) |
entered in search engine) which can be generated using affix file (from |
193 |
|
ispell) or using findaffix output file (also part of ispell package) |
194 |
|
|
195 |
=head1 PUBLIC METHODS |
=head1 PUBLIC METHODS |
196 |
|
|
198 |
|
|
199 |
=item new |
=item new |
200 |
|
|
201 |
The new() constructor (without parameters) create container for new |
The new() constructor (without parameters) create container for new language. |
202 |
language. |
Only parameter it supports is DEBUG which turns on (some) debugging output. |
|
Only parametar it supports is DEBUG which turns on (some) debugging |
|
|
output. |
|
203 |
|
|
204 |
=item load_affix |
=item load_affix |
205 |
|
|
206 |
Function load_affix loads ispell's affix file. |
Function load_affix() loads ispell's affix file for later usage. |
207 |
|
|
208 |
|
=item load_findaffix |
209 |
|
|
210 |
|
This function loads output of findaffix program from ispell package. |
211 |
|
This is better idea (if you are creating affix file for particular language |
212 |
|
yourself or you can get your hands on one) because affix file from ispell |
213 |
|
is limited to 26 entries (because each entry is denoted by single character). |
214 |
|
|
215 |
=item alternatives |
=item alternatives |
216 |
|
|
217 |
Function alternatives |
Function alternatives return array of all alternative spellings of particular |
218 |
|
word(s). It will also return spelling which are not correct if there is |
219 |
|
rule like that in affix file. |
220 |
|
|
221 |
|
=item minimal |
222 |
|
|
223 |
|
This function returns minimal of all alternatives of a given word(s). It's |
224 |
|
a poor man's version of normalize (because we don't know grammatic of |
225 |
|
particular language, just some spelling rules). |
226 |
|
|
227 |
|
=back |
228 |
|
|
229 |
=head1 PRIVATE METHODS |
=head1 PRIVATE METHODS |
230 |
|
|
237 |
|
|
238 |
=head1 BUGS |
=head1 BUGS |
239 |
|
|
240 |
There are no known bugs. |
There are no known bugs. If you find any, please report it in CPAN's |
241 |
|
request tracker at: http://rt.cpan.org/ |
242 |
|
|
243 |
=head1 CONTACT AND COPYRIGHT |
=head1 CONTACT AND COPYRIGHT |
244 |
|
|
245 |
Copyright 2002 Dobrica Pavlinusic (dpavlin@rot13.org). All |
Copyright 2002-2003 Dobrica Pavlinusic (dpavlin@rot13.org). All |
246 |
rights reserved. This program is free software; you can redistribute |
rights reserved. This program is free software; you can redistribute |
247 |
it and/or modify it under the same terms as Perl itself. |
it and/or modify it under the same terms as Perl itself. |
248 |
|
|