| 1 | package Lingua::Stem::UniNE; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use v5.8.1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | my @languages = qw( bg cs de fa ); | |||||||||||||||||||||||||||
| 13 | 2 | my @aggressive = qw( cs de ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | my %is_language = map { $_ => 1 } @languages; | |||||||||||||||||||||||||||
| 16 | 2 | my %has_aggressive = map { $_ => 1 } @aggressive; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | has language => ( | ||||||||||||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||||||||||
| 20 | 16 | ▶ | isa => sub { croak "Invalid language '$_[0]'" | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 21 | 16 | ▶ | unless $is_language{$_[0]} }, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 16 | ▶ | coerce => sub { defined $_[0] ? lc $_[0] : '' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 12 | ▶ | trigger => sub { $_[0]->_clear_stemmer }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 2 | required => 1, | |||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | has aggressive => ( | ||||||||||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||||||||||
| 29 | 3 | ▶ | coerce => sub { !!$_[0] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 1 | ▶ | trigger => sub { $_[0]->_clear_stemmer }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 2 | default => 0, | |||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 2 | has _stemmer => ( | |||||||||||||||||||||||||||
| 35 | is => 'rw', | ||||||||||||||||||||||||||||
| 36 | builder => '_build_stemmer', | ||||||||||||||||||||||||||||
| 37 | clearer => '_clear_stemmer', | ||||||||||||||||||||||||||||
| 38 | lazy => 1, | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 13 | ▶ | sub _build_stemmer { | ||||||||||||||||||||||||||
|
Subroutine
_build_stemmer: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 42 | 13 | my $self = shift; | |||||||||||||||||||||||||||
| 43 | 13 | my $language = uc $self->language; | |||||||||||||||||||||||||||
| 44 | 13 | my $function = 'stem'; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 13 | ▶ | if ($self->aggressive && $has_aggressive{$self->language}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->aggressive and $has_aggressive{$self->language}
MC/DC100%2/2
$self->aggressive and $has_aggressive{$self->language}
$self->aggressive
$has_aggressive{$self->language}
Truth table100%3/3
A and B
A= $self->aggressiveB= $has_aggressive{$self->language}
| |||||||||||||||||||||||||||||
| 47 | 8 | $function .= '_aggressive'; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 13 | require "Lingua/Stem/UniNE/$language.pm"; | |||||||||||||||||||||||||||
| 51 | 13 | $self->_stemmer( \&{"Lingua::Stem::UniNE::${language}::${function}"} ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 6 | ▶ | sub languages { | ||||||||||||||||||||||||||
|
Subroutine
languages: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 6 | return @languages; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 19 | ▶ | sub stem { | ||||||||||||||||||||||||||
|
Subroutine
stem: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 19 | my $self = shift; | |||||||||||||||||||||||||||
| 60 | 19 | my @stems = map { $self->_stemmer->($_) } @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 19 | ▶ | return wantarray ? @stems : pop @stems; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | 1; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||||||||||