blib/lib/Lingua/Stem/Uk.pm

filter: Statementstmt 78.2% 72 / 92 Branchbran 42.1% 16 / 38 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 81.8% 9 / 11 Podpod 100% 4 / 4 totaltotal 66.4% 103 / 155 CC 24 SCAR 26.9
CC
24
Cov
66%
stem
24.8
stem_caching
20.0
stem_word
10.2
CRAP 14.8
↑ Summary
1 package Lingua::Stem::Uk;
2 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use vars qw (@ISA @EXPORT_OK @EXPORT %EXPORT_TAGS $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 @ISA = qw (Exporter);
12 2 @EXPORT = ();
13 2 @EXPORT_OK = qw (stem stem_word clear_stem_cache stem_caching);
14 2 %EXPORT_TAGS = ();
15 }
16 2 $VERSION = "0.01";
17  
18 2 my $Stem_Caching = 0;
19 2 my $Stem_Cache = {};
20  
21 2 my $VOWEL = qr/аеіоуиєюяї/;
22 2 my $PERFECTIVEGROUND = qr/((ів|івши|івшись|ив|ивши|ившись)|((?<=[ая])(в|вши|вшись)))$/;
23 2 my $REFLEXIVE = qr/(с[яь])$/;
24 2 my $ADJECTIVE = qr/(ее|іе|ие|ое|ими|іми|ої|а|е|і|у|ю|ій|ий|ой|ем|ім|им|ом|его|ого|ему|ому|іх|их|ую|юю|ая|яя|ою|ею)$/;
25 2 my $PARTICIPLE = qr/((івш|ивш|уюч|ьн|л)|((?<=[ая])(ем|нн|вш|ющ|щ)))$/;
26 2 my $VERB = qr/((іла|ила|ена|ейте|уйте|іть|іли|или|ей|уй|іл|ил|ім|им|ен|іло|ило|ено|ять|ує|ують|іт|ит|ени|іть|ить|ую|ю)|((?<=[ая])(ла|на|ете|йте|ли|й|л|ем|н|ло|но|ет|ют|ны|ть|ешь|нно)))$/;
27 2 my $NOUN = qr/(а|ев|ов|іе|ье|е|іями|ями|ами|еї|ії|и|ією|ею|єю|ой|ий|й|иям|ям|ием|ем|ам|ом|о|у|ах|іях|ях|и|і|ь|ію|ью|ю|ия|ья|я)$/;
28 2 my $RVRE = qr/^(.*?[$VOWEL])(.*)$/;
29 2 my $DERIVATIONAL = qr/[^$VOWEL][$VOWEL]+[^$VOWEL]+[$VOWEL].*(?<=і)сть?$/;
30  
31 4 ▶sub stem {
Subroutine stem: called CC=13 SCAR=32.1
Pod documented
32 4 ▶ return [] if ($#_ == -1);
Branch: 1 branch
BranchTrueFalseTotal
if $#_ == -1 0 4 4
33 4 my $parm_ref;
34 4 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 4 0 4
35 4 $parm_ref = shift;
36 } else {
37 0 $parm_ref = { @_ };
38 }
39  
40 4 my $words = [];
41 4 my $locale = 'uk';
42 4 my $exceptions = {};
43 4 foreach (keys %$parm_ref) {
44 4 my $key = lc ($_);
45 4 ▶ if ($key eq '-words') {
Branch: 3 branches
BranchTrueFalseTotal
if ($key eq '-words') { } 4 0 4
elsif ($key eq '-exceptions') { } 0 0 0
elsif ($key eq '-locale') { } 0 0 0
46 4 @$words = @{$parm_ref->{$key}};
47 } elsif ($key eq '-exceptions') {
48 0 $exceptions = $parm_ref->{$key};
49 } elsif ($key eq '-locale') {
50 0 $locale = $parm_ref->{$key};
51 } else {
52 0 croak (__PACKAGE__ . "::stem() - Unknown parameter '$key' with value '$parm_ref->{$key}'\n");
53 }
54 }
55  
56 4 local( $_ );
57 4 foreach (@$words) {
58 # Flatten case
59 34 $_ = lc $_;
60  
61 # Check against exceptions list
62 34 ▶ if (exists $exceptions->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $exceptions->{$_}) 0 34 34
63 0 $_ = $exceptions->{$_};
64 0 next;
65 }
66  
67 # Check against cache of stemmed words
68 34 my $original_word = $_;
69 34 ▶ if ($Stem_Caching && exists $Stem_Cache->{$original_word}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Stem_Caching and exists $Stem_Cache->{$original_word}) 0 34 34
Condition33%1/3
$Stem_Caching and exists $Stem_Cache->{$original_word}
!ll&&!rl&&r
3400
MC/DC0%0/2
$Stem_Caching and exists $Stem_Cache->{$original_word}
$Stem_Caching exists $Stem_Cache->{$original_word}
Truth table33%1/3
A and B
A= $Stem_CachingB= exists $Stem_Cache->{$original_word}
ABresult
0X0
100
111
70 0 $_ = $Stem_Cache->{$original_word};
71 0 next;
72 }
73  
74 34 $_ = stem_word($_);
75  
76 34 ▶ $Stem_Cache->{$original_word} = $_ if $Stem_Caching;
Branch: 1 branch
BranchTrueFalseTotal
if $Stem_Caching 0 34 34
77 }
78 4 ▶ $Stem_Cache = {} if ($Stem_Caching < 2);
Branch: 1 branch
BranchTrueFalseTotal
if $Stem_Caching < 2 4 0 4
79  
80 4 return $words;
81 }
82  
83 34 ▶sub stem_word {
Subroutine stem_word: called CC=9 SCAR=23.2
Pod documented
84 34 my $word = lc shift;
85  
86 # Check against cache of stemmed words
87 34 ▶ if ($Stem_Caching && exists $Stem_Cache->{$word}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Stem_Caching and exists $Stem_Cache->{$word}) 0 34 34
Condition33%1/3
$Stem_Caching and exists $Stem_Cache->{$word}
!ll&&!rl&&r
3400
MC/DC0%0/2
$Stem_Caching and exists $Stem_Cache->{$word}
$Stem_Caching exists $Stem_Cache->{$word}
Truth table33%1/3
A and B
A= $Stem_CachingB= exists $Stem_Cache->{$word}
ABresult
0X0
100
111
88 0 return $Stem_Cache->{$word};
89 }
90  
91 34 my ($start, $RV) = $word =~ /$RVRE/;
92 34 ▶ return $word unless $RV;
Branch: 1 branch
BranchTrueFalseTotal
unless $RV 0 34 34
93  
94 # Step 1
95 34 ▶ unless ($RV =~ s/$PERFECTIVEGROUND//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($RV =~ s/$PERFECTIVEGROUND//) 32 2 34
96 32 $RV =~ s/$REFLEXIVE//;
97  
98 32 ▶ if ($RV =~ s/$ADJECTIVE//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($RV =~ s/$ADJECTIVE//) { } 29 3 32
99 29 $RV =~ s/$PARTICIPLE//;
100 } else {
101 3 ▶ $RV =~ s/$NOUN// unless $RV =~ s/$VERB//;
Branch: 1 branch
BranchTrueFalseTotal
unless $RV =~ s/$VERB// 0 3 3
102 }
103 }
104  
105 # Step 2
106 34 $RV =~ s/и$//;
107  
108 # Step 3
109 34 ▶ $RV =~ s/ість?$// if $RV =~ /$DERIVATIONAL/;
Branch: 1 branch
BranchTrueFalseTotal
if $RV =~ /$DERIVATIONAL/ 0 34 34
110  
111 # Step 4
112 34 ▶ unless ($RV =~ s/ь$//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($RV =~ s/\x{44c}$//) 34 0 34
113 34 $RV =~ s/іше?//;
114 34 $RV =~ s/нн$/н/;
115 }
116  
117 34 return $start.$RV;
118 }
119  
120 0 ▶sub stem_caching {
Subroutine stem_caching: not called CC=4 SCAR=30.0
Pod documented
121 0 my $parm_ref;
122 0 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
123 0 $parm_ref = shift;
124 } else {
125 0 $parm_ref = { @_ };
126 }
127 0 my $caching_level = $parm_ref->{-level};
128 0 ▶ if (defined $caching_level) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $caching_level) 0 0 0
129 0 ▶ if ($caching_level !~ m/^[012]$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($caching_level =~ /^[012]$/) 0 0 0
130 0 croak(__PACKAGE__ . "::stem_caching() - Legal values are '0','1' or '2'. '$caching_level' is not a legal value");
131 }
132 0 $Stem_Caching = $caching_level;
133 }
134 0 return $Stem_Caching;
135 }
136  
137 0 ▶sub clear_stem_cache {
Subroutine clear_stem_cache: not called CC=1 SCAR=6.9
Pod documented
138 0 $Stem_Cache = {};
139 }
140
141  
142 2 1;
143 __END__
↑ Summary