line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package KinoSearch1::Analysis::Stemmer; |
2
|
26
|
|
|
26
|
|
1240
|
use strict; |
|
26
|
|
|
|
|
61
|
|
|
26
|
|
|
|
|
845
|
|
3
|
26
|
|
|
26
|
|
140
|
use warnings; |
|
26
|
|
|
|
|
55
|
|
|
26
|
|
|
|
|
647
|
|
4
|
26
|
|
|
26
|
|
145
|
use KinoSearch1::Util::ToolSet; |
|
26
|
|
|
|
|
50
|
|
|
26
|
|
|
|
|
3936
|
|
5
|
26
|
|
|
26
|
|
152
|
use base qw( KinoSearch1::Analysis::Analyzer ); |
|
26
|
|
|
|
|
53
|
|
|
26
|
|
|
|
|
2680
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our %supported_languages; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
BEGIN { |
10
|
26
|
|
|
26
|
|
295
|
__PACKAGE__->init_instance_vars( |
11
|
|
|
|
|
|
|
# constructor params / members |
12
|
|
|
|
|
|
|
stemmifier => undef, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
26
|
|
|
26
|
|
23104
|
use Lingua::Stem::Snowball qw( stemmers ); |
|
26
|
|
|
|
|
145647
|
|
|
26
|
|
|
|
|
8813
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# build a list of supported languages. |
19
|
|
|
|
|
|
|
$supported_languages{$_} = 1 for stemmers(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub init_instance { |
22
|
4
|
|
|
4
|
1
|
13
|
my $self = shift; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# verify language param |
25
|
4
|
|
|
|
|
40
|
my $language = $self->{language} = lc( $self->{language} ); |
26
|
4
|
50
|
|
|
|
23
|
croak("Unsupported language: '$language'") |
27
|
|
|
|
|
|
|
unless $supported_languages{$language}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# create instance of Snowball stemmer |
30
|
4
|
|
|
|
|
45
|
$self->{stemmifier} = Lingua::Stem::Snowball->new( lang => $language ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub analyze { |
34
|
11075
|
|
|
11075
|
1
|
13512
|
my ( $self, $batch ) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# replace terms with stemmed versions. |
37
|
11075
|
|
|
|
|
40983
|
my $all_texts = $batch->get_all_texts; |
38
|
11075
|
|
|
|
|
75137
|
$self->{stemmifier}->stem_in_place($all_texts); |
39
|
11075
|
|
|
|
|
32392
|
$batch->set_all_texts($all_texts); |
40
|
|
|
|
|
|
|
|
41
|
11075
|
|
|
|
|
21340
|
$batch->reset; |
42
|
11075
|
|
|
|
|
46380
|
return $batch; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |