11 |
use Text::Iconv; |
use Text::Iconv; |
12 |
use Data::Dumper; |
use Data::Dumper; |
13 |
use File::Temp qw/ :mktemp /; |
use File::Temp qw/ :mktemp /; |
14 |
|
use Text::Soundex; |
15 |
|
|
16 |
my $iso2utf = Text::Iconv->new('ISO-8859-2','UTF-8'); |
my $iso2utf = Text::Iconv->new('ISO-8859-2','UTF-8'); |
17 |
my $utf2iso = Text::Iconv->new('UTF-8','ISO-8859-2'); |
my $utf2iso = Text::Iconv->new('UTF-8','ISO-8859-2'); |
213 |
|
|
214 |
} |
} |
215 |
|
|
216 |
|
# this is optional function which return words which sound like |
217 |
|
sub apropos_index { |
218 |
|
my $self = shift; |
219 |
|
|
220 |
|
my $fld = shift || croak "apropos_index need field"; |
221 |
|
my $words = shift || return; |
222 |
|
|
223 |
|
my @a; |
224 |
|
|
225 |
|
foreach my $word (split(/\s+/,$words)) { |
226 |
|
|
227 |
|
my $hash = soundex($word); |
228 |
|
my $c = substr($word,0,1); |
229 |
|
|
230 |
|
my $index = $self->open_index; |
231 |
|
my $index_file = $self->{index_dir}."/".$self->{config_name}; |
232 |
|
|
233 |
|
open(SWISH,"swish-e -f $index_file -k $c |") || die "can't start swish-e"; |
234 |
|
my @k_arr; |
235 |
|
while(<SWISH>) { |
236 |
|
next if (/^#/); |
237 |
|
s/^.+?:\s+//; |
238 |
|
@k_arr = split(/\s+/); |
239 |
|
} |
240 |
|
|
241 |
|
foreach my $k (@k_arr) { |
242 |
|
push @a, $k if (soundex($k) eq $hash); |
243 |
|
} |
244 |
|
} |
245 |
|
|
246 |
|
# print STDERR "apropos_index($fld,$word) [$hash]: ",join(" ",@a),"\n"; |
247 |
|
return @a; |
248 |
|
|
249 |
|
} |
250 |
|
|
251 |
1; |
1; |