blib/lib/Lingua/Stem/Patch/PL.pm

filter: Statementstmt 100% 74 / 74 Branchbran 100% 52 / 52 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 8 totaltotal 94.5% 139 / 147 CC 27 SCAR 14.9
CC
27
Cov
100%
remove_adjective
7.0
remove_noun
5.0
remove_diminutive
5.0
CRAP 4.4
« blib/lib/Lingua/Stem/Patch/EO.pm ↑ Summary Build »
1 package Lingua::Stem::Patch::PL;
2  
3 1 ▶use v5.8.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '0.05';
10 1 our @EXPORT_OK = qw( stem stem_pl );
11  
12 1 *stem_pl = \&stem;
13  
14 sub stem {
15 77 ▶ my $word = lc shift;
Subroutine stem: called CC=1 SCAR=0.0
Pod undocumented
16  
17 77 $word = remove_noun($word);
18 77 $word = remove_diminutive($word);
19 77 $word = remove_adjective($word);
20 77 $word = remove_verb($word);
21 77 $word = remove_adverb($word);
22 77 $word = remove_plural($word);
23 77 $word = remove_other($word);
24  
25 77 return $word;
26 }
27  
28 sub remove_noun {
29 77 ▶ my ($word) = @_;
Subroutine remove_noun: called CC=5 SCAR=16.1
Pod undocumented
30 77 my $length = length $word;
31  
32 77 ▶ if ($length > 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 6) 37 40 77
33 37 ▶ return $word if $word =~ s{ (?:
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: tach | acj[a\x{105}i] # -acja -acj\x{105} -acji | [ae]ni[eu] # -anie -aniu -enie -eniu | (?<= ty ) ka # -tyka \x{2192} -ty ) $//x 9 28 37
34 tach
35 | acj[aąi] # -acja -acją -acji
36 | [ae]ni[eu] # -anie -aniu -enie -eniu
37 | (?<= ty ) ka # -tyka → -ty
38 ) $}{}x;
39 }
40  
41 68 ▶ if ($length > 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 5) 53 15 68
42 53 ▶ return $word if $word =~ s{ (?:
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: ach | ami | ce | ta | [cn]i[au] # -cia -ciu -nia -niu | (?<= c ) j[a\x{105}i] # -cja -cj\x{105} -cji \x{2192} -c ) $//x 12 41 53
43 ach | ami | ce | ta
44 | [cn]i[au] # -cia -ciu -nia -niu
45 | (?<= c ) j[aąi] # -cja -cją -cji → -c
46 ) $}{}x;
47 }
48  
49 56 return $word;
50 }
51  
52 sub remove_diminutive {
53 77 ▶ my ($word) = @_;
Subroutine remove_diminutive: called CC=5 SCAR=16.1
Pod undocumented
54 77 my $length = length $word;
55  
56 77 ▶ if ($length > 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 6) 21 56 77
57 21 ▶ return $word if $word =~ s{ (?:
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: (?: [aiu]s | [ei]c ) zek # -aszek -eczek -iczek -iszek -uszek | (?<= e[jnr] ) ek # -ejek -enek -erek \342\206\222 -ej -en -er ) $//x 6 15 21
58 (?: [aiu]s | [ei]c ) zek # -aszek -eczek -iczek -iszek -uszek
59 | (?<= e[jnr] ) ek # -ejek -enek -erek → -ej -en -er
60 ) $}{}x;
61 }
62  
63 71 ▶ if ($length > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 4) 54 17 71
64 54 ▶ return $word if $word =~ s{
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ [ae]k # -ak -ek $//x 4 50 54
65 [ae]k # -ak -ek
66 $}{}x;
67 }
68  
69 67 return $word;
70 }
71  
72 sub remove_adjective {
73 77 ▶ my ($word) = @_;
Subroutine remove_adjective: called CC=7 SCAR=19.5
Pod undocumented
74 77 my $length = length $word;
75  
76 77 ▶ if ($length > 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 7) 10 67 77
77 10 ▶ return $1 if $word =~ m{^
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /^ naj # naj- ( .+ ) # $1 sz (?: [ey] | ych ) # -sze -szy -szych $/x 3 7 10
78 naj # naj-
79 ( .+ ) # $1
80 sz (?: [ey] | ych ) # -sze -szy -szych
81 $}x;
82 }
83  
84 74 ▶ if ($length > 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 6) 11 63 74
85 11 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ czny $//x 1 10 11
86 if $word =~ s{ czny $}{}x;
87 }
88  
89 73 ▶ if ($length > 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 5) 31 42 73
90 31 ▶ return $word if $word =~ s{ (?:
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: ego | ej | ych | ow[aey] # -owa -owe -owy ) $//x 6 25 31
91 ego | ej | ych
92 | ow[aey] # -owa -owe -owy
93 ) $}{}x;
94 }
95  
96 67 return $word;
97 }
98  
99 sub remove_verb {
100 77 ▶ my ($word) = @_;
Subroutine remove_verb: called CC=5 SCAR=16.1
Pod undocumented
101 77 my $length = length $word;
102  
103 77 ▶ if ($length > 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 5) 25 52 77
104 25 ▶ return $word if $word =~ s{ (?:
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: bym | cie | \x{142}em | [ae] (?: my | sz | \x{15b}\x{107} ) # -amy -emy -asz -esz -a\x{15b}\x{107} -e\x{15b}\x{107} ) $//x 9 16 25
105 bym | cie | łem
106 | [ae] (?: my | sz | ść ) # -amy -emy -asz -esz -aść -eść
107 ) $}{}x;
108 }
109  
110 68 ▶ if ($length > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 3) 54 14 68
111 54 ▶ return $word if $word =~ s{ (?:
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: \x{105}c | a[\x{107}m\x{142}] # -a\x{107} -am -a\x{142} | e[\x{107}m] # -e\x{107} -em | i[\x{107}\x{142}] # -i\x{107} -i\x{142} | (?<= a ) j # -aj \x{2192} -a | (?<= [ae] ) (?: sz | \x{15b}\x{107} ) # -asz -a\x{15b}\x{107} -esz -e\x{15b}\x{107} \x{2192} -a -e ) $//x 13 41 54
112 ąc
113 | a[ćmł] # -ać -am -ał
114 | e[ćm] # -eć -em
115 | i[ćł] # -ić -ił
116 | (?<= a ) j # -aj → -a
117 | (?<= [ae] ) (?: sz | ść ) # -asz -aść -esz -eść → -a -e
118 ) $}{}x;
119 }
120  
121 55 return $word;
122 }
123  
124 sub remove_adverb {
125 77 ▶ my ($word) = @_;
Subroutine remove_adverb: called CC=3 SCAR=11.0
Pod undocumented
126 77 my $length = length $word;
127  
128 77 ▶ if ($length > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 4) 29 48 77
129 29 ▶ return $word if $word =~ s{ (?:
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: (?<= r ) ze # -rze \342\206\222 -r | (?<= [nw] ) ie # -nie -wie \342\206\222 -n -w ) $//x 3 26 29
130 (?<= r ) ze # -rze → -r
131 | (?<= [nw] ) ie # -nie -wie → -n -w
132 ) $}{}x;
133 }
134  
135 74 return $word;
136 }
137  
138 sub remove_plural {
139 77 ▶ my ($word) = @_;
Subroutine remove_plural: called CC=3 SCAR=11.0
Pod undocumented
140 77 my $length = length $word;
141  
142 77 ▶ if ($length > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 4) 26 51 77
143 26 ▶ return $word if $word =~ s{ (?:
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: ami | om | \363w ) $//x 2 24 26
144 ami | om | ów
145 ) $}{}x;
146 }
147  
148 75 return $word;
149 }
150  
151 sub remove_other {
152 77 ▶ my ($word) = @_;
Subroutine remove_other: called CC=5 SCAR=16.1
Pod undocumented
153 77 my $length = length $word;
154  
155 77 ▶ if ($length > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 4) 25 52 77
156 25 ▶ return $word if $word =~ s{
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ i[ae] # -ia -ie $//x 2 23 25
157 i[ae] # -ia -ie
158 $}{}x;
159 }
160  
161 75 ▶ if ($length > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 3) 47 28 75
162 47 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ [a\x{105}\x{119}i\x{142}uy] $//x 15 32 47
163 if $word =~ s{ [aąęiłuy] $}{}x;
164 }
165  
166 60 return $word;
167 }
168  
169 1 1;
170  
171 __END__
« blib/lib/Lingua/Stem/Patch/EO.pm ↑ Summary Build »