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

filter: Statementstmt 100% 56 / 56 Branchbran 100% 24 / 24 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 97.8% 92 / 94 SCAR 27.7
CC
16
Cov
100%
stem
12.0
stem_aggressive
5.0
BEGIN
1.0
CRAP 16.0
« blib/lib/Lingua/Stem/Patch/PL.pm ↑ Summary blib/lib/Lingua/Stem/Patch/IO.pm »
1 package Lingua::Stem::Patch::EO;
2  
3 4 ▶use v5.8.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 our $VERSION = '0.04';
10 4 our @EXPORT_OK = qw( stem stem_eo stem_aggressive stem_eo_aggressive );
11  
12 4 *stem_eo = \&stem;
13 4 *stem_eo_aggressive = \&stem_aggressive;
14  
15 my %protect = (
16 180 correlative => { map { $_ => 1 } map {
17 20 my $start = $_;
18 20 map { $start . $_ } qw( a al am e el es o om u )
19 } qw( ki ti i ĉi neni ) },
20 260 root => { map { $_ => 1 } qw(
21 ĉar ĉi ĉu kaj ke la minus plus se
22 ĉe da de el ekster en ĝis je kun na po pri pro sen tra
23 ajn do ja jen ju ne pli tamen tre tro
24 ci ĝi ili li mi ni oni ri si ŝi ŝli vi
25 unu du tri kvin
26 ĵus nun plu tuj
27 amen bis boj fi ha he ho hu hura nu ve
28 ) },
29 4 simple => { map { my $root = $_; map { $root . $_ => 1 } qw( a e i o ) } qw(
30 abrikot absint arogant artrit azot balustrad bant bat biskvit blat boat
31 bot briliant cit ĉokolad dat degrad delikat diamant diskont dorlot dot
32 ekscit elefant ermit etat evit flat font frat front frot gad gant genot
33 glad glat glit grad granat granit grat grenad grot hepat hipokrit hont
34 horizont imit incit iniciat intermit invit kalikot kamlot kant kapot
35 karot kat klimat komitat kompat konfit konsonant konstant konstat
36 kontant kot krad kravat kvant kvit lad lekant leŭtenant limonad lit lot
37 markot marmot mat medit merit milit miozot monat mont muskat not oblat
38 palat parad parazit pat perlamot pilot pint pirit plad plant plat plot
39 pont pot predikat privat profit rabat rabot rad rakont rat renkont rilat
40 rot sabat salat sat ŝat skarlat soldat spat spirit spit sprit stat ŝtat
41 strat subit sublimat svat ŝvit terebint tint trikot trot universitat
42 vant vat vizit volont zenit
43 almilit bofrat ciferplat esperant malŝat manplat
44 ) },
45 );
46  
47 sub stem {
48 674 ▶ my $word = lc shift;
Subroutine stem: called CC=12 SCAR=24.8
Pod undocumented
49  
50 674 for ($word) {
51 # standalone roots
52 674 ▶ last if $protect{root}{$word};
Branch: 1 branch
BranchTrueFalseTotal
if $protect{"root"}{$word} 130 544 674
53  
54 # l’ l' → la
55 544 ▶ last if s{ (?<= ^ l ) [’'] $}{a}x;
Branch: 1 branch
BranchTrueFalseTotal
if s/ (?<= ^ l ) [\x{2019}'] $/a/x 4 540 544
56  
57 # un’ un' unuj → unu
58 540 ▶ last if s{ (?<= ^ un ) [’'] $}{u}x;
Branch: 1 branch
BranchTrueFalseTotal
if s/ (?<= ^ un ) [\x{2019}'] $/u/x 4 536 540
59 536 ▶ last if s{ (?<= ^ unu ) j $}{}x;
Branch: 1 branch
BranchTrueFalseTotal
if s/ (?<= ^ unu ) j $//x 2 534 536
60  
61 # -’ -' → -o
62 534 s{ [’'] $}{o}x;
63  
64 # nouns, adjectives, -u correlatives:
65 # -oj -on -ojn → o
66 # -aj -an -ajn → a
67 # -uj -un -ujn → u
68 534 s{ (?<= [aou] ) (?: [jn] | jn ) $}{}x;
69  
70 # correlatives: -en → -e
71 534 s{^ ( (?: [ĉkt] | nen )? ie ) n $}{$1}x;
72  
73 # correlative roots
74 534 ▶ last if $protect{correlative}{$word};
Branch: 1 branch
BranchTrueFalseTotal
if $protect{"correlative"}{$word} 190 344 534
75  
76 # accusative pronouns: -in → -i
77 344 ▶ last if s{ (?<= i ) n $}{}x;
Branch: 1 branch
BranchTrueFalseTotal
if s/ (?<= i ) n $//x 26 318 344
78  
79 # accusative adverbs: -en → -o
80 318 s{ en $}{o}x;
81  
82 # verbs: -is -as -os -us -u → -i
83 318 s{ (?: [aiou] s | u ) $}{i}x;
84  
85 # lexical aspect: ek- el-
86 318 s{^ ek (?! scit ) }{}x;
87 318 s{^ el (?! efant ) }{}x;
88  
89 # simple words: root plus single suffix
90 318 ▶ last if $protect{simple}{$word};
Branch: 1 branch
BranchTrueFalseTotal
if $protect{"simple"}{$word} 8 310 318
91  
92 # imperfective verbs & action nouns: -adi -ado → -i
93 310 ▶ last if s{ ad [io] $}{i}x;
Branch: 1 branch
BranchTrueFalseTotal
if s/ ad [io] $/i/x 8 302 310
94  
95 # compound verbs:
96 # -inti -anti -onti -iti -ati -oti → -i
97 # -inte -ante -onte -ite -ate -ote → -i
98 # -inta -anta -onta -ita -ata -ota → -i
99 302 ▶ last if s{ (?: [aio] n? t ) [aei] $}{i}x;
Branch: 1 branch
BranchTrueFalseTotal
if s/ (?: [aio] n? t ) [aei] $/i/x 132 170 302
100  
101 # participle nouns:
102 # -into -anto -onto → -anto
103 # -ito -ato -oto → -ato
104 170 ▶ last if s{ [aio] ( n? ) to $}{a$1to}x;
Branch: 1 branch
BranchTrueFalseTotal
if s/ [aio] ( n? ) to $/a$1to/x 12 158 170
105 }
106  
107 674 return $word;
108 }
109  
110 sub stem_aggressive {
111 332 ▶ my $word = stem(shift);
Subroutine stem_aggressive: called CC=5 SCAR=16.1
Pod undocumented
112 332 my $copy = $word;
113  
114 332 for ($word) {
115 # protected words
116 last if $protect{root}{$word}
117 332 ▶ || $protect{correlative}{$word};
Branch: 1 branch
BranchTrueFalseTotal
if $protect{"root"}{$word} or $protect{"correlative"}{$word} 177 155 332
Condition100%3/3
$protect{"root"}{$word} or $protect{"correlative"}{$word}
l!l&&r!l&&!r
8295155
MC/DC100%2/2
$protect{"root"}{$word} or $protect{"correlative"}{$word}
$protect{"root"}{$word} $protect{"correlative"}{$word}
Truth table100%3/3
A or B
A= $protect{"root"}{$word}B= $protect{"correlative"}{$word}
ABresult
1X1
011
000
118  
119 # remove final suffix
120 155 s{ [aeio] $}{}x;
121  
122 155 ▶ last if $protect{simple}{$copy};
Branch: 1 branch
BranchTrueFalseTotal
if $protect{"simple"}{$copy} 4 151 155
123  
124 # remove suffix for participle nouns:
125 # -int- -ant- -ont- -it- -at- -ot-
126 151 s{ [aio] n? t $}{}x;
127 }
128  
129 332 return $word;
130 }
131  
132 4 1;
133  
134 __END__
« blib/lib/Lingua/Stem/Patch/PL.pm ↑ Summary blib/lib/Lingua/Stem/Patch/IO.pm »