Tool/EnglishMorpho/Lemmatizer.pm

filter: Statementstmt 33.1% 64 / 193 Branchbran 5.8% 14 / 238 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 65.0% 13 / 20 Podpod 100% 1 / 1 totaltotal 20.3% 96 / 471 CC 124 SCAR 63.8
CC
124
Cov
19%
_lemmatize_VBG
1190.0
_lemmatize_VBD_VBN
1122.0
_lemmatize_NNS_NNPS
240.0
CRAP 591.8
↑ Summary Tool/EnglishMorpho/Analysis.pm »
1 package Treex::Tool::EnglishMorpho::Lemmatizer;
2 3 $Treex::Tool::EnglishMorpho::Lemmatizer::VERSION = '2.20151102';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Treex::Core::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Treex::Core::Resource qw(require_file_from_share);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 has 'exceptions_filename' => (
12 is => 'ro',
13 init_arg => undef,
14 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
15 1 return require_file_from_share('data/models/lemmatizer/en/exceptions2014_11_21.tsv');
16 },
17 3 );
18  
19 has 'negation_filename' => (
20 is => 'ro',
21 init_arg => undef,
22 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
23 1 return require_file_from_share('data/models/lemmatizer/en/negation');
24 },
25 3 );
26  
27 3 has 'exceptions' => (
28 is => 'ro',
29 builder => '_build_exceptions',
30 init_arg => undef,
31 lazy => 1,
32 );
33  
34 3 has 'negation' => (
35 is => 'ro',
36 builder => '_build_negation',
37 init_arg => undef,
38 lazy => 1,
39 );
40  
41 3 has 'cut_negation' => (
42 isa => 'Bool',
43 default => 1,
44 reader => 'cut_negation',
45 );
46  
47 3 has 'lowercase_proper_names' => (
48 isa => 'Bool',
49 default => 0,
50 reader => 'lowercase_proper_names',
51 );
52  
53 3 my $V = qr/[aeiou]/;
54 3 my $VY = qr/[aeiouy]/;
55 3 my $C = qr/[bcdfghjklmnpqrstvwxyz]/;
56 3 my $CXY = qr/[bcdfghjklmnpqrstvwxz]/;
57 3 my $S = qr/([sxz]|[cs]h)/;
58 3 my $S2 = qr/(ss|zz)/;
59 3 my $PRE = qr/(be|ex|in|mis|pre|pro|re)/;
60  
61 #The most importat sub:
62 #Input: word form and POS tag (Penn style)
63 #Output: lemma and was_negative_prefix
64 1 ▶sub lemmatize {
Subroutine lemmatize: called CC=6 SCAR=21.4
Pod documented
65 1 my ( $self, $word, $tag ) = @_;
66 1 my $negative_prefix = 0;
67  
68 1 ▶ if ( ( $tag !~ /^NNP/ || $self->lowercase_proper_names ) && $word ne 'I' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!($tag =~ /^NNP/) || $self->lowercase_proper_names and $word ne "I") 0 1 1
Condition33%2/6
!($tag =~ /^NNP/) || $self->lowercase_proper_names and $word ne "I"
!ll&&!rl&&r
010
not $tag =~ /^NNP/ or $self->lowercase_proper_names
l!l&&r!l&&!r
100
MC/DC0%0/3
!($tag =~ /^NNP/) || $self->lowercase_proper_names and $word ne "I"
not $tag =~ /^NNP/ $self->lowercase_proper_names $word ne "I"
Truth table20%1/5
not(A) or B and C
A= not $tag =~ /^NNP/B= $self->lowercase_proper_namesC= $word ne "I"
ABCresult
00X0
1X00
0100
1X11
0111
69 0 $word = lc $word;
70 }
71  
72 1 my $entry = $self->exceptions->{$tag}{$word};
73 1 ▶ if ($entry) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry) { } 0 1 1
74 0 return @$entry;
75  
76 }
77 else {
78 1 ▶ if ( $self->cut_negation ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cut_negation) 1 0 1
79 1 ( $word, $negative_prefix ) = $self->_cut_negative_prefix( $word, $tag );
80 }
81 1 return ( $self->_lemmatize_by_rules( $word, $tag ), $negative_prefix );
82 }
83 }
84  
85 1 ▶sub _cut_negative_prefix {
Subroutine _cut_negative_prefix: called CC=3 SCAR=14.2
86 1 my ( $self, $word, $tag ) = @_;
87  
88 # We are interested only in adjectives, adverbs and nouns.
89 # English verbs are negated usually by "not" (don't,...).
90 # Proper nouns (NNP,NNPS) are also left unchanged (Disney, Intel, Irvin... Non-IBM).
91 1 ▶ if ( $tag =~ /^(J.*|R.*|NN|NNS)$/ and $word =~ $self->negation ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /^(J.*|R.*|NN|NNS)$/ and $word =~ $self->negation) 0 1 1
Condition33%1/3
$tag =~ /^(J.*|R.*|NN|NNS)$/ and $word =~ $self->negation
!ll&&!rl&&r
100
MC/DC0%0/2
$tag =~ /^(J.*|R.*|NN|NNS)$/ and $word =~ $self->negation
$tag =~ /^(J.*|R.*|NN|NNS)$/ $word =~ $self->negation
Truth table33%1/3
A and B
A= $tag =~ /^(J.*|R.*|NN|NNS)$/B= $word =~ $self->negation
ABresult
0X0
100
111
92 0 $word =~ s/^(un|in|im|non-?|dis-?|il|ir)//;
93 0 return ( $word, 1 );
94 }
95 1 return ( $word, 0 );
96 }
97  
98 0 ▶sub _lemmatize_NNS_NNPS {
Subroutine _lemmatize_NNS_NNPS: not called CC=15 SCAR=54.8
99 0 my ( $self, $word ) = @_;
100 0 ▶ return $word if $word =~ s/men$/man/; #over 600 words (in BNC)
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/men$/man/ 0 0 0
101 0 ▶ return $word if $word =~ s/shoes$/shoe/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/shoes$/shoe/ 0 0 0
102 0 ▶ return $word if $word =~ s/wives$/wife/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/wives$/wife/ 0 0 0
103 0 ▶ return $word if $word =~ s/(${C}us)es$/$1/; #buses bonuses
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${C}us)es$/$1/ 0 0 0
104  
105 0 ▶ return $word if $word =~ s/(${V}se)s$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${V}se)s$/$1/ 0 0 0
106 0 ▶ return $word if $word =~ s/(.${CXY}z)es$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.${CXY}z)es$/$1/ 0 0 0
107 0 ▶ return $word if $word =~ s/(${VY}ze)s$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${VY}ze)s$/$1/ 0 0 0
108 0 ▶ return $word if $word =~ s/($S2)es$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($S2)es$/$1/ 0 0 0
109 0 ▶ return $word if $word =~ s/(.${V}rse)s$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.${V}rse)s$/$1/ 0 0 0
110 0 ▶ return $word if $word =~ s/onses$/onse/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/onses$/onse/ 0 0 0
111 0 ▶ return $word if $word =~ s/($S)es$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($S)es$/$1/ 0 0 0
112  
113 0 ▶ return $word if $word =~ s/(.$C)ies$/$1y/; #ponies vs ties
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.$C)ies$/$1y/ 0 0 0
114 0 ▶ return $word if $word =~ s/(${CXY}o)es$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${CXY}o)es$/$1/ 0 0 0
115 0 ▶ return $word if $word =~ s/s$//;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/s$// 0 0 0
116 0 return $word;
117 }
118  
119 0 ▶sub _lemmatize_VBG { ## no critic (Subroutines::ProhibitExcessComplexity) this is complex
Subroutine _lemmatize_VBG: not called CC=34 SCAR=70.8
120 0 my ( $self, $word ) = @_;
121 0 ▶ return $word if $word =~ s/(${CXY}z)ing$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${CXY}z)ing$/$1/ 0 0 0
122 0 ▶ return $word if $word =~ s/(${VY}z)ing$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${VY}z)ing$/$1e/ 0 0 0
123 0 ▶ return $word if $word =~ s/($S2)ing$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($S2)ing$/$1/ 0 0 0
124 0 ▶ return $word if $word =~ s/($C${V}ll)ing$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($C${V}ll)ing$/$1/ 0 0 0
125 0 ▶ return $word if $word =~ s/($C${V}($CXY)\2)ing$/$1/; #cancel-ling vs call-ing - exception is needed
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($C$V($CXY)\2)ing$/$1/ 0 0 0
126 0 ▶ return $word if $word =~ s/^($CXY)ing$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/^($CXY)ing$/$1/ 0 0 0
127 0 ▶ return $word if $word =~ s/^($PRE*$C${V}ng)ing$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/^($PRE*$C${V}ng)ing$/$1/ 0 0 0
128 0 ▶ return $word if $word =~ s/icking$/ick/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/icking$/ick/ 0 0 0
129 0 ▶ return $word if $word =~ s/(${C}in)ing$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${C}in)ing$/$1e/ 0 0 0
130 0 ▶ return $word if $word =~ s/($C$V[npwx])ing$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($C${V}[npwx])ing$/$1/ 0 0 0
131 0 ▶ return $word if $word =~ s/(qu$V${C})ing$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(qu$V$C)ing$/$1e/ 0 0 0
132 0 ▶ return $word if $word =~ s/(u${V}d)ing$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(u${V}d)ing$/$1e/ 0 0 0
133 0 ▶ return $word if $word =~ s/(${C}let)ing$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${C}let)ing$/$1e/ 0 0 0
134 0 ▶ return $word if $word =~ s/^($PRE*$C+[ei]t)ing$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/^($PRE*$C+[ei]t)ing$/$1e/ 0 0 0
135 0 ▶ return $word if $word =~ s/([ei]t)ing$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/([ei]t)ing$/$1/ 0 0 0
136 0 ▶ return $word if $word =~ s/($PRE$CXY${CXY}eat)ing$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($PRE$CXY${CXY}eat)ing$/$1/ 0 0 0
137 0 ▶ return $word if $word =~ s/($V$CXY${CXY}eat)ing$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($V$CXY${CXY}eat)ing$/$1e/ 0 0 0
138 0 ▶ return $word if $word =~ s/(.[eo]at)ing$/$1/; #treating vs creating
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.[eo]at)ing$/$1/ 0 0 0
139 0 ▶ return $word if $word =~ s/(.${V}at)ing$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.${V}at)ing$/$1e/ 0 0 0
140 0 ▶ return $word if $word =~ s/($V$V[cgsv])ing$/$1e/; #announcing increasing
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($V${V}[cgsv])ing$/$1e/ 0 0 0
141 0 ▶ return $word if $word =~ s/($V$V$C)ing$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($V$V$C)ing$/$1/ 0 0 0
142 0 ▶ return $word if $word =~ s/(.[rw]l)ing$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.[rw]l)ing$/$1/ 0 0 0
143 0 ▶ return $word if $word =~ s/(.th)ing$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.th)ing$/$1e/ 0 0 0
144 0 ▶ return $word if $word =~ s/($CXY[cglsv])ing$/$1e/; #involving
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${CXY}[cglsv])ing$/$1e/ 0 0 0
145 0 ▶ return $word if $word =~ s/($CXY$CXY)ing$/$1/; #reporting
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($CXY$CXY)ing$/$1/ 0 0 0
146 0 ▶ return $word if $word =~ s/uing$/ue/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/uing$/ue/ 0 0 0
147 0 ▶ return $word if $word =~ s/($VY$VY)ing$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($VY$VY)ing$/$1/ 0 0 0
148 0 ▶ return $word if $word =~ s/ying$/y/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ying$/y/ 0 0 0
149 0 ▶ return $word if $word =~ s/(${CXY}o)ing$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${CXY}o)ing$/$1/ 0 0 0
150 0 ▶ return $word if $word =~ s/^($PRE*$C+or)ing$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/^($PRE*$C+or)ing$/$1e/ 0 0 0
151 0 ▶ return $word if $word =~ s/($C[clt]or)ing$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${C}[clt]or)ing$/$1e/ 0 0 0
152 0 ▶ return $word if $word =~ s/([eo]r)ing$/$1/; #offering
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/([eo]r)ing$/$1/ 0 0 0
153 0 ▶ return $word if $word =~ s/ing$/e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ing$/e/ 0 0 0
154 0 return $word;
155 }
156  
157 0 ▶sub _lemmatize_VBD_VBN { ## no critic (Subroutines::ProhibitExcessComplexity) this is complex
Subroutine _lemmatize_VBD_VBN: not called CC=33 SCAR=70.2
158 0 my ( $self, $word ) = @_;
159 0 ▶ return $word if $word =~ s/en$/e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/en$/e/ 0 0 0
160 0 ▶ return $word if $word =~ s/(${CXY}z)ed$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${CXY}z)ed$/$1/ 0 0 0
161 0 ▶ return $word if $word =~ s/(${VY}z)ed$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${VY}z)ed$/$1e/ 0 0 0
162 0 ▶ return $word if $word =~ s/($S2)ed$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($S2)ed$/$1/ 0 0 0
163 0 ▶ return $word if $word =~ s/($C${V}ll)ed$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($C${V}ll)ed$/$1/ 0 0 0
164 0 ▶ return $word if $word =~ s/($C${V}($CXY)\2)ed$/$1/; #cancel-led vs call-ed - wordlist is needed
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($C$V($CXY)\2)ed$/$1/ 0 0 0
165 0 ▶ return $word if $word =~ s/^($CXY)ed$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/^($CXY)ed$/$1/ 0 0 0
166 0 ▶ return $word if $word =~ s/^($PRE*$C${V}ng)ed$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/^($PRE*$C${V}ng)ed$/$1/ 0 0 0
167 0 ▶ return $word if $word =~ s/icked$/ick/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/icked$/ick/ 0 0 0
168 0 ▶ return $word if $word =~ s/(${C}(in|[clnt]or))ed$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($C(in|[clnt]or))ed$/$1e/ 0 0 0
169 0 ▶ return $word if $word =~ s/($C$V[npwx])ed$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($C${V}[npwx])ed$/$1/ 0 0 0
170 0 ▶ return $word if $word =~ s/^($PRE*$C+or)ed$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/^($PRE*$C+or)ed$/$1e/ 0 0 0
171 0 ▶ return $word if $word =~ s/([eo]r)ed$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/([eo]r)ed$/$1/ 0 0 0
172 0 ▶ return $word if $word =~ s/(${C})ied$/$1y/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($C)ied$/$1y/ 0 0 0
173 0 ▶ return $word if $word =~ s/(qu$V${C})ed$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(qu$V$C)ed$/$1e/ 0 0 0
174 0 ▶ return $word if $word =~ s/(u${V}d)ed$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(u${V}d)ed$/$1e/ 0 0 0
175 0 ▶ return $word if $word =~ s/(${C}let)ed$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${C}let)ed$/$1e/ 0 0 0
176 0 ▶ return $word if $word =~ s/^($PRE*$C+[ei]t)ed$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/^($PRE*$C+[ei]t)ed$/$1e/ 0 0 0
177 0 ▶ return $word if $word =~ s/([ei]t)ed$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/([ei]t)ed$/$1/ 0 0 0
178 0 ▶ return $word if $word =~ s/($PRE$CXY${CXY}eat)ed$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($PRE$CXY${CXY}eat)ed$/$1/ 0 0 0
179 0 ▶ return $word if $word =~ s/($V$CXY${CXY}eat)ed$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($V$CXY${CXY}eat)ed$/$1e/ 0 0 0
180 0 ▶ return $word if $word =~ s/(.[eo]at)ed$/$1/; #treated vs created
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.[eo]at)ed$/$1/ 0 0 0
181 0 ▶ return $word if $word =~ s/(.${V}at)ed$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.${V}at)ed$/$1e/ 0 0 0
182 0 ▶ return $word if $word =~ s/($V$V[cgsv])ed$/$1e/; #announced
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($V${V}[cgsv])ed$/$1e/ 0 0 0
183 0 ▶ return $word if $word =~ s/($V$V$C)ed$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($V$V$C)ed$/$1/ 0 0 0
184 0 ▶ return $word if $word =~ s/(.[rw]l)ed$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.[rw]l)ed$/$1/ 0 0 0
185 0 ▶ return $word if $word =~ s/(.th)ed$/$1e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.th)ed$/$1e/ 0 0 0
186 0 ▶ return $word if $word =~ s/ued$/ue/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ued$/ue/ 0 0 0
187 0 ▶ return $word if $word =~ s/($CXY[cglsv])ed$/$1e/; #involved
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${CXY}[cglsv])ed$/$1e/ 0 0 0
188 0 ▶ return $word if $word =~ s/($CXY$CXY)ed$/$1/; #reported
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($CXY$CXY)ed$/$1/ 0 0 0
189 0 ▶ return $word if $word =~ s/($VY$VY)ed$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($VY$VY)ed$/$1/ 0 0 0
190 0 ▶ return $word if $word =~ s/ed$/e/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ed$/e/ 0 0 0
191 0 return $word;
192 }
193  
194 0 ▶sub _lemmatize_VBZ {
Subroutine _lemmatize_VBZ: not called CC=11 SCAR=48.8
195 0 my ( $self, $word ) = @_;
196 0 ▶ return $word if $word =~ s/(${V}se)s$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${V}se)s$/$1/ 0 0 0
197 0 ▶ return $word if $word =~ s/(.${CXY}z)es$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.${CXY}z)es$/$1/ 0 0 0
198 0 ▶ return $word if $word =~ s/(${VY}ze)s$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${VY}ze)s$/$1/ 0 0 0
199 0 ▶ return $word if $word =~ s/($S2)es$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($S2)es$/$1/ 0 0 0
200 0 ▶ return $word if $word =~ s/(.${V}rse)s$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.${V}rse)s$/$1/ 0 0 0
201 0 ▶ return $word if $word =~ s/onses$/onse/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/onses$/onse/ 0 0 0
202 0 ▶ return $word if $word =~ s/($S)es$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($S)es$/$1/ 0 0 0
203  
204 0 ▶ return $word if $word =~ s/(.$C)ies$/$1y/; #tries, relies vs lies
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.$C)ies$/$1y/ 0 0 0
205 0 ▶ return $word if $word =~ s/(${CXY}o)es$/$1/; #does, undergoes
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(${CXY}o)es$/$1/ 0 0 0
206 0 ▶ return $word if $word =~ s/(.)s$/$1/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.)s$/$1/ 0 0 0
207 0 return $word;
208 }
209  
210 0 ▶sub _lemmatize_JJR_RBR {
Subroutine _lemmatize_JJR_RBR: not called CC=10 SCAR=47.0
211 0 my ( $self, $word ) = @_;
212 0 ▶ return $word if $word =~ s/([^e]ll)er$/$1/; #smaller
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/([^e]ll)er$/$1/ 0 0 0
213 0 ▶ return $word if $word =~ s/($C)\1er$/$1/; #bigger
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($C)\1er$/$1/ 0 0 0
214 0 ▶ return $word if $word =~ s/ier$/y/; #earlier
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/ier$/y/ 0 0 0
215 0 ▶ return $word if $word =~ s/($V$V$C)er$/$1/; #weaker
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($V$V$C)er$/$1/ 0 0 0
216 0 ▶ return $word if $word =~ s/($C$V[npwx])er$/$1/; #lower
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($C${V}[npwx])er$/$1/ 0 0 0
217 0 ▶ return $word if $word =~ s/($V$C)er$/$1e/; #nicer wider
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($V$C)er$/$1e/ 0 0 0
218 0 ▶ return $word if $word =~ s/([bcdfghjklmpqrstvwxz][cglsv])er$/$1e/; #larger,stranger vs stronger, younger
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/([bcdfghjklmpqrstvwxz][cglsv])er$/$1e/ 0 0 0
219 0 ▶ return $word if $word =~ s/([ue])er$/$1e/; #freer
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/([ue])er$/$1e/ 0 0 0
220 0 ▶ return $word if $word =~ s/er$//; #harder
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/er$// 0 0 0
221 0 return $word;
222 }
223  
224 0 ▶sub _lemmatize_JJS_RBS {
Subroutine _lemmatize_JJS_RBS: not called CC=9 SCAR=45.0
225 0 my ( $self, $word ) = @_;
226 0 ▶ return $word if $word =~ s/([^e]ll)est$/$1/; #smallest
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/([^e]ll)est$/$1/ 0 0 0
227 0 ▶ return $word if $word =~ s/(.)\1est$/$1/; #biggest
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.)\1est$/$1/ 0 0 0
228 0 ▶ return $word if $word =~ s/iest$/y/; #earliest
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/iest$/y/ 0 0 0
229 0 ▶ return $word if $word =~ s/($V$V$C)est$/$1/; #weakest
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($V$V$C)est$/$1/ 0 0 0
230 0 ▶ return $word if $word =~ s/($C$V[npwx])est$/$1/; #lowest
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($C${V}[npwx])est$/$1/ 0 0 0
231 0 ▶ return $word if $word =~ s/($V$C)est$/$1e/; #nicest widest
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/($V$C)est$/$1e/ 0 0 0
232 0 ▶ return $word if $word =~ s/([bcdfghjklmpqrstvwxz][cglsv])est$/$1e/; #largest vs strongest
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/([bcdfghjklmpqrstvwxz][cglsv])est$/$1e/ 0 0 0
233 0 ▶ return $word if $word =~ s/(.{3,})est$/$1/; #hardest
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ s/(.{3,})est$/$1/ 0 0 0
234 0 return $word;
235 }
236  
237 1 ▶sub _lemmatize_by_rules {
Subroutine _lemmatize_by_rules: called CC=8 SCAR=24.7
238 1 my ( $self, $word, $tag ) = @_;
239  
240 1 ▶ my $lemma = $tag =~ /NNP?S/
Branch: 6 branches
BranchTrueFalseTotal
$tag =~ /NNP?S/ ? : 0 1 1
$tag =~ /^VBG/ ? : 0 1 1
$tag =~ /VB[DN]/ ? : 0 1 1
$tag eq 'VBZ' ? : 0 1 1
$tag =~ /JJR|RBR/ ? : 0 1 1
$tag =~ /JJS|RBS/ ? : 0 1 1
241 ? $self->_lemmatize_NNS_NNPS($word)
242 : $tag =~ /^VBG/ ? $self->_lemmatize_VBG($word)
243 : $tag =~ /VB[DN]/ ? $self->_lemmatize_VBD_VBN($word)
244 : $tag eq 'VBZ' ? $self->_lemmatize_VBZ($word)
245 : $tag =~ /JJR|RBR/ ? $self->_lemmatize_JJR_RBR($word)
246 : $tag =~ /JJS|RBS/ ? $self->_lemmatize_JJS_RBS($word)
247 : $word
248 ;
249 1 ▶ return $word if $lemma eq ''; # Otherwise e.g. "est"->""
Branch: 1 branch
BranchTrueFalseTotal
if $lemma eq "" 0 1 1
250 1 return $lemma;
251 }
252  
253 1 ▶sub _build_exceptions {
Subroutine _build_exceptions: called CC=4 SCAR=14.0
254 1 my $self = shift;
255 1 my %exceptions;
256 1 log_debug( $self->exceptions_filename );
257 1 ▶ open my $ex_file, "<:encoding(utf-8)", $self->exceptions_filename or log_fatal($!);
Branch: 1 branch
BranchTrueFalseTotal
open my $ex_file, "<:encoding(utf-8)", $self->exceptions_filename or log_fatal($!) 1 0 1
258 1 ▶ while (<$ex_file>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $ex_file)) 5610 1 5611
259 5610 chomp;
260 5610 my ( $word, $tag, $lemma, $negative_prefix ) = split /\t/;
261  
262 5610 ▶ $negative_prefix = ( defined $negative_prefix and $negative_prefix eq '1' );
Condition33%1/3
defined $negative_prefix && $negative_prefix eq '1'
!ll&&!rl&&r
561000
MC/DC0%0/2
defined $negative_prefix && $negative_prefix eq '1'
defined $negative_prefix $negative_prefix eq '1'
Truth table33%1/3
A && B
A= defined $negative_prefixB= $negative_prefix eq '1'
ABresult
0X0
100
111
263 5610 $exceptions{$tag}{$word} = [ $lemma, $negative_prefix ];
264 }
265 1 close $ex_file;
266 1 return \%exceptions;
267 }
268  
269 0 ▶sub _build_negation {
Subroutine _build_negation: not called CC=1 SCAR=6.9
270 0 my $self = shift;
271 0 my $pattern = '';
272 0 my @lines = read_file( $self->negation_filename, binmode => ':encoding(utf-8)', err_mode => 'log_fatal' );
273  
274 # or log_fatal('Cannot load lemmatization exceptions from ' . $self->negation_filename);
275 0 chomp(@lines);
276 0 $pattern = join '|', @lines;
277  
278 #$pattern =~ s/-/\-/g;
279 0 my $negation = qr/^($pattern)/;
280 0 return $negation;
281 }
282  
283 3 1;
284  
285 __END__
↑ Summary Tool/EnglishMorpho/Analysis.pm »