blib/lib/Lingua/Stem/Ru.pm

filter: Statementstmt 77.2% 68 / 88 Branchbran 52.6% 20 / 38 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 77.7% 7 / 9 Podpod 100% 4 / 4 totaltotal 67.7% 101 / 149 CC 24 SCAR 27.3
CC
24
Cov
68%
stem
24.8
stem_caching
20.0
stem_word
9.1
CRAP 15.4
↑ Summary
1 package Lingua::Stem::Ru;
2 3 $Lingua::Stem::Ru::VERSION = '0.04_02'; # TRIAL
3  
4 3 ▶$Lingua::Stem::Ru::VERSION = '0.0402';use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 our @EXPORT = ();
11 3 our @EXPORT_OK = qw (stem stem_word clear_stem_cache stem_caching);
12 3 our %EXPORT_TAGS = ();
13  
14 3 my $Stem_Caching = 0;
15 3 my $Stem_Cache = {};
16  
17 3 my $VOWEL = qr/ÁÅÉÏÕÙÜÀÑ/;
18 3 my $PERFECTIVEGROUND = qr/((É×|É×ÛÉ|É×ÛÉÓØ|Ù×|Ù×ÛÉ|Ù×ÛÉÓØ)|((?<=[ÁÑ])(×|×ÛÉ|×ÛÉÓØ)))$/;
19 3 my $REFLEXIVE = qr/(Ó[ÑØ])$/;
20 3 my $ADJECTIVE = qr/(ÅÅ|ÉÅ|ÙÅ|ÏÅ|ÉÍÉ|ÙÍÉ|ÅÊ|ÉÊ|ÙÊ|ÏÊ|ÅÍ|ÉÍ|ÙÍ|ÏÍ|ÅÇÏ|ÏÇÏ|ÅÍÕ|ÏÍÕ|ÉÈ|ÙÈ|ÕÀ|ÀÀ|ÁÑ|ÑÑ|ÏÀ|ÅÀ)$/;
21 3 my $PARTICIPLE = qr/((É×Û|Ù×Û|ÕÀÝ)|((?<=[ÁÑ])(ÅÍ|ÎÎ|×Û|ÀÝ|Ý)))$/;
22 3 my $VERB = qr/((ÉÌÁ|ÙÌÁ|ÅÎÁ|ÅÊÔÅ|ÕÊÔÅ|ÉÔÅ|ÉÌÉ|ÙÌÉ|ÅÊ|ÕÊ|ÉÌ|ÙÌ|ÉÍ|ÙÍ|ÅÎ|ÉÌÏ|ÙÌÏ|ÅÎÏ|ÑÔ|ÕÅÔ|ÕÀÔ|ÉÔ|ÙÔ|ÅÎÙ|ÉÔØ|ÙÔØ|ÉÛØ|ÕÀ|À)|((?<=[ÁÑ])(ÌÁ|ÎÁ|ÅÔÅ|ÊÔÅ|ÌÉ|Ê|Ì|ÅÍ|Î|ÌÏ|ÎÏ|ÅÔ|ÀÔ|ÎÙ|ÔØ|ÅÛØ|ÎÎÏ)))$/;
23 3 my $NOUN = qr/(Á|Å×|Ï×|ÉÅ|ØÅ|Å|ÉÑÍÉ|ÑÍÉ|ÁÍÉ|ÅÉ|ÉÉ|É|ÉÅÊ|ÅÊ|ÏÊ|ÉÊ|Ê|ÉÑÍ|ÑÍ|ÉÅÍ|ÅÍ|ÁÍ|ÏÍ|Ï|Õ|ÁÈ|ÉÑÈ|ÑÈ|Ù|Ø|ÉÀ|ØÀ|À|ÉÑ|ØÑ|Ñ)$/;
24 3 my $RVRE = qr/^(.*?[$VOWEL])(.*)$/;
25 3 my $DERIVATIONAL = qr/[^$VOWEL][$VOWEL]+[^$VOWEL]+[$VOWEL].*(?<=Ï)ÓÔØ?$/;
26  
27 1 ▶sub stem {
Subroutine stem: called CC=13 SCAR=32.1
Pod documented
28 1 ▶ return [] if ($#_ == -1);
Branch: 1 branch
BranchTrueFalseTotal
if $#_ == -1 0 1 1
29 1 my $parm_ref;
30 1 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 1 0 1
31 1 $parm_ref = shift;
32 } else {
33 0 $parm_ref = { @_ };
34 }
35  
36 1 my $words = [];
37 1 my $locale = 'ru';
38 1 my $exceptions = {};
39 1 foreach (keys %$parm_ref) {
40 1 my $key = lc ($_);
41 1 ▶ if ($key eq '-words') {
Branch: 3 branches
BranchTrueFalseTotal
if ($key eq '-words') { } 1 0 1
elsif ($key eq '-exceptions') { } 0 0 0
elsif ($key eq '-locale') { } 0 0 0
42 1 @$words = @{$parm_ref->{$key}};
43 } elsif ($key eq '-exceptions') {
44 0 $exceptions = $parm_ref->{$key};
45 } elsif ($key eq '-locale') {
46 0 $locale = $parm_ref->{$key};
47 } else {
48 0 croak (__PACKAGE__ . "::stem() - Unknown parameter '$key' with value '$parm_ref->{$key}'\n");
49 }
50 }
51  
52 1 local( $_ );
53 1 foreach (@$words) {
54 # Flatten case
55 49673 $_ = lc $_;
56  
57 # Check against exceptions list
58 49673 ▶ if (exists $exceptions->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $exceptions->{$_}) 0 49673 49673
59 0 $_ = $exceptions->{$_};
60 0 next;
61 }
62  
63 # Check against cache of stemmed words
64 49673 my $original_word = $_;
65 49673 ▶ if ($Stem_Caching && exists $Stem_Cache->{$original_word}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Stem_Caching and exists $Stem_Cache->{$original_word}) 0 49673 49673
Condition33%1/3
$Stem_Caching and exists $Stem_Cache->{$original_word}
!ll&&!rl&&r
4967300
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
66 0 $_ = $Stem_Cache->{$original_word};
67 0 next;
68 }
69  
70 49673 $_ = stem_word($_);
71  
72 49673 ▶ $Stem_Cache->{$original_word} = $_ if $Stem_Caching;
Branch: 1 branch
BranchTrueFalseTotal
if $Stem_Caching 0 49673 49673
73 }
74 1 ▶ $Stem_Cache = {} if ($Stem_Caching < 2);
Branch: 1 branch
BranchTrueFalseTotal
if $Stem_Caching < 2 1 0 1
75  
76 1 return $words;
77 }
78  
79 49682 ▶sub stem_word {
Subroutine stem_word: called CC=9 SCAR=22.1
Pod documented
80 49682 my $word = lc shift;
81  
82 # Check against cache of stemmed words
83 49682 ▶ if ($Stem_Caching && exists $Stem_Cache->{$word}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Stem_Caching and exists $Stem_Cache->{$word}) 0 49682 49682
Condition33%1/3
$Stem_Caching and exists $Stem_Cache->{$word}
!ll&&!rl&&r
4968200
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
84 0 return $Stem_Cache->{$word};
85 }
86  
87 49682 my ($start, $RV) = $word =~ /$RVRE/;
88 49682 ▶ return $word unless $RV;
Branch: 1 branch
BranchTrueFalseTotal
unless $RV 217 49465 49682
89  
90 # Step 1
91 49465 ▶ unless ($RV =~ s/$PERFECTIVEGROUND//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($RV =~ s/$PERFECTIVEGROUND//) 49033 432 49465
92 49033 $RV =~ s/$REFLEXIVE//;
93  
94 49033 ▶ if ($RV =~ s/$ADJECTIVE//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($RV =~ s/$ADJECTIVE//) { } 15241 33792 49033
95 15241 $RV =~ s/$PARTICIPLE//;
96 } else {
97 33792 ▶ $RV =~ s/$NOUN// unless $RV =~ s/$VERB//;
Branch: 1 branch
BranchTrueFalseTotal
unless $RV =~ s/$VERB// 20694 13098 33792
98 }
99 }
100  
101 # Step 2
102 49465 $RV =~ s/É$//;
103  
104 # Step 3
105 49465 ▶ $RV =~ s/ÏÓÔØ?$// if $RV =~ /$DERIVATIONAL/;
Branch: 1 branch
BranchTrueFalseTotal
if $RV =~ /$DERIVATIONAL/ 406 49059 49465
106  
107 # Step 4
108 49465 ▶ unless ($RV =~ s/Ø$//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($RV =~ s/\330$//) 49034 431 49465
109 49034 $RV =~ s/ÅÊÛÅ?//;
110 49034 $RV =~ s/ÎÎ$/Î/;
111 }
112  
113 49465 return $start.$RV;
114 }
115  
116 0 ▶sub stem_caching {
Subroutine stem_caching: not called CC=4 SCAR=30.0
Pod documented
117 0 my $parm_ref;
118 0 ▶ if (ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
119 0 $parm_ref = shift;
120 } else {
121 0 $parm_ref = { @_ };
122 }
123 0 my $caching_level = $parm_ref->{-level};
124 0 ▶ if (defined $caching_level) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $caching_level) 0 0 0
125 0 ▶ if ($caching_level !~ m/^[012]$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($caching_level =~ /^[012]$/) 0 0 0
126 0 croak(__PACKAGE__ . "::stem_caching() - Legal values are '0','1' or '2'. '$caching_level' is not a legal value");
127 }
128 0 $Stem_Caching = $caching_level;
129 }
130 0 return $Stem_Caching;
131 }
132  
133 0 ▶sub clear_stem_cache {
Subroutine clear_stem_cache: not called CC=1 SCAR=6.9
Pod documented
134 0 $Stem_Cache = {};
135 }
136
137  
138 3 1;
139 __END__
↑ Summary