UniNE/CS.pm

filter: Statementstmt 92.3% 109 / 118 Branchbran 65.8% 79 / 120 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 9 totaltotal 78.6% 217 / 276 CC 64 SCAR 31.8
CC
64
Cov
80%
remove_derivational
55.1
remove_diminutive
24.8
remove_case
15.0
CRAP 24.1
↑ Summary UniNE/BG.pm »
1 package Lingua::Stem::UniNE::CS;
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 strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Unicode::CaseFold qw( fc );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Unicode::Normalize qw( NFC );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.08';
12 2 our @EXPORT_OK = qw( stem stem_cs stem_aggressive stem_cs_aggressive );
13  
14 2 *stem_cs = \&stem;
15 2 *stem_cs_aggressive = \&stem_aggressive;
16  
17 78 ▶sub stem {
Subroutine stem: called CC=1 SCAR=0.0
Pod undocumented
18 78 my ($word) = @_;
19  
20 78 $word = NFC fc $word;
21 78 $word = remove_case($word);
22 78 $word = remove_possessive($word);
23  
24 78 return $word;
25 }
26  
27 5 ▶sub stem_aggressive {
Subroutine stem_aggressive: called CC=1 SCAR=0.0
Pod undocumented
28 5 my ($word) = @_;
29  
30 5 $word = NFC fc $word;
31 5 $word = remove_case($word);
32 5 $word = remove_possessive($word);
33 5 $word = remove_comparative($word);
34 5 $word = remove_diminutive($word);
35 5 $word = remove_augmentative($word);
36 5 $word = remove_derivational($word);
37  
38 5 return $word;
39 }
40  
41 # remove grammatical case endings from nouns and adjectives
42 83 ▶sub remove_case {
Subroutine remove_case: called CC=15 SCAR=27.1
Pod undocumented
43 83 my ($word) = @_;
44 83 my $length = length $word;
45  
46 83 ▶ if ($length > 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 7) 8 75 83
47 8 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ atech $//x 1 7 8
48 if $word =~ s{ atech $}{}x;
49 }
50  
51 82 ▶ if ($length > 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 6) 22 60 82
52 22 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ at\x{16f}m $//x 1 21 22
53 if $word =~ s{ atům $}{}x;
54  
55 21 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?<= \x{11b} ) tem $//x 1 20 21
56 if $word =~ s{ (?<= ě ) tem $}{}x; # -ětem → -ě
57 }
58  
59 80 ▶ if ($length > 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 5) 43 37 80
60 43 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: \375mi # -\375mi | am[ai] # -ama -ami | at[ay] # -ata -aty | ov[\351i] # -ov\351 -ovi | [\341\375]ch # -\341ch -\375ch ) $//x 9 34 43
61 if $word =~ s{ (?:
62 ými # -ými
63 | am[ai] # -ama -ami
64 | at[ay] # -ata -aty
65 | ov[éi] # -ové -ovi
66 | [áý]ch # -ách -ých
67 ) $}{}x;
68  
69 34 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: (?<= [e\x{11b}] ) t[ei] # -ete -eti -\x{11b}te -\x{11b}ti \x{2192} -e -\x{11b} | (?<= [\351i] ) mu # -\351mu -imu \x{2192} -\351 -i | (?<= [ei\355] ) ch # -ech -ich -\355ch \x{2192} -e -i -\355 | (?<= [e\x{11b}\355] ) mi # -emi -\x{11b}mi -\355mi \x{2192} -e -\x{11b} -\355 | (?<= [\351i\355] ) ho # -\351ho -iho -\355ho \x{2192} -\351 -i -\355 ) $//x 15 19 34
70 if $word =~ s{ (?:
71 (?<= [eě] ) t[ei] # -ete -eti -ěte -ěti → -e -ě
72 | (?<= [éi] ) mu # -ému -imu → -é -i
73 | (?<= [eií] ) ch # -ech -ich -ích → -e -i -í
74 | (?<= [eěí] ) mi # -emi -ěmi -ími → -e -ě -í
75 | (?<= [éií] ) ho # -ého -iho -ího → -é -i -í
76 ) $}{}x;
77 }
78  
79 56 ▶ if ($length > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 4) 39 17 56
80 39 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: at # -at | mi # -mi | us # -us | o[su] # -os -ou | [\341\x{16f}\375]m # -\341m -\x{16f}m -\375m ) $//x 9 30 39
81 if $word =~ s{ (?:
82 at # -at
83 | mi # -mi
84 | us # -us
85 | o[su] # -os -ou
86 | [áůý]m # -ám -ům -ým
87 ) $}{}x;
88  
89 30 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: es # -es | [\351\355]m # -\351m -\355m | (?<= e ) m # -em \x{2192} -e ) $//x 7 23 30
90 if $word =~ s{ (?:
91 es # -es
92 | [éí]m # -ém -ím
93 | (?<= e ) m # -em → -e
94 ) $}{}x;
95 }
96  
97 40 ▶ if ($length > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 3) 38 2 40
98 38 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ [a\341\351ou\x{16f}y\375] $//x 11 27 38
99 if $word =~ s{ [aáéouůyý] $}{}x;
100  
101 27 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ / [e\x{11b}i\355] $/x 25 2 27
102 if $word =~ m{ [eěií] $}x;
103 }
104  
105 4 return $word;
106 }
107  
108 # remove possesive endings from names
109 83 ▶sub remove_possessive {
Subroutine remove_possessive: called CC=4 SCAR=13.9
Pod undocumented
110 83 my ($word) = @_;
111  
112 83 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if length $word < 6 74 9 83
113 if length $word < 6;
114  
115 9 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ [o\x{16f}]v $//x 2 7 9
116 if $word =~ s{ [oů]v $}{}x; # -ov -ův
117  
118 7 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?<= i ) n $//x 1 6 7
119 if $word =~ s{ (?<= i ) n $}{}x; # -in → -i
120  
121 6 return $word;
122 }
123  
124 5 ▶sub remove_comparative {
Subroutine remove_comparative: called CC=3 SCAR=11.0
Pod undocumented
125 5 my ($word) = @_;
126  
127 5 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if length $word < 6 4 1 5
128 if length $word < 6;
129  
130 1 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?<= [e\x{11b}] ) j\x{161} $//x 0 1 1
131 if $word =~ s{ (?<= [eě] ) jš $}{}x; # -ejš -ějš → -e -ě
132  
133 1 return $word;
134 }
135  
136 5 ▶sub remove_diminutive {
Subroutine remove_diminutive: called CC=14 SCAR=32.1
Pod undocumented
137 5 my ($word) = @_;
138 5 my $length = length $word;
139  
140 5 ▶ if ($length > 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 7) 0 5 5
141 0 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ ou\x{161}ek $//x 0 0 0
142 if $word =~ s{ oušek $}{}x;
143 }
144  
145 5 ▶ if ($length > 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 6) 0 5 5
146 # -aček -áček -anek -ánek -oček -onek -uček -unek
147 0 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ [a\341ou][\x{10d}n]ek $//x 0 0 0
148 if $word =~ s{ [aáou][čn]ek $}{}x;
149  
150 # -eček -éček -enek -ének -iček -íček -inek -ínek → -e -é -i -í
151 0 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?<= [e\351i\355] ) [\x{10d}n]ek $//x 0 0 0
152 if $word =~ s{ (?<= [eéií] ) [čn]ek $}{}x;
153 }
154  
155 5 ▶ if ($length > 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 5) 1 4 5
156 # -ačk -áčk -ank -ánk -átk -očk -onk -učk -unk -ušk
157 1 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: [a\341ou][\x{10d}n] | \341t | u\x{161} ) k $//x 0 1 1
158 if $word =~ s{ (?: [aáou][čn] | át | uš ) k $}{}x;
159  
160 # -ečk -éčk -enk -énk -ičk -íčk -ink -ínk
161 1 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ [e\351i\355][\x{10d}n]k $//x 0 1 1
162 if $word =~ s{ [eéií][čn]k $}{}x;
163 }
164  
165 5 ▶ if ($length > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 4) 1 4 5
166 # -ak -ák -ok -uk → -a -á -o -u
167 1 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?<= [a\341ou] ) k $//x 0 1 1
168 if $word =~ s{ (?<= [aáou] ) k $}{}x;
169  
170 # -ek -ék -ik -ík → -e -é -i -í
171 1 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?<= [e\351i\355] ) k $//x 0 1 1
172 if $word =~ s{ (?<= [eéií] ) k $}{}x;
173 }
174  
175 5 ▶ if ($length > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 3) 2 3 5
176 2 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ k $//x 0 2 2
177 if $word =~ s{ k $}{}x;
178 }
179  
180 5 return $word;
181 }
182  
183 5 ▶sub remove_augmentative {
Subroutine remove_augmentative: called CC=7 SCAR=21.0
Pod undocumented
184 5 my ($word) = @_;
185 5 my $length = length $word;
186  
187 5 ▶ if ($length > 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 6) 0 5 5
188 0 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ ajzn $//x 0 0 0
189 if $word =~ s{ ajzn $}{}x;
190 }
191  
192 5 ▶ if ($length > 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 5) 1 4 5
193 1 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?<= i ) (?: sk | zn ) $//x 0 1 1
194 if $word =~ s{ (?<= i ) (?: sk | zn ) $}{}x; # -isk -izn → -i
195 }
196  
197 5 ▶ if ($length > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 4) 1 4 5
198 1 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ \341k $//x 0 1 1
199 if $word =~ s{ ák $}{}x;
200 }
201  
202 5 return $word;
203 }
204  
205 5 ▶sub remove_derivational {
Subroutine remove_derivational: called CC=22 SCAR=40.1
Pod undocumented
206 5 my ($word) = @_;
207 5 my $length = length $word;
208  
209 5 ▶ if ($length > 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 8) 0 5 5
210 0 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ obinec $//x 0 0 0
211 if $word =~ s{ obinec $}{}x;
212 }
213  
214 5 ▶ if ($length > 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 7) 0 5 5
215 # -ovisk -ovišt -ovník -ovstv
216 0 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ ov (?: isk | i\x{161}t | n\355k | stv ) $//x 0 0 0
217 if $word =~ s{ ov (?: isk | išt | ník | stv ) $}{}x;
218  
219 # -ionář → -i
220 0 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?<= i ) on\341\x{159} $//x 0 0 0
221 if $word =~ s{ (?<= i ) onář $}{}x;
222 }
223  
224 5 ▶ if ($length > 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 6) 0 5 5
225 0 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: \341sek | loun | nost | \x{161}tin | teln | ov (?: ec | \355k | in | tv ) # -ovec -ov\355k -ovin -ovtv ) $//x 0 0 0
226 if $word =~ s{ (?:
227 ásek | loun | nost | štin | teln |
228 ov (?: ec | ík | in | tv ) # -ovec -ovík -ovin -ovtv
229 ) $}{}x;
230  
231 # -enic -inec -itel → -e -i
232 0 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: (?<= e ) nic | (?<= i ) (?: nec | tel ) ) $//x 0 0 0
233 if $word =~ s{ (?: (?<= e ) nic | (?<= i ) (?: nec | tel ) ) $}{}x;
234 }
235  
236 5 ▶ if ($length > 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 5) 1 4 5
237 1 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ \341rn $//x 0 1 1
238 if $word =~ s{ árn $}{}x;
239  
240 1 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?<= \x{11b} ) nk $//x 0 1 1
241 if $word =~ s{ (?<= ě ) nk $}{}x; # -ěnk → -ě
242  
243 # -ián -isk -ist -išt -itb → -i -í
244 1 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?<= i ) (?: \341n | sk | st | \x{161}t | tb ) $//x 0 1 1
245 if $word =~ s{ (?<= i ) (?: án | sk | st | št | tb ) $}{}x;
246  
247 # -írn → -í
248 1 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?<= \355 ) rn $//x 0 1 1
249 if $word =~ s{ (?<= í ) rn $}{}x;
250  
251 # -och -ost -oun -ouš -out -ovn
252 1 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ o (?: ch | st | un | u\x{161} | ut | vn ) $//x 0 1 1
253 if $word =~ s{ o (?: ch | st | un | uš | ut | vn ) $}{}x;
254  
255 1 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: \x{10d}an | ctv | k\341\x{159} | kyn | n\351\x{159} | n\355k | stv | u\x{161}k ) $//x 0 1 1
256 if $word =~ s{ (?:
257 čan | ctv | kář | kyn | néř | ník | stv | ušk
258 ) $}{}x;
259 }
260  
261 5 ▶ if ($length > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 4) 1 4 5
262 # -ač -áč -an -án -ář -as
263 1 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: a[\x{10d}ns] | \341[\x{10d}n\x{159}] ) $//x 0 1 1
264 if $word =~ s{ (?: a[čns] | á[čnř] ) $}{}x;
265  
266 # -ec -en -ěn -éř -ic -in -it -iv -ín -íř → -e -ě -é -i -í
267 1 ▶ return palatalize($word)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: (?<= e ) [cn] | (?<= \x{11b} ) n | (?<= \351 ) \x{159} | (?<= i ) [cntv] | (?<= \355 ) [n\x{159}] ) $//x 0 1 1
268 if $word =~ s{ (?:
269 (?<= e ) [cn]
270 | (?<= ě ) n
271 | (?<= é ) ř
272 | (?<= i ) [cntv]
273 | (?<= í ) [nř]
274 ) $}{}x;
275  
276 # -čk -čn -dl -nk -ob -oň -ot -ov -tk -tv -ul -vk -yn
277 1 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ (?: \x{10d}[kn] | o[b\x{148}tv] | t[kv] | [du]l | [nv]k | yn ) $//x 0 1 1
278 if $word =~ s{ (?:
279 č[kn] | o[bňtv] | t[kv] | [du]l | [nv]k | yn
280 ) $}{}x;
281 }
282  
283 5 ▶ if ($length > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 3) 2 3 5
284 2 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ [c\x{10d}klnt] $//x 1 1 2
285 if $word =~ s{ [cčklnt] $}{}x;
286 }
287  
288 4 return $word;
289 }
290  
291 49 ▶sub palatalize {
Subroutine palatalize: called CC=5 SCAR=16.1
Pod undocumented
292 49 my ($word) = @_;
293  
294 49 ▶ return $word
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ \x{10d}t[\x{11b}i\355] $/ck/x or $word =~ s/ \x{161}t[\x{11b}i\355] $/sk/x or $word =~ s/ [c\x{10d}][ei] $/k/x or $word =~ s/ [z\x{17e}][ei] $/h/x 19 30 49
Condition100%9/9
$word =~ s/ \x{10d}t[\x{11b}i\355] $/ck/x or $word =~ s/ \x{161}t[\x{11b}i\355] $/sk/x or $word =~ s/ [c\x{10d}][ei] $/k/x or $word =~ s/ [z\x{17e}][ei] $/h/x
l!l&&r!l&&!r
13630
$word =~ s/ \x{10d}t[\x{11b}i\355] $/ck/x or $word =~ s/ \x{161}t[\x{11b}i\355] $/sk/x or $word =~ s/ [c\x{10d}][ei] $/k/x
l!l&&r!l&&!r
8536
$word =~ s/ \x{10d}t[\x{11b}i\355] $/ck/x or $word =~ s/ \x{161}t[\x{11b}i\355] $/sk/x
l!l&&r!l&&!r
3541
MC/DC100%4/4
$word =~ s/ \x{10d}t[\x{11b}i\355] $/ck/x or $word =~ s/ \x{161}t[\x{11b}i\355] $/sk/x or $word =~ s/ [c\x{10d}][ei] $/k/x or $word =~ s/ [z\x{17e}][ei] $/h/x
$word =~ s/ \x{10d}t[\x{11b}i\355] $/ck/x $word =~ s/ \x{161}t[\x{11b}i\355] $/sk/x $word =~ s/ [c\x{10d}][ei] $/k/x $word =~ s/ [z\x{17e}][ei] $/h/x
Truth table100%5/5
A or B or C or D
A= $word =~ s/ \x{10d}t[\x{11b}i\355] $/ck/xB= $word =~ s/ \x{161}t[\x{11b}i\355] $/sk/xC= $word =~ s/ [c\x{10d}][ei] $/k/xD= $word =~ s/ [z\x{17e}][ei] $/h/x
ABCDresult
1XXX1
01XX1
001X1
00011
00000
295 if $word =~ s{ čt[ěií] $}{ck}x # -čtě -čti -čtí → -ck
296 || $word =~ s{ št[ěií] $}{sk}x # -ště -šti -ští → -sk
297 || $word =~ s{ [cč][ei] $}{k}x # -ce -ci -če -či → -k
298 || $word =~ s{ [zž][ei] $}{h}x; # -ze -zi -že -ži → -h
299  
300 30 chop $word;
301  
302 30 return $word;
303 }
304  
305 2 1;
306  
307 __END__
↑ Summary UniNE/BG.pm »