line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::Stem::UniNE; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
104754
|
use v5.8.1; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
93
|
|
4
|
2
|
|
|
2
|
|
12
|
use utf8; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
16
|
|
5
|
2
|
|
|
2
|
|
51
|
use Carp; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
187
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1826
|
use Moo; |
|
2
|
|
|
|
|
49053
|
|
|
2
|
|
|
|
|
14
|
|
8
|
2
|
|
|
2
|
|
5426
|
use namespace::clean; |
|
2
|
|
|
|
|
39097
|
|
|
2
|
|
|
|
|
15
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my @languages = qw( bg cs de fa ); |
13
|
|
|
|
|
|
|
my @aggressive = qw( cs de ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %is_language = map { $_ => 1 } @languages; |
16
|
|
|
|
|
|
|
my %has_aggressive = map { $_ => 1 } @aggressive; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has language => ( |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
isa => sub { croak "Invalid language '$_[0]'" |
21
|
|
|
|
|
|
|
unless $is_language{$_[0]} }, |
22
|
|
|
|
|
|
|
coerce => sub { defined $_[0] ? lc $_[0] : '' }, |
23
|
|
|
|
|
|
|
trigger => sub { $_[0]->_clear_stemmer }, |
24
|
|
|
|
|
|
|
required => 1, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has aggressive => ( |
28
|
|
|
|
|
|
|
is => 'rw', |
29
|
|
|
|
|
|
|
coerce => sub { !!$_[0] }, |
30
|
|
|
|
|
|
|
trigger => sub { $_[0]->_clear_stemmer }, |
31
|
|
|
|
|
|
|
default => 0, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has _stemmer => ( |
35
|
|
|
|
|
|
|
is => 'rw', |
36
|
|
|
|
|
|
|
builder => '_build_stemmer', |
37
|
|
|
|
|
|
|
clearer => '_clear_stemmer', |
38
|
|
|
|
|
|
|
lazy => 1, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _build_stemmer { |
42
|
13
|
|
|
13
|
|
546
|
my $self = shift; |
43
|
13
|
|
|
|
|
284
|
my $language = uc $self->language; |
44
|
13
|
|
|
|
|
87
|
my $function = 'stem'; |
45
|
|
|
|
|
|
|
|
46
|
13
|
100
|
100
|
|
|
278
|
if ($self->aggressive && $has_aggressive{$self->language}) { |
47
|
8
|
|
|
|
|
281
|
$function .= '_aggressive'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
13
|
|
|
|
|
3801
|
require "Lingua/Stem/UniNE/$language.pm"; |
51
|
13
|
|
|
|
|
28
|
$self->_stemmer( \&{"Lingua::Stem::UniNE::${language}::${function}"} ); |
|
13
|
|
|
|
|
458
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub languages { |
55
|
6
|
|
|
6
|
1
|
6219
|
return @languages; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub stem { |
59
|
19
|
|
|
19
|
1
|
2673
|
my $self = shift; |
60
|
19
|
|
|
|
|
40
|
my @stems = map { $self->_stemmer->($_) } @_; |
|
21
|
|
|
|
|
553
|
|
61
|
|
|
|
|
|
|
|
62
|
19
|
100
|
|
|
|
150
|
return wantarray ? @stems : pop @stems; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |