blib/lib/Lingua/Stem/Cistem.pm

filter: Statementstmt 100% 123 / 123 Branchbran 100% 40 / 40 Conditioncond 84.7% 50 / 59 MC/DCmcdc 70.0% 21 / 30 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 93.2% 247 / 265 CC 42 SCAR 23.4
CC
42
Cov
96%
segment_robust
13.0
segment
11.1
stem_robust
11.0
CRAP 10.3
↑ Summary
1 package Lingua::Stem::Cistem;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 require Exporter;
11  
12 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 $Lingua::Stem::Cistem::VERSION = '0.08';
14 2 @Lingua::Stem::Cistem::ISA = qw(Exporter);
15 2 @Lingua::Stem::Cistem::EXPORT = qw();
16 2 @Lingua::Stem::Cistem::EXPORT_OK = qw(stem segment stem_robust segment_robust);
17 2 %Lingua::Stem::Cistem::EXPORT_TAGS = (
18 'all' => [qw(stem segment stem_robust segment_robust)],
19 'orig' => [qw(stem segment)],
20 'robust' => [qw(stem_robust segment_robust)],
21 );
22 }
23  
24 43 ▶sub stem {
Subroutine stem: called CC=10 SCAR=23.1
Pod documented
25 43 ▶ my $word = shift // '';
Condition50%1/2
shift() // ""
l!l
430
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
26 43 my $case_insensitive = shift;
27  
28 43 my $upper = (ucfirst $word eq $word);
29  
30 43 $word = lc($word);
31 43 $word =~ tr/äöü/aou/;
32 43 $word =~ s/ß/ss/g;
33  
34 43 $word =~ s/^ge(.{4,})/$1/;
35  
36 43 $word =~ s/sch/\$/g;
37 43 $word =~ s/ei/\%/g;
38 43 $word =~ s/ie/\&/g;
39 43 $word =~ s/(.)\1/$1*/g;
40  
41 43 ▶ while(length($word)>3) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $word > 3) 28 26 54
42 28 ▶ if( length($word)>5 && ($word =~ s/e[mr]$// || $word =~ s/nd$//) ) {}
Branch: 3 branches
BranchTrueFalseTotal
if (length $word > 5 and $word =~ s/e[mr]$// || $word =~ s/nd$//) { } 3 25 28
elsif (!$upper || $case_insensitive and $word =~ s/t$//) { } 5 20 25
elsif ($word =~ s/[esn]$//) { } 3 17 20
Condition66%4/6
length $word > 5 and $word =~ s/e[mr]$// || $word =~ s/nd$//
!ll&&!rl&&r
2503
$word =~ s/e[mr]$// or $word =~ s/nd$//
l!l&&r!l&&!r
210
MC/DC33%1/3
length $word > 5 and $word =~ s/e[mr]$// || $word =~ s/nd$//
length $word > 5 $word =~ s/e[mr]$// $word =~ s/nd$//
Truth table75%3/4
A and B or C
A= length $word > 5B= $word =~ s/e[mr]$//C= $word =~ s/nd$//
ABCresult
0XX0
1000
11X1
1011
43 ▶ elsif( (!($upper) || $case_insensitive) && $word =~ s/t$//) {}
Condition100%6/6
!$upper || $case_insensitive and $word =~ s/t$//
!ll&&!rl&&r
1375
not $upper or $case_insensitive
l!l&&r!l&&!r
10213
MC/DC100%3/3
!$upper || $case_insensitive and $word =~ s/t$//
not $upper $case_insensitive $word =~ s/t$//
Truth table80%4/5
not(A) or B and C
A= not $upperB= $case_insensitiveC= $word =~ s/t$//
ABCresult
00X0
1X00
0100
1X11
0111
44 elsif( $word =~ s/[esn]$//) {}
45 17 else { last; }
46 }
47  
48 43 $word =~ s/(.)\*/$1$1/g;
49 43 $word =~ s/\$/sch/g;
50 43 $word =~ s/\%/ei/g;
51 43 $word =~ s/\&/ie/g;
52  
53 43 return $word;
54 }
55  
56 37 ▶sub segment {
Subroutine segment: called CC=11 SCAR=24.0
Pod documented
57 37 ▶ my $word = shift // '';
Condition50%1/2
shift() // ""
l!l
370
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
58 37 my $case_insensitive = shift;
59  
60 37 my $upper = (ucfirst $word eq $word);
61  
62 37 $word = lc($word);
63  
64 37 my $original = $word;
65  
66 37 $word =~ s/sch/\$/g;
67 37 $word =~ s/ei/\%/g;
68 37 $word =~ s/ie/\&/g;
69 37 $word =~ s/(.)\1/$1*/g;
70  
71 37 my $suffix_length = 0;
72  
73 37 ▶ while(length($word)>3){
Branch: 1 branch
BranchTrueFalseTotal
if (length $word > 3) 21 27 48
74 21 ▶ if( length($word)>5 && ($word =~ s/(e[mr])$// || $word =~ s/(nd)$//) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (length $word > 5 and $word =~ s/(e[mr])$// || $word =~ s/(nd)$//) { } 3 18 21
elsif (!$upper || $case_insensitive and $word =~ s/t$//) { } 5 13 18
elsif ($word =~ s/([esn])$//) { } 3 10 13
Condition66%4/6
length $word > 5 and $word =~ s/(e[mr])$// || $word =~ s/(nd)$//
!ll&&!rl&&r
1803
$word =~ s/(e[mr])$// or $word =~ s/(nd)$//
l!l&&r!l&&!r
210
MC/DC33%1/3
length $word > 5 and $word =~ s/(e[mr])$// || $word =~ s/(nd)$//
length $word > 5 $word =~ s/(e[mr])$// $word =~ s/(nd)$//
Truth table75%3/4
A and B or C
A= length $word > 5B= $word =~ s/(e[mr])$//C= $word =~ s/(nd)$//
ABCresult
0XX0
1000
11X1
1011
75 3 $suffix_length += 2;
76 }
77 ▶ elsif( (!($upper) || $case_insensitive) && $word =~ s/t$//) {
Condition83%5/6
!$upper || $case_insensitive and $word =~ s/t$//
!ll&&!rl&&r
1305
not $upper or $case_insensitive
l!l&&r!l&&!r
3213
MC/DC66%2/3
!$upper || $case_insensitive and $word =~ s/t$//
not $upper $case_insensitive $word =~ s/t$//
Truth table60%3/5
not(A) or B and C
A= not $upperB= $case_insensitiveC= $word =~ s/t$//
ABCresult
00X0
1X00
0100
1X11
0111
78 5 $suffix_length++;
79 }
80 elsif( $word =~ s/([esn])$//) {
81 3 $suffix_length++;
82 }
83 10 else{ last; }
84 }
85  
86 37 $word =~ s/(.)\*/$1$1/g;
87  
88 37 $word =~ s/\$/sch/g;
89 37 $word =~ s/\%/ei/g;
90 37 $word =~ s/\&/ie/g;
91  
92 37 my $suffix = '';
93  
94 37 ▶ if( $suffix_length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suffix_length) 11 26 37
95 11 $suffix = substr($original, - $suffix_length);
96 }
97  
98 37 return ($word, $suffix);
99 }
100  
101 51 ▶sub stem_robust {
Subroutine stem_robust: called CC=11 SCAR=24.0
Pod documented
102 51 ▶ my $word = shift // '';
Condition50%1/2
shift() // ""
l!l
510
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
103 51 my $case_insensitive = shift;
104 51 my $keep_ge_prefix = shift;
105  
106 51 my $ucfirst = (ucfirst $word eq $word);
107  
108 51 $word = lc($word);
109 51 $word =~ tr/äöü/aou/;
110 51 $word =~ s/([aou])\N{U+0308}/$1/g; # remove U+0308 COMBINING DIAERESIS
111 51 $word =~ s/ß/ss/g;
112  
113 51 ▶ $word =~ s/^ge(.{4,})/$1/ unless $keep_ge_prefix;
Branch: 1 branch
BranchTrueFalseTotal
unless $keep_ge_prefix 49 2 51
114  
115 51 $word =~ s/sch/\N{U+0006}/g; # \N{U+0006} ACK
116 51 $word =~ s/ei/\N{U+0007}/g; # \N{U+0007} BEL
117 51 $word =~ s/ie/\N{U+0008}/g; # \N{U+0008} BS
118  
119 51 $word =~ s/(.)\1/$1*/g;
120  
121 51 my @graphemes = $word =~ m/\X/g;
122 51 my $length = scalar @graphemes;
123 #my $length = scalar (($word =~ m/\X/g)); # does not work
124  
125 51 ▶ while($length > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 3) 32 32 64
126 32 ▶ if ( $length>5 && ($word =~ s/e[mr]$// || $word =~ s/nd$//) ) {$length -= 2;}
Branch: 3 branches
BranchTrueFalseTotal
if ($length > 5 and $word =~ s/e[mr]$// || $word =~ s/nd$//) { } 3 29 32
elsif (!$ucfirst || $case_insensitive and $word =~ s/t$//) { } 5 24 29
elsif ($word =~ s/[esn]$//) { } 5 19 24
Condition100%6/6
$length > 5 and $word =~ s/e[mr]$// || $word =~ s/nd$//
!ll&&!rl&&r
2453
$word =~ s/e[mr]$// or $word =~ s/nd$//
l!l&&r!l&&!r
215
MC/DC100%3/3
$length > 5 and $word =~ s/e[mr]$// || $word =~ s/nd$//
$length > 5 $word =~ s/e[mr]$// $word =~ s/nd$//
Truth table100%4/4
A and B or C
A= $length > 5B= $word =~ s/e[mr]$//C= $word =~ s/nd$//
ABCresult
0XX0
1000
11X1
1011
127 5 ▶ elsif ( (!($ucfirst) || $case_insensitive) && $word =~ s/t$//) {$length--;}
Condition100%6/6
!$ucfirst || $case_insensitive and $word =~ s/t$//
!ll&&!rl&&r
1775
not $ucfirst or $case_insensitive
l!l&&r!l&&!r
10217
MC/DC100%3/3
!$ucfirst || $case_insensitive and $word =~ s/t$//
not $ucfirst $case_insensitive $word =~ s/t$//
Truth table80%4/5
not(A) or B and C
A= not $ucfirstB= $case_insensitiveC= $word =~ s/t$//
ABCresult
00X0
1X00
0100
1X11
0111
128 5 elsif ( $word =~ s/[esn]$//) {$length--;}
129 19 else { last; }
130 }
131  
132 51 $word =~ s/(.)\*/$1$1/g;
133  
134 51 $word =~ s/\N{U+0006}/sch/g; # \N{U+0006} ACK
135 51 $word =~ s/\N{U+0007}/ei/g; # \N{U+0007} BEL
136 51 $word =~ s/\N{U+0008}/ie/g; # \N{U+0008} BS
137  
138 51 return $word;
139 }
140  
141  
142 51 ▶sub segment_robust {
Subroutine segment_robust: called CC=13 SCAR=25.6
Pod documented
143 51 ▶ my $word = shift // '';
Condition50%1/2
shift() // ""
l!l
510
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
144 51 my $case_insensitive = shift;
145 51 my $keep_ge_prefix = shift;
146  
147 51 my $ucfirst = (ucfirst $word eq $word);
148  
149 51 $word = lc($word);
150 51 $word =~ tr/äöü/aou/;
151 51 $word =~ s/([aou])\N{U+0308}/$1/g; # remove U+0308 COMBINING DIAERESIS
152 51 $word =~ s/ß/ss/g;
153  
154 51 my $prefix = '';
155 51 ▶ if (!$keep_ge_prefix && $word =~ s/^ge(.{4,})/$1/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $keep_ge_prefix and $word =~ s/^ge(.{4,})/$1/) 2 49 51
Condition100%3/3
not $keep_ge_prefix and $word =~ s/^ge(.{4,})/$1/
!ll&&!rl&&r
2472
MC/DC100%2/2
not $keep_ge_prefix and $word =~ s/^ge(.{4,})/$1/
not $keep_ge_prefix $word =~ s/^ge(.{4,})/$1/
Truth table100%3/3
not(A) and B
A= not $keep_ge_prefixB= $word =~ s/^ge(.{4,})/$1/
ABresult
0X0
100
111
156 2 $prefix = 'ge';
157 }
158  
159 51 my $original = $word;
160  
161 51 $word =~ s/sch/\N{U+0006}/g; # \N{U+0006} ACK
162 51 $word =~ s/ei/\N{U+0007}/g; # \N{U+0007} BEL
163 51 $word =~ s/ie/\N{U+0008}/g; # \N{U+0008} BS
164  
165 51 $word =~ s/(.)\1/$1*/g;
166  
167 51 my @graphemes = $word =~ m/\X/g;
168 51 my $length = scalar @graphemes;
169  
170 51 my $suffix_length = 0;
171  
172 51 ▶ while($length > 3){
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 3) 32 32 64
173 32 ▶ if( $length > 5 && ($word =~ s/(e[mr])$// || $word =~ s/(nd)$//) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($length > 5 and $word =~ s/(e[mr])$// || $word =~ s/(nd)$//) { } 3 29 32
elsif (!$ucfirst || $case_insensitive and $word =~ s/t$//) { } 5 24 29
elsif ($word =~ s/([esn])$//) { } 5 19 24
Condition100%6/6
$length > 5 and $word =~ s/(e[mr])$// || $word =~ s/(nd)$//
!ll&&!rl&&r
2453
$word =~ s/(e[mr])$// or $word =~ s/(nd)$//
l!l&&r!l&&!r
215
MC/DC100%3/3
$length > 5 and $word =~ s/(e[mr])$// || $word =~ s/(nd)$//
$length > 5 $word =~ s/(e[mr])$// $word =~ s/(nd)$//
Truth table100%4/4
A and B or C
A= $length > 5B= $word =~ s/(e[mr])$//C= $word =~ s/(nd)$//
ABCresult
0XX0
1000
11X1
1011
174 3 $suffix_length += 2;
175 3 $length -= 2;
176 }
177 ▶ elsif( (!($ucfirst) || $case_insensitive) && $word =~ s/t$//) {
Condition100%6/6
!$ucfirst || $case_insensitive and $word =~ s/t$//
!ll&&!rl&&r
1775
not $ucfirst or $case_insensitive
l!l&&r!l&&!r
10217
MC/DC100%3/3
!$ucfirst || $case_insensitive and $word =~ s/t$//
not $ucfirst $case_insensitive $word =~ s/t$//
Truth table80%4/5
not(A) or B and C
A= not $ucfirstB= $case_insensitiveC= $word =~ s/t$//
ABCresult
00X0
1X00
0100
1X11
0111
178 5 $suffix_length++;
179 5 $length--;
180 }
181 elsif( $word =~ s/([esn])$//) {
182 5 $suffix_length++;
183 5 $length--;
184 }
185 19 else{ last; }
186 }
187  
188 51 $word =~ s/(.)\*/$1$1/g;
189  
190 51 $word =~ s/\N{U+0006}/sch/g; # \N{U+0006} ACK
191 51 $word =~ s/\N{U+0007}/ei/g; # \N{U+0007} BEL
192 51 $word =~ s/\N{U+0008}/ie/g; # \N{U+0008} BS
193  
194 51 my $suffix = '';
195  
196 51 ▶ if( $suffix_length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($suffix_length) 13 38 51
197 13 $suffix = substr($original, - $suffix_length);
198 }
199  
200 51 return ($prefix, $word, $suffix);
201 }
202  
203 2 1;
204 __END__
↑ Summary