MSTperl/FeaturesControl.pm

filter: Statementstmt 60.8% 364 / 598 Branchbran 59.0% 130 / 220 Conditioncond 37.8% 31 / 82 MC/DCmcdc 16.6% 7 / 42 Subroutinesub 60.6% 54 / 89 Podpod 35.7% 25 / 70 totaltotal 55.5% 611 / 1101 CC 149 SCAR 27.4
CC
149
Cov
58%
feature_equals
90.0
feature_equals_pc
90.0
feature_substr_parent
30.0
CRAP 15.5
« MSTperl/TrainerBase.pm ↑ Summary MSTperl/Parser.pm »
1 package Treex::Tool::Parser::MSTperl::FeaturesControl;
2 {
3 4 $Treex::Tool::Parser::MSTperl::FeaturesControl::VERSION = '0.11949';
4 }
5  
6 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use Treex::Tool::Parser::MSTperl::ModelAdditional;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # TODO dynamic features
13  
14 4 has 'config' => (
15 isa => 'Treex::Tool::Parser::MSTperl::Config',
16 is => 'ro',
17 required => '1',
18 weak_ref => '1',
19 );
20  
21 # FEATURES
22  
23 4 has 'feature_count' => (
24 is => 'rw',
25 isa => 'Int',
26 );
27  
28 has 'feature_codes_from_config' => (
29 is => 'rw',
30 isa => 'ArrayRef[Str]',
31 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 4 );
33  
34 has 'feature_codes' => (
35 is => 'rw',
36 isa => 'ArrayRef[Str]',
37 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
38 4 );
39  
40 has 'feature_codes_hash' => (
41 is => 'rw',
42 isa => 'HashRef[Str]',
43 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 4 );
45  
46 has 'feature_indexes' => (
47 is => 'rw',
48 isa => 'HashRef[Str]',
49 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
50 4 );
51  
52 # for each feature contains (a reference to) an array
53 # which cointains all its subfeature indexes
54 has 'feature_simple_features_indexes' => (
55 is => 'rw',
56 isa => 'ArrayRef[ArrayRef[Int]]',
57 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
58 4 );
59  
60 # features containing array simple features
61 has 'array_features' => (
62 is => 'rw',
63 isa => 'HashRef[Int]',
64 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
65 4 );
66  
67 # features containing dynamic simple features
68 has 'dynamic_features' => (
69 is => 'rw',
70 isa => 'HashRef[Int]',
71 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
72 4 );
73  
74 # SIMPLE FEATURES
75  
76 4 has 'simple_feature_count' => (
77 is => 'rw',
78 isa => 'Int',
79 );
80  
81 has 'simple_feature_codes' => (
82 is => 'rw',
83 isa => 'ArrayRef[Str]',
84 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
85 4 );
86  
87 has 'simple_feature_codes_hash' => (
88 is => 'rw',
89 isa => 'HashRef[Str]',
90 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
91 4 );
92  
93 has 'simple_feature_indexes' => (
94 is => 'rw',
95 isa => 'HashRef[Str]',
96 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
97 4 );
98  
99 has 'simple_feature_subs' => (
100 is => 'rw',
101 isa => 'ArrayRef',
102 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
103 4 );
104  
105 has 'simple_feature_sub_arguments' => (
106 is => 'rw',
107 isa => 'ArrayRef',
108 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
109 4 );
110  
111 # simple features that return an array of values
112 has 'array_simple_features' => (
113 is => 'rw',
114 isa => 'HashRef[Int]',
115 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
116 4 );
117  
118 # simple features that must be always recomputed
119 # because their value cannot be always computed from input data
120 # (for labeller - parent's label, brother's label etc.)
121 has 'dynamic_simple_features' => (
122 is => 'rw',
123 isa => 'HashRef[Int]',
124 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
125 4 );
126  
127 # # simple features that get more than 1 argument as input
128 # has 'multiarg_simple_features' => (
129 # is => 'rw',
130 # isa => 'HashRef[Int]',
131 # default => sub { {} },
132 # );
133  
134 # CACHING
135  
136 4 has 'use_edge_features_cache' => (
137 is => 'ro',
138 isa => 'Bool',
139 default => '0',
140 );
141  
142 # using cache turned off to fit into RAM by default
143 # turn on if training with a lot of RAM or on small training data
144 # turned off when parsing (does not make any sense for parsing)
145  
146 has 'edge_features_cache' => (
147 is => 'rw',
148 isa => 'HashRef[ArrayRef[Str]]',
149 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
150 4 );
151  
152 4 has pmi_model => (
153 is => 'rw',
154 isa => 'Maybe[Treex::Tool::Parser::MSTperl::ModelAdditional]',
155 default => undef,
156 );
157  
158 4 has cprob_model => (
159 is => 'rw',
160 isa => 'Maybe[Treex::Tool::Parser::MSTperl::ModelAdditional]',
161 default => undef,
162 );
163  
164 2 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
165 2 my ($self) = @_;
166  
167 # ignore some settings if in parsing-only mode
168 # if ( !$self->training ) {
169 # $self->use_edge_features_cache(0);
170 # }
171  
172 # features
173 2 foreach my $feature ( @{ $self->feature_codes_from_config } ) {
174 48 $self->set_feature($feature);
175 }
176  
177 2 $self->feature_count( scalar( @{ $self->feature_codes } ) );
178 2 $self->simple_feature_count( scalar( @{ $self->simple_feature_codes } ) );
179  
180 2 return;
181 }
182  
183 48 ▶sub set_feature {
Subroutine set_feature: called CC=9 SCAR=22.1
Pod documented
184 48 my ( $self, $feature_code ) = @_;
185  
186 48 ▶ if ( $self->feature_codes_hash->{$feature_code} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->feature_codes_hash->{$feature_code}) { } 0 48 48
187 0 warn "Feature '$feature_code' is defined more than once; " .
188 "disregarding its later definitions.\n";
189 } else {
190  
191 # get simple features
192 48 my $isArrayFeature = 0;
193 48 my $isDynamicFeature = 0;
194 48 my @simple_features_indexes;
195 my %simple_features_hash;
196 48 foreach my $simple_feature_code ( split( /\|/, $feature_code ) ) {
197  
198 # checks
199 131 ▶ if ( $simple_features_hash{$simple_feature_code} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($simple_features_hash{$simple_feature_code}) 0 131 131
200 0 warn "Simple feature '$simple_feature_code' " .
201 "is used more than once in '$feature_code'; " .
202 "disregarding its later uses.\n";
203 0 next;
204 }
205 131 ▶ if ( !$self->simple_feature_codes_hash->{$simple_feature_code} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->simple_feature_codes_hash->{$simple_feature_code}) 42 89 131
206  
207 # this simple feature has not been used at all yet
208 42 $self->set_simple_feature($simple_feature_code);
209 }
210  
211 # save
212 my $simple_feature_index =
213 131 $self->simple_feature_indexes->{$simple_feature_code};
214 131 $simple_features_hash{$simple_feature_code} = 1;
215 131 ▶ if ( $self->array_simple_features->{$simple_feature_index} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->array_simple_features->{$simple_feature_index}) 2 129 131
216 2 $isArrayFeature = 1;
217 }
218 131 ▶ if ( $self->dynamic_simple_features->{$simple_feature_index} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dynamic_simple_features->{$simple_feature_index}) 3 128 131
219 3 $isDynamicFeature = 1;
220 }
221 131 push @simple_features_indexes, $simple_feature_index;
222 }
223  
224 # save
225 48 my $feature_index = scalar( @{ $self->feature_codes } );
226 48 $self->feature_codes_hash->{$feature_code} = 1;
227 48 $self->feature_indexes->{$feature_code} = $feature_index;
228 48 push @{ $self->feature_codes }, $feature_code;
229 48 push @{ $self->feature_simple_features_indexes },
230 [@simple_features_indexes];
231 48 ▶ if ($isArrayFeature) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isArrayFeature) 2 46 48
232 2 $self->array_features->{$feature_index} = 1;
233 }
234 48 ▶ if ($isDynamicFeature) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isDynamicFeature) 3 45 48
235 3 $self->dynamic_features->{$feature_index} = 1;
236 }
237 }
238  
239 48 return;
240 }
241  
242 42 ▶sub set_simple_feature {
Subroutine set_simple_feature: called CC=23 SCAR=32.7
Pod documented
243 42 my ( $self, $simple_feature_code ) = @_;
244  
245 # get sub reference and field index
246 42 my $simple_feature_index = scalar @{ $self->simple_feature_codes };
247 42 my $simple_feature_sub;
248 my $simple_feature_field;
249  
250 # simple parent/child feature
251 42 ▶ if ( $simple_feature_code =~ /^([a-zA-Z0-9_]+)$/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($simple_feature_code =~ /^([a-zA-Z0-9_]+)$/) { } 8 34 42
elsif ($simple_feature_code =~ /^([12gGlr])\.([a-z0-9_]+)$/) { } 6 28 34
elsif ($simple_feature_code =~ /^([12gGlr\.a-z]+|[A-Z]+)\([-a-z0-9_,]*\)$/) { } 28 0 28
252  
253 8 ▶ if ( $simple_feature_code =~ /^([a-z0-9_]+)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($simple_feature_code =~ /^([a-z0-9_]+)$/) { } 4 4 8
elsif ($simple_feature_code =~ /^([A-Z0-9_]+)$/) { } 4 0 4
254  
255 # child feature
256 4 $simple_feature_sub = \&{feature_child};
257 4 $simple_feature_field = $1;
258 } elsif ( $simple_feature_code =~ /^([A-Z0-9_]+)$/ ) {
259  
260 # parent feature
261 4 $simple_feature_sub = \&{feature_parent};
262 4 $simple_feature_field = lc($1);
263 } else {
264 0 die "Incorrect simple feature format '$simple_feature_code'. " .
265 "Use lowercase (" . lc($simple_feature_code) .
266 ") for child node and UPPERCASE (" . uc($simple_feature_code) .
267 ") for parent node.\n";
268 }
269  
270 # first/second/(left sibling)/(right sibling)/Grandparent/grandchildren
271 # node feature
272 } elsif ( $simple_feature_code =~ /^([12gGlr])\.([a-z0-9_]+)$/ ) {
273  
274 6 $simple_feature_field = $2;
275  
276 6 ▶ if ( $1 eq '1' ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($1 eq '1') { } 2 4 6
elsif ($1 eq '2') { } 2 2 4
elsif ($1 eq 'g') { } 0 2 2
elsif ($1 eq 'G') { } 1 1 2
elsif ($1 eq 'l') { } 1 0 1
elsif ($1 eq 'r') { } 0 0 0
277  
278 # first node feature
279 2 $simple_feature_sub = \&{feature_first};
280 } elsif ( $1 eq '2' ) {
281  
282 # second node feature
283 2 $simple_feature_sub = \&{feature_second};
284 } elsif ( $1 eq 'g' ) {
285  
286 # grandchildren node feature
287 0 $simple_feature_sub = \&{feature_grandchildren};
288 } elsif ( $1 eq 'G' ) {
289  
290 # grandparent node feature
291 1 $simple_feature_sub = \&{feature_grandparent};
292 } elsif ( $1 eq 'l' ) {
293  
294 # left sibling edge child feature
295 1 $simple_feature_sub = \&{feature_left_sibling};
296 } elsif ( $1 eq 'r' ) {
297  
298 # right sibling edge child feature
299 0 $simple_feature_sub = \&{feature_right_sibling};
300 } else {
301 0 croak "Assertion failed!";
302 }
303  
304 # function feature
305 } elsif (
306 $simple_feature_code
307 =~ /^([12gGlr\.a-z]+|[A-Z]+)\([-a-z0-9_,]*\)$/
308 )
309 {
310 28 my $function_name = $1;
311 28 $simple_feature_sub =
312 $self->get_simple_feature_sub_reference($function_name);
313  
314 28 ▶ if ($function_name eq 'between'
Branch: 1 branch
BranchTrueFalseTotal
if ($function_name eq "between" or $function_name eq "foreach" or substr($function_name, 0, 2) eq "g.") 2 26 28
Condition66%4/6
$function_name eq "between" or $function_name eq "foreach" or substr($function_name, 0, 2) eq "g."
l!l&&r!l&&!r
2026
$function_name eq "between" or $function_name eq "foreach"
l!l&&r!l&&!r
2026
MC/DC33%1/3
$function_name eq "between" or $function_name eq "foreach" or substr($function_name, 0, 2) eq "g."
$function_name eq "between" $function_name eq "foreach" substr($function_name, 0, 2) eq "g."
Truth table50%2/4
A or B or C
A= $function_name eq "between"B= $function_name eq "foreach"C= substr($function_name, 0, 2) eq "g."
ABCresult
1XX1
01X1
0011
0000
315 || $function_name eq 'foreach'
316 || substr( $function_name, 0, 2 ) eq 'g.'
317 )
318 {
319  
320 # array function
321 2 $self->array_simple_features->{$simple_feature_index} = 1;
322 }
323  
324 28 ▶ if ($function_name eq 'LABEL'
Branch: 1 branch
BranchTrueFalseTotal
if ($function_name eq "LABEL" or $function_name eq "l.label" or $function_name eq "prevlabel" or $function_name eq "G.label" or $function_name eq "g.label") 3 25 28
Condition83%10/12
$function_name eq "LABEL" or $function_name eq "l.label" or $function_name eq "prevlabel" or $function_name eq "G.label" or $function_name eq "g.label"
l!l&&r!l&&!r
3025
$function_name eq "LABEL" or $function_name eq "l.label" or $function_name eq "prevlabel" or $function_name eq "G.label"
l!l&&r!l&&!r
2125
$function_name eq "LABEL" or $function_name eq "l.label" or $function_name eq "prevlabel"
l!l&&r!l&&!r
2026
$function_name eq "LABEL" or $function_name eq "l.label"
l!l&&r!l&&!r
1126
MC/DC60%3/5
$function_name eq "LABEL" or $function_name eq "l.label" or $function_name eq "prevlabel" or $function_name eq "G.label" or $function_name eq "g.label"
$function_name eq "LABEL" $function_name eq "l.label" $function_name eq "prevlabel" $function_name eq "G.label" $function_name eq "g.label"
Truth table66%4/6
A or B or C or D or E
A= $function_name eq "LABEL"B= $function_name eq "l.label"C= $function_name eq "prevlabel"D= $function_name eq "G.label"E= $function_name eq "g.label"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
325 || $function_name eq 'l.label' || $function_name eq 'prevlabel'
326 || $function_name eq 'G.label'
327 || $function_name eq 'g.label'
328 )
329 {
330  
331 # dynamic feature
332 3 $self->dynamic_simple_features->{$simple_feature_index} = 1;
333 }
334  
335 # set $simple_feature_field
336 28 ▶ if ( $simple_feature_code =~ /$function_name\(\)$/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($simple_feature_code =~ /$function_name\(\)$/) { } 9 19 28
elsif ($simple_feature_code =~ /$function_name\(([-a-z0-9_]+)\)$/) { } 14 5 19
elsif ($simple_feature_code =~ /$function_name\(([-a-z0-9_,]+)\)$/) { } 5 0 5
337  
338 # no-arg function feature
339 9 $simple_feature_field = [];
340 } elsif ( $simple_feature_code =~ /$function_name\(([-a-z0-9_]+)\)$/ ) {
341  
342 # one-arg function feature
343 14 $simple_feature_field = $1;
344 } elsif (
345 $simple_feature_code
346 =~ /$function_name\(([-a-z0-9_,]+)\)$/
347 )
348 {
349  
350 # multiarg function feature
351 5 my @fields = split /,/, $1;
352 5 $simple_feature_field = \@fields;
353 } else {
354 0 die "Incorrect simple function feature format " .
355 "'$simple_feature_code'.\n";
356 }
357 } else {
358 0 die "Incorrect simple feature format '$simple_feature_code'.\n";
359 }
360  
361 # if $simple_feature_field is (a ref to) an array of field names,
362 # handles that correctly by iterating over the array and returning
363 # an array of field indexes;
364 # if there is an integer argument instead of a field name,
365 # detects that and keeps that integer unchanged
366 42 my $simple_feature_sub_arguments =
367 $self->config->field_name2index($simple_feature_field);
368  
369 # save
370 42 $self->simple_feature_codes_hash->{$simple_feature_code} = 1;
371 42 $self->simple_feature_indexes->{$simple_feature_code} =
372 $simple_feature_index;
373 42 push @{ $self->simple_feature_codes }, $simple_feature_code;
374 42 push @{ $self->simple_feature_subs }, $simple_feature_sub;
375 42 push @{ $self->simple_feature_sub_arguments },
376 $simple_feature_sub_arguments;
377  
378 42 return;
379 }
380  
381 # FEATURES COMPUTATION
382  
383 # array (ref) of all features of the edge,
384 # in the form of "feature_index:values_string" strings,
385 # where feature_index is the index of the feature
386 # (index in feature_codes, translatable via feature_indexes)
387 # and values_string are values of corresponding simple features,
388 # joined together by '|'
389 # (if any of the simple features does not return a value, the whole feature
390 # is not present)
391 # TODO maybe not returning a value is still a valuable information -> include?
392 4531 ▶sub get_all_features {
Subroutine get_all_features: called CC=14 SCAR=32.9
Pod documented
393  
394 # Edge; 0: all features, 1: only dynamic, -1: only non-dynamic
395 # either get only dynamic features or get all but dynamic features
396 4531 my ( $self, $edge, $only_dynamic_features ) = @_;
397  
398 # try to get features from cache
399 # TODO: cache not used now and probably does not even work:
400 # check&fix or remove
401 4531 my $edge_signature;
402 4531 ▶ if ( $self->use_edge_features_cache ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_edge_features_cache) 0 4531 4531
403 0 $edge_signature = $edge->signature();
404  
405 0 my $cache_features = $self->edge_features_cache->{$edge_signature};
406 0 ▶ if ($cache_features) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_features) 0 0 0
407 0 return $cache_features;
408 }
409 }
410  
411 # double else: if cache not used or if edge features not found in cache
412 4531 my $simple_feature_values = $self->get_simple_feature_values_array($edge);
413 4531 my @features;
414 4531 my $features_count = $self->feature_count;
415 4531 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($feature_index < $features_count) 91289 4531 95820
416 my $feature_index = 0;
417 $feature_index < $features_count;
418 $feature_index++
419 )
420 {
421 91289 ▶ if ($only_dynamic_features
Branch: 2 branches
BranchTrueFalseTotal
if ($only_dynamic_features and $only_dynamic_features == 1 and not $self->dynamic_features->{$feature_index}) { } 0 91289 91289
elsif ($only_dynamic_features and $only_dynamic_features == -1 and $self->dynamic_features->{$feature_index}) { } 0 91289 91289
Condition33%2/6
$only_dynamic_features and $only_dynamic_features == 1 and not $self->dynamic_features->{$feature_index}
!ll&&!rl&&r
9128900
$only_dynamic_features and $only_dynamic_features == 1
!ll&&!rl&&r
9128900
MC/DC0%0/3
$only_dynamic_features and $only_dynamic_features == 1 and not $self->dynamic_features->{$feature_index}
$only_dynamic_features $only_dynamic_features == 1 not $self->dynamic_features->{$feature_index}
Truth table25%1/4
A and B and not(C)
A= $only_dynamic_featuresB= $only_dynamic_features == 1C= not $self->dynamic_features->{$feature_index}
ABCresult
0XX0
10X0
1100
1111
422 && $only_dynamic_features == 1
423 && !$self->dynamic_features->{$feature_index}
424 )
425 {
426 0 next;
427 ▶ } elsif (
Condition33%2/6
$only_dynamic_features and $only_dynamic_features == -1 and $self->dynamic_features->{$feature_index}
!ll&&!rl&&r
9128900
$only_dynamic_features and $only_dynamic_features == -1
!ll&&!rl&&r
9128900
MC/DC0%0/3
$only_dynamic_features and $only_dynamic_features == -1 and $self->dynamic_features->{$feature_index}
$only_dynamic_features $only_dynamic_features == -1 $self->dynamic_features->{$feature_index}
Truth table25%1/4
A and B and C
A= $only_dynamic_featuresB= $only_dynamic_features == -1C= $self->dynamic_features->{$feature_index}
ABCresult
0XX0
10X0
1100
1111
428 $only_dynamic_features
429 && $only_dynamic_features == -1
430 && $self->dynamic_features->{$feature_index}
431 )
432 {
433 0 next;
434 } else {
435 91289 my $feature_value =
436 $self->get_feature_value( $feature_index, $simple_feature_values );
437 91289 ▶ if ( $self->array_features->{$feature_index} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->array_features->{$feature_index}) { } 4531 86758 91289
438  
439 #it is an array feature, the returned value is an array reference
440 4531 foreach my $value ( @{$feature_value} ) {
441 22735 push @features, "$feature_index:$value";
442 }
443 } else {
444  
445 #it is not an array feature, the returned value is a string
446 86758 ▶ if ( $feature_value ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feature_value ne "") 85458 1300 86758
447 85458 push @features, "$feature_index:$feature_value";
448 }
449 }
450 }
451 }
452  
453 # save result in cache
454 4531 ▶ if ( $self->use_edge_features_cache ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->use_edge_features_cache) 0 4531 4531
455 0 $self->edge_features_cache->{$edge_signature} = \@features;
456 }
457  
458 4531 return \@features;
459 }
460  
461 # returns value of feature: simple feature values joined by '|'
462 # or '' if any of them is undefined or empty;
463 # for an array feature returns an array (ref) of these
464 # or an empty array (ref)
465 91289 ▶sub get_feature_value {
Subroutine get_feature_value: called CC=6 SCAR=18.0
Pod documented
466 91289 my ( $self, $feature_index, $simple_feature_values ) = @_;
467  
468 91289 my $simple_features_indexes =
469 $self->feature_simple_features_indexes->[$feature_index];
470  
471 91289 ▶ if ( $self->array_features->{$feature_index} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->array_features->{$feature_index}) { } 4531 86758 91289
472 4531 my $feature_value =
473 $self->get_array_feature_value(
474 $simple_features_indexes,
475 $simple_feature_values, 0
476 );
477 4531 ▶ if ($feature_value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feature_value) { } 4531 0 4531
478 4531 return $feature_value;
479 } else {
480 0 return [];
481 }
482 } else {
483 86758 my @values;
484 86758 foreach my $simple_feature_index ( @{$simple_features_indexes} ) {
485 240441 my $value = $simple_feature_values->[$simple_feature_index];
486 240441 ▶ if ( defined $value && $value ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value ne '') { } 239141 1300 240441
Condition66%2/3
defined $value and $value ne ""
!ll&&!rl&&r
01300239141
MC/DC50%1/2
defined $value and $value ne ""
defined $value $value ne ""
Truth table66%2/3
A and B
A= defined $valueB= $value ne ""
ABresult
0X0
100
111
487 239141 push @values, $value;
488 } else {
489 1300 return '';
490 }
491 }
492  
493 85458 my $feature_value = join '|', @values;
494 85458 return $feature_value;
495 }
496 }
497  
498 # for features containing subfeatures that return an array of values
499 13593 ▶sub get_array_feature_value {
Subroutine get_array_feature_value: called CC=5 SCAR=16.1
Pod documented
500 my (
501 13593 $self,
502 $simple_features_indexes,
503 $simple_feature_values,
504 $start_from
505 ) = @_;
506  
507 # get value at this position (position = $start_from)
508 13593 my $simple_feature_index = $simple_features_indexes->[$start_from];
509 13593 my $value = $simple_feature_values->[$simple_feature_index];
510 13593 ▶ if ( !$self->array_simple_features->{$simple_feature_index} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->array_simple_features->{$simple_feature_index}) 9062 4531 13593
511  
512 # if not an array reference
513 9062 $value = [ ($value) ]; # make it an array reference
514 }
515  
516 13593 my $simple_features_count = scalar @{$simple_features_indexes};
517 13593 ▶ if ( $start_from < $simple_features_count - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_from < $simple_features_count - 1) { } 9062 4531 13593
518  
519 # not the last simple feature => have to recurse
520 9062 my $append =
521 $self->get_array_feature_value(
522 $simple_features_indexes,
523 $simple_feature_values, $start_from + 1
524 );
525 9062 my @values;
526 9062 foreach my $my_value ( @{$value} ) {
527 27266 foreach my $append_value ( @{$append} ) {
528 45470 my $add_value = "$my_value|$append_value";
529 45470 push @values, $add_value;
530 }
531 }
532 9062 return [@values];
533 } else { # else bottom of recursion
534 4531 return $value;
535 }
536 }
537  
538 # SIMPLE FEATURES
539  
540 4531 ▶sub get_simple_feature_values_array {
Subroutine get_simple_feature_values_array: called CC=2 SCAR=6.9
Pod documented
541 4531 my ( $self, $edge ) = @_;
542  
543 4531 my @simple_feature_values;
544 4531 my $simple_feature_count = $self->simple_feature_count;
545 4531 ▶ for (
Branch: 1 branch
BranchTrueFalseTotal
if ($simple_feature_index < $simple_feature_count) 77696 4531 82227
546 my $simple_feature_index = 0;
547 $simple_feature_index < $simple_feature_count;
548 $simple_feature_index++
549 )
550 {
551 77696 my $sub = $self->simple_feature_subs->[$simple_feature_index];
552  
553 # If the simple feature has one parameter,
554 # then $arguments is the one argument;
555 # if the simple feature has more than one parameter,
556 # then $arguments is a reference to an array of arguments.
557 77696 my $arguments =
558 $self->simple_feature_sub_arguments->[$simple_feature_index];
559 77696 my $value = &$sub( $self, $edge, $arguments );
560 77696 push @simple_feature_values, $value;
561 }
562  
563 4531 return [@simple_feature_values];
564 }
565  
566 4 my %simple_feature_sub_references = (
567 'LABEL' => \&{feature_parent_label},
568 'prevlabel' => \&{feature_previous_label},
569 'l.label' => \&{feature_previous_label},
570 'G.label' => \&{feature_grandparent_label},
571 'g.label' => \&{feature_grandchildren_label},
572 'distance' => \&{feature_distance},
573 'G.distance' => \&{feature_grandparent_distance},
574 'attdir' => \&{feature_attachement_direction},
575 'G.attdir' => \&{feature_grandparent_attachement_direction}, # grandparent to child
576 'preceding' => \&{feature_preceding_child},
577 'PRECEDING' => \&{feature_preceding_parent},
578 '1.preceding' => \&{feature_preceding_first},
579 '2.preceding' => \&{feature_preceding_second},
580 'following' => \&{feature_following_child},
581 'FOLLOWING' => \&{feature_following_parent},
582 '1.following' => \&{feature_following_first},
583 '2.following' => \&{feature_following_second},
584 'between' => \&{feature_between},
585 'foreach' => \&{feature_foreach},
586 'equals' => \&{feature_equals},
587 'equalspc' => \&{feature_equals_pc},
588 'equalspcat' => \&{feature_equals_pc_at},
589 'arrayat' => \&{feature_array_at_child},
590 'ARRAYAT' => \&{feature_array_at_parent},
591 'arrayatcp' => \&{feature_array_at_cp},
592 'isfirst' => \&{feature_child_is_first_in_sentence},
593 'ISFIRST' => \&{feature_parent_is_first_in_sentence},
594 'islast' => \&{feature_child_is_last_in_sentence},
595 'ISLAST' => \&{feature_parent_is_last_in_sentence},
596 'isfirstchild' => \&{feature_child_is_first_child},
597 'islastchild' => \&{feature_child_is_last_child},
598 'islastleftchild' => \&{feature_child_is_last_left_child},
599 'isfirstrightchild' => \&{feature_child_is_first_right_child},
600 'childno' => \&{feature_number_of_childs_children},
601 'CHILDNO' => \&{feature_number_of_parents_children},
602 'substr' => \&{feature_substr_child},
603 'SUBSTR' => \&{feature_substr_parent},
604 'pmi' => \&{feature_pmi},
605 'pmibucketed' => \&{feature_pmi_bucketed},
606 'pmirounded' => \&{feature_pmi_rounded},
607 'pmid' => \&{feature_pmi_d},
608 'cprob' => \&{feature_cprob},
609 'cprobbucketed' => \&{feature_cprob_bucketed},
610 'cprobrounded' => \&{feature_cprob_rounded},
611  
612 # obsolete
613 # 'pmitworounded' => \&{feature_pmi_2_rounded},
614 # 'pmithreerounded' => \&{feature_pmi_3_rounded},
615 # 'cprobtworounded' => \&{feature_cprob_2_rounded},
616 # 'cprobthreerounded' => \&{feature_cprob_3_rounded},
617 );
618  
619 28 ▶sub get_simple_feature_sub_reference {
Subroutine get_simple_feature_sub_reference: called CC=2 SCAR=7.6
Pod documented
620 28 my ( $self, $simple_feature_function ) = @_;
621  
622 28 ▶ if ( $simple_feature_sub_references{$simple_feature_function} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($simple_feature_sub_references{$simple_feature_function}) { } 28 0 28
623 28 return $simple_feature_sub_references{$simple_feature_function};
624 } else {
625 0 croak "Unknown feature function '$simple_feature_function'!";
626 }
627 }
628  
629 # returns undef if there is no grandparent, i.e. the parent is the root
630 1040 ▶sub get_grandparent {
Subroutine get_grandparent: called CC=1 SCAR=0.0
Pod undocumented
631 1040 my ( $self, $edge ) = @_;
632  
633 1040 return ( $edge->parent )->parent;
634 }
635  
636 4531 ▶sub feature_distance {
Subroutine feature_distance: called CC=1 SCAR=0.0
Pod documented
637 4531 my ( $self, $edge ) = @_;
638  
639 4531 return $self->feature_distance_generic( $edge->parent, $edge->child );
640 }
641  
642 0 ▶sub feature_grandparent_distance {
Subroutine feature_grandparent_distance: not called CC=2 SCAR=17.9
Pod undocumented
643 0 my ( $self, $edge ) = @_;
644  
645 0 my $grandparent = $self->get_grandparent($edge);
646 0 ▶ if ( defined $grandparent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grandparent) { } 0 0 0
647 0 return $self->feature_distance_generic( $edge->parent, $edge->child );
648 } else {
649 0 return '#novalue#';
650 }
651 }
652  
653 4531 ▶sub feature_distance_generic {
Subroutine feature_distance_generic: called CC=3 SCAR=11.0
Pod undocumented
654 4531 my ( $self, $node1, $node2 ) = @_;
655  
656 4531 my $distance = $node1->ord - $node2->ord;
657  
658 4531 my $bucket = $self->config->distance2bucket->{$distance};
659 4531 ▶ if ( defined $bucket ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bucket) { } 3720 811 4531
660 3720 return $bucket;
661 } else {
662 811 ▶ if ( $distance <= $self->config->minBucket ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distance <= $self->config->minBucket) { } 464 347 811
663 464 return $self->config->minBucket;
664 } else { # $distance >= $self->maxBucket
665 347 return $self->config->maxBucket;
666 }
667 }
668 }
669  
670 0 ▶sub feature_attachement_direction {
Subroutine feature_attachement_direction: not called CC=1 SCAR=6.9
Pod undocumented
671 0 my ( $self, $edge ) = @_;
672  
673 0 return $self->feature_attachement_direction_generic(
674 $edge->parent, $edge->child
675 );
676 }
677  
678 0 ▶sub feature_grandparent_attachement_direction {
Subroutine feature_grandparent_attachement_direction: not called CC=2 SCAR=17.9
Pod undocumented
679 0 my ( $self, $edge ) = @_;
680  
681 0 my $grandparent = $self->get_grandparent($edge);
682 0 ▶ if ( defined $grandparent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grandparent) { } 0 0 0
683 0 return $self->feature_attachement_direction_generic(
684 $edge->parent, $edge->child
685 );
686 } else {
687 0 return '#novalue#';
688 }
689 }
690  
691 0 ▶sub feature_attachement_direction_generic {
Subroutine feature_attachement_direction_generic: not called CC=2 SCAR=17.9
Pod undocumented
692 0 my ( $self, $node1, $node2 ) = @_;
693  
694 0 ▶ if ( $node1->ord < $node2->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node1->ord < $node2->ord) { } 0 0 0
695 0 return -1;
696 } else {
697 0 return 1;
698 }
699 }
700  
701 9062 ▶sub feature_child {
Subroutine feature_child: called CC=1 SCAR=0.0
Pod documented
702 9062 my ( $self, $edge, $field_index ) = @_;
703 9062 return ( $edge->child->fields->[$field_index] );
704 }
705  
706 9062 ▶sub feature_parent {
Subroutine feature_parent: called CC=1 SCAR=0.0
Pod documented
707 9062 my ( $self, $edge, $field_index ) = @_;
708 9062 return ( $edge->parent->fields->[$field_index] );
709 }
710  
711 520 ▶sub feature_grandparent {
Subroutine feature_grandparent: called CC=2 SCAR=6.9
Pod undocumented
712 520 my ( $self, $edge, $field_index ) = @_;
713  
714 520 my $grandparent = $self->get_grandparent($edge);
715 520 ▶ if ( defined $grandparent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grandparent) { } 472 48 520
716 472 return ( $grandparent->fields->[$field_index] );
717 } else {
718 48 return '#novalue#';
719 }
720 }
721  
722 520 ▶sub feature_parent_label {
Subroutine feature_parent_label: called CC=1 SCAR=0.0
Pod undocumented
723 520 my ( $self, $edge ) = @_;
724 520 return ( $edge->parent->label );
725 }
726  
727 520 ▶sub feature_previous_label {
Subroutine feature_previous_label: called CC=2 SCAR=6.9
Pod undocumented
728 520 my ( $self, $edge ) = @_;
729  
730 520 my $left_sibling = $self->get_left_sibling($edge);
731 520 ▶ if ( defined $left_sibling ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $left_sibling) { } 230 290 520
732 230 return ( $left_sibling->child->label );
733 } else {
734 290 return $self->config->SEQUENCE_BOUNDARY_LABEL;
735 }
736 }
737  
738 520 ▶sub feature_grandparent_label {
Subroutine feature_grandparent_label: called CC=2 SCAR=6.9
Pod undocumented
739 520 my ( $self, $edge ) = @_;
740  
741 520 my $grandparent = $self->get_grandparent($edge);
742 520 ▶ if ( defined $grandparent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grandparent) { } 472 48 520
743 472 return ( $grandparent->label );
744 } else {
745 48 return '#novalue#';
746 }
747 }
748  
749 4531 ▶sub feature_first {
Subroutine feature_first: called CC=1 SCAR=0.0
Pod documented
750 4531 my ( $self, $edge, $field_index ) = @_;
751 4531 return ( $edge->first->fields->[$field_index] );
752 }
753  
754 4531 ▶sub feature_second {
Subroutine feature_second: called CC=1 SCAR=0.0
Pod documented
755 4531 my ( $self, $edge, $field_index ) = @_;
756 4531 return ( $edge->second->fields->[$field_index] );
757 }
758  
759 520 ▶sub feature_left_sibling {
Subroutine feature_left_sibling: called CC=2 SCAR=6.9
Pod undocumented
760 520 my ( $self, $edge, $field_index ) = @_;
761  
762 520 my $left_sibling = $self->get_left_sibling($edge);
763 520 ▶ if ( defined $left_sibling ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $left_sibling) { } 230 290 520
764 230 return ( $left_sibling->child->fields->[$field_index] );
765 } else {
766 290 return '#start#';
767 }
768 }
769  
770 0 ▶sub feature_right_sibling {
Subroutine feature_right_sibling: not called CC=2 SCAR=17.9
Pod undocumented
771 0 my ( $self, $edge, $field_index ) = @_;
772  
773 0 my $right_sibling = $self->get_right_sibling($edge);
774 0 ▶ if ( defined $right_sibling ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $right_sibling) { } 0 0 0
775 0 return ( $right_sibling->child->fields->[$field_index] );
776 } else {
777 0 return '#end#';
778 }
779 }
780  
781 1040 ▶sub get_left_sibling {
Subroutine get_left_sibling: called CC=3 SCAR=11.0
Pod undocumented
782 1040 my ( $self, $edge ) = @_;
783  
784 1040 my $siblings = $edge->parent->children;
785 1040 my $is_first = ( $siblings->[0]->child->ord == $edge->child->ord );
786 1040 ▶ if ($is_first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_first) { } 580 460 1040
787  
788 # there is no left sibling to the leftmost node
789 580 return;
790 } else {
791  
792 # find my position among parent's children (is at least 1)
793 460 my $my_index = 1;
794 460 ▶ while ( $siblings->[$my_index]->child->ord != $edge->child->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($siblings->[$my_index]->child->ord != $edge->child->ord) 364 460 824
795 364 $my_index++;
796 }
797  
798 # now ($my_index-1) is the index of my (closest) left sibling
799 460 return ( $siblings->[ $my_index - 1 ] );
800 }
801 }
802  
803 0 ▶sub get_right_sibling {
Subroutine get_right_sibling: not called CC=3 SCAR=24.8
Pod undocumented
804 0 my ( $self, $edge ) = @_;
805  
806 0 my $siblings = $edge->parent->children;
807 0 my $last_sibling_index = scalar(@$siblings) - 1;
808 0 my $is_last = (
809 $siblings->[$last_sibling_index]->child->ord
810 == $edge->child->ord
811 );
812 0 ▶ if ($is_last) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_last) { } 0 0 0
813  
814 # there is no right sibling to the rightmost node
815 0 return;
816 } else {
817  
818 # find my position among parent's children
819 # (is at most $last_sibling_index - 1)
820 0 my $my_index = $last_sibling_index - 1;
821 0 ▶ while ( $siblings->[$my_index]->child->ord != $edge->child->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($siblings->[$my_index]->child->ord != $edge->child->ord) 0 0 0
822 0 $my_index--;
823 }
824  
825 # now ($my_index+1) is the index of my (closest) right sibling
826 0 return $siblings->[ $my_index + 1 ];
827 }
828 }
829  
830 4531 ▶sub feature_preceding_child {
Subroutine feature_preceding_child: called CC=3 SCAR=11.2
Pod documented
831 4531 my ( $self, $edge, $field_index ) = @_;
832  
833 4531 my $node = $edge->sentence->getNodeByOrd( $edge->child->ord - 1 );
834  
835 # $node may be undef
836 4531 ▶ if ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) { } 4531 0 4531
837 4531 ▶ if ( $edge->parent->ord == $node->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edge->parent->ord == $node->ord) { } 401 4130 4531
838  
839 # no gap between nodes
840 401 return '#mid#';
841 } else {
842 4130 return $node->fields->[$field_index];
843 }
844 } else {
845 0 return '#start#';
846 }
847 }
848  
849 4531 ▶sub feature_preceding_parent {
Subroutine feature_preceding_parent: called CC=3 SCAR=11.0
Pod documented
850 4531 my ( $self, $edge, $field_index ) = @_;
851  
852 4531 my $node = $edge->sentence->getNodeByOrd( $edge->parent->ord - 1 );
853  
854 # $node may be undef
855 4531 ▶ if ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) { } 4206 325 4531
856 4206 ▶ if ( $edge->child->ord == $node->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edge->child->ord == $node->ord) { } 440 3766 4206
857  
858 # no gap between nodes
859 440 return '#mid#';
860 } else {
861 3766 return $node->fields->[$field_index];
862 }
863 } else {
864 325 return '#start#';
865 }
866 }
867  
868 4531 ▶sub feature_following_child {
Subroutine feature_following_child: called CC=3 SCAR=11.0
Pod documented
869 4531 my ( $self, $edge, $field_index ) = @_;
870  
871 4531 my $node = $edge->sentence->getNodeByOrd( $edge->child->ord + 1 );
872  
873 # $node may be undef
874 4531 ▶ if ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) { } 4255 276 4531
875 4255 ▶ if ( $edge->parent->ord == $node->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edge->parent->ord == $node->ord) { } 440 3815 4255
876  
877 # no gap between nodes
878 440 return '#mid#';
879 } else {
880 3815 return $node->fields->[$field_index];
881 }
882 } else {
883 276 return '#end#';
884 }
885 }
886  
887 4531 ▶sub feature_following_parent {
Subroutine feature_following_parent: called CC=3 SCAR=11.0
Pod documented
888 4531 my ( $self, $edge, $field_index ) = @_;
889  
890 4531 my $node = $edge->sentence->getNodeByOrd( $edge->parent->ord + 1 );
891  
892 # $node may be undef
893 4531 ▶ if ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) { } 4311 220 4531
894 4311 ▶ if ( $edge->child->ord == $node->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edge->child->ord == $node->ord) { } 401 3910 4311
895  
896 # no gap between nodes
897 401 return '#mid#';
898 } else {
899 3910 return $node->fields->[$field_index];
900 }
901 } else {
902 220 return '#end#';
903 }
904 }
905  
906 0 ▶sub feature_preceding_first {
Subroutine feature_preceding_first: not called CC=2 SCAR=17.9
Pod documented
907 0 my ( $self, $edge, $field_index ) = @_;
908  
909 0 my $node = $edge->sentence->getNodeByOrd( $edge->first->ord - 1 );
910  
911 # $node may be undef
912 0 ▶ if ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) { } 0 0 0
913 0 return $node->fields->[$field_index];
914 } else {
915 0 return '#start#';
916 }
917 }
918  
919 0 ▶sub feature_preceding_second {
Subroutine feature_preceding_second: not called CC=3 SCAR=24.8
Pod documented
920 0 my ( $self, $edge, $field_index ) = @_;
921  
922 0 my $node = $edge->sentence->getNodeByOrd( $edge->second->ord - 1 );
923  
924 # $node may be undef
925 0 ▶ if ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) { } 0 0 0
926 0 ▶ if ( $edge->first->ord == $node->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edge->first->ord == $node->ord) { } 0 0 0
927  
928 # node preceding second node is first node
929 0 return '#mid#';
930 } else {
931 0 return $node->fields->[$field_index];
932 }
933 } else {
934 0 return '#start#';
935 }
936 }
937  
938 0 ▶sub feature_following_first {
Subroutine feature_following_first: not called CC=3 SCAR=24.8
Pod documented
939 0 my ( $self, $edge, $field_index ) = @_;
940  
941 0 my $node = $edge->sentence->getNodeByOrd( $edge->first->ord + 1 );
942  
943 # $node may be undef
944 0 ▶ if ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) { } 0 0 0
945 0 ▶ if ( $edge->second->ord == $node->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edge->second->ord == $node->ord) { } 0 0 0
946  
947 # node following first node is second node
948 0 return '#mid#';
949 } else {
950 0 return $node->fields->[$field_index];
951 }
952 } else {
953 0 return '#end#';
954 }
955 }
956  
957 0 ▶sub feature_following_second {
Subroutine feature_following_second: not called CC=2 SCAR=17.9
Pod documented
958 0 my ( $self, $edge, $field_index ) = @_;
959  
960 0 my $node = $edge->sentence->getNodeByOrd( $edge->second->ord + 1 );
961  
962 # $node may be undef
963 0 ▶ if ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) { } 0 0 0
964 0 return $node->fields->[$field_index];
965 } else {
966 0 return '#end#';
967 }
968 }
969  
970 4531 ▶sub feature_between {
Subroutine feature_between: called CC=3 SCAR=11.0
Pod documented
971 4531 my ( $self, $edge, $field_index ) = @_;
972  
973 4531 my @values;
974 my $from;
975 4531 my $to;
976 4531 ▶ if ( $edge->parent->ord < $edge->child->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edge->parent->ord < $edge->child->ord) { } 2500 2031 4531
977 2500 $from = $edge->parent->ord + 1;
978 2500 $to = $edge->child->ord - 1;
979 } else {
980 2031 $from = $edge->child->ord + 1;
981 2031 $to = $edge->parent->ord - 1;
982 }
983  
984 # TODO: use precomputed values instead
985  
986 4531 ▶ for ( my $ord = $from; $ord <= $to; $ord++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ord <= $to) 22735 4531 27266
987 22735 push @values,
988 $edge->sentence->getNodeByOrd($ord)->fields->[$field_index];
989 }
990 4531 return [@values];
991  
992 # my $len = $to - $from;
993 # if ($len >= 0) {
994 # return $edge->sentence->betweenFeatureValues->
995 # {$field_index}->[$from]->[$len];
996 # } else {
997 # return;
998 # }
999  
1000 }
1001  
1002 0 ▶sub feature_foreach {
Subroutine feature_foreach: not called CC=2 SCAR=17.9
Pod documented
1003 0 my ( $self, $edge, $field_index ) = @_;
1004  
1005 0 my $values = $edge->child->fields->[$field_index];
1006 0 ▶ if ($values) {
Branch: 1 branch
BranchTrueFalseTotal
if ($values) { } 0 0 0
1007 0 my @values = split / /, $edge->child->fields->[$field_index];
1008 0 return [@values];
1009 } else {
1010 0 return '';
1011 }
1012 }
1013  
1014 0 ▶sub feature_equals {
Subroutine feature_equals: not called CC=9 SCAR=45.0
Pod documented
1015 0 my ( $self, $edge, $field_indexes ) = @_;
1016  
1017 # equals takes two arguments
1018 0 ▶ if ( @{$field_indexes} == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$field_indexes;} == 2) { } 0 0 0
1019 0 my ( $field_index_1, $field_index_2 ) = @{$field_indexes};
1020 0 my $values_1 = $edge->child->fields->[$field_index_1];
1021 0 my $values_2 = $edge->child->fields->[$field_index_2];
1022  
1023 # we handle undefines and empties specially
1024 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $values_1 and $values_1 ne '' and defined $values_2 and $values_2 ne '') { } 0 0 0
Condition0%0/9
defined $values_1 and $values_1 ne "" and defined $values_2 and $values_2 ne ""
!ll&&!rl&&r
000
defined $values_1 and $values_1 ne "" and defined $values_2
!ll&&!rl&&r
000
defined $values_1 and $values_1 ne ""
!ll&&!rl&&r
000
MC/DC0%0/4
defined $values_1 and $values_1 ne "" and defined $values_2 and $values_2 ne ""
defined $values_1 $values_1 ne "" defined $values_2 $values_2 ne ""
Truth table0%0/5
A and B and C and D
A= defined $values_1B= $values_1 ne ""C= defined $values_2D= $values_2 ne ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1025 defined $values_1
1026 && $values_1 ne ''
1027 && defined $values_2
1028 && $values_2 ne ''
1029 )
1030 {
1031 0 my $result = 0; # default not equal
1032 0 my @values_1 = split / /, $values_1;
1033 0 my @values_2 = split / /, $values_2;
1034  
1035 # try to find a match
1036 0 foreach my $value_1 (@values_1) {
1037 0 foreach my $value_2 (@values_2) {
1038 0 ▶ if ( $value_1 eq $value_2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value_1 eq $value_2) 0 0 0
1039 0 $result = 1; # one match is enough
1040 }
1041 }
1042 }
1043 0 return $result;
1044 } else {
1045 0 return -1; # undef
1046 }
1047 } else {
1048 0 croak "equals() takes TWO arguments!!!";
1049 }
1050 }
1051  
1052 # only difference to equals is the line:
1053 # my $values_1 = $edge->PARENT->fields->[$field_index_1];
1054 0 ▶sub feature_equals_pc {
Subroutine feature_equals_pc: not called CC=9 SCAR=45.0
Pod documented
1055 0 my ( $self, $edge, $field_indexes ) = @_;
1056  
1057 # equals takes two arguments
1058 0 ▶ if ( @{$field_indexes} == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$field_indexes;} == 2) { } 0 0 0
1059 0 my ( $field_index_1, $field_index_2 ) = @{$field_indexes};
1060 0 my $values_1 = $edge->parent->fields->[$field_index_1];
1061 0 my $values_2 = $edge->child->fields->[$field_index_2];
1062  
1063 # we handle undefines and empties specially
1064 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $values_1 and $values_1 ne '' and defined $values_2 and $values_2 ne '') { } 0 0 0
Condition0%0/9
defined $values_1 and $values_1 ne "" and defined $values_2 and $values_2 ne ""
!ll&&!rl&&r
000
defined $values_1 and $values_1 ne "" and defined $values_2
!ll&&!rl&&r
000
defined $values_1 and $values_1 ne ""
!ll&&!rl&&r
000
MC/DC0%0/4
defined $values_1 and $values_1 ne "" and defined $values_2 and $values_2 ne ""
defined $values_1 $values_1 ne "" defined $values_2 $values_2 ne ""
Truth table0%0/5
A and B and C and D
A= defined $values_1B= $values_1 ne ""C= defined $values_2D= $values_2 ne ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1065 defined $values_1
1066 && $values_1 ne ''
1067 && defined $values_2
1068 && $values_2 ne ''
1069 )
1070 {
1071 0 my $result = 0; # default not equal
1072 0 my @values_1 = split / /, $values_1;
1073 0 my @values_2 = split / /, $values_2;
1074  
1075 # try to find a match
1076 0 foreach my $value_1 (@values_1) {
1077 0 foreach my $value_2 (@values_2) {
1078 0 ▶ if ( $value_1 eq $value_2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value_1 eq $value_2) 0 0 0
1079 0 $result = 1; # one match is enough
1080 }
1081 }
1082 }
1083 0 return $result;
1084 } else {
1085 0 return -1; # undef
1086 }
1087 } else {
1088 0 croak "equals() takes TWO arguments!!!";
1089 }
1090 }
1091  
1092 # sub equalsat - does not make sense
1093  
1094 # whether the character at the given position of the given field
1095 # equals in parent and in child
1096 4531 ▶sub feature_equals_pc_at {
Subroutine feature_equals_pc_at: called CC=7 SCAR=19.6
Pod documented
1097 4531 my ( $self, $edge, $arguments ) = @_;
1098  
1099 # equals takes two arguments
1100 4531 ▶ if ( @{$arguments} == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$arguments;} == 2) { } 4531 0 4531
1101 4531 my ( $field_index, $position ) = @{$arguments};
1102 4531 my $field_parent = $edge->parent->fields->[$field_index];
1103 4531 my $field_child = $edge->child->fields->[$field_index];
1104  
1105 # we handle undefines and too short fields specially
1106 4531 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $field_parent and length $field_parent > $position and defined $field_child and length $field_child > $position) { } 520 4011 4531
Condition77%7/9
defined $field_parent and length $field_parent > $position and defined $field_child and length $field_child > $position
!ll&&!rl&&r
3734277520
defined $field_parent and length $field_parent > $position and defined $field_child
!ll&&!rl&&r
37340797
defined $field_parent and length $field_parent > $position
!ll&&!rl&&r
03734797
MC/DC50%2/4
defined $field_parent and length $field_parent > $position and defined $field_child and length $field_child > $position
defined $field_parent length $field_parent > $position defined $field_child length $field_child > $position
Truth table60%3/5
A and B and C and D
A= defined $field_parentB= length $field_parent > $positionC= defined $field_childD= length $field_child > $position
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1107 defined $field_parent
1108 && length $field_parent > $position
1109 && defined $field_child
1110 && length $field_child > $position
1111 )
1112 {
1113 520 my $value_parent = substr $field_parent, $position, 1;
1114 520 my $value_child = substr $field_child, $position, 1;
1115 520 ▶ if ( $value_parent eq $value_child ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value_parent eq $value_child) { } 71 449 520
1116 71 return 1;
1117 } else {
1118 449 return 0;
1119 }
1120 } else {
1121 4011 return -1; # undef
1122 }
1123 } else {
1124 0 croak "equals() takes TWO arguments!!!";
1125 }
1126 }
1127  
1128 # substring (field, start, length)
1129 12033 ▶sub feature_substr_child {
Subroutine feature_substr_child: called CC=5 SCAR=16.4
Pod undocumented
1130 12033 my ( $self, $edge, $arguments ) = @_;
1131  
1132 # substr takes two or three arguments
1133 12033 ▶ if ( @{$arguments} != 3 && @{$arguments} != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$arguments;} != 3 and @{$arguments;} != 2) { } 0 12033 12033
Condition66%2/3
@{$arguments;} != 3 and @{$arguments;} != 2
!ll&&!rl&&r
802240110
MC/DC0%0/2
@{$arguments;} != 3 and @{$arguments;} != 2
@{$arguments;} != 3 @{$arguments;} != 2
Truth table66%2/3
A and B
A= @{$arguments;} != 3B= @{$arguments;} != 2
ABresult
0X0
100
111
1134 0 croak "substr() takes THREE or TWO arguments!!!";
1135 } else {
1136 12033 my ( $field_index, $start, $length ) = @{$arguments};
1137 12033 my $field = $edge->child->fields->[$field_index];
1138  
1139 12033 my $value = '';
1140 12033 ▶ if ( defined $field ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $field) 12033 0 12033
1141 12033 ▶ if ( defined $length ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length) { } 8022 4011 12033
1142 8022 $value = substr( $field, $start, $length );
1143 } else {
1144 4011 $value = substr( $field, $start );
1145 }
1146 }
1147  
1148 12033 return $value;
1149 }
1150 }
1151  
1152 # substring (field, start, length)
1153 0 ▶sub feature_substr_parent {
Subroutine feature_substr_parent: not called CC=5 SCAR=34.0
Pod undocumented
1154 0 my ( $self, $edge, $arguments ) = @_;
1155  
1156 # substr takes two or three arguments
1157 0 ▶ if ( @{$arguments} != 3 && @{$arguments} != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$arguments;} != 3 and @{$arguments;} != 2) { } 0 0 0
Condition0%0/3
@{$arguments;} != 3 and @{$arguments;} != 2
!ll&&!rl&&r
000
MC/DC0%0/2
@{$arguments;} != 3 and @{$arguments;} != 2
@{$arguments;} != 3 @{$arguments;} != 2
Truth table0%0/3
A and B
A= @{$arguments;} != 3B= @{$arguments;} != 2
ABresult
0X0
100
111
1158 0 croak "substr() takes THREE or TWO arguments!!!";
1159 } else {
1160 0 my ( $field_index, $start, $length ) = @{$arguments};
1161 0 my $field = $edge->parent->fields->[$field_index];
1162  
1163 0 my $value = '';
1164 0 ▶ if ( defined $field ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $field) 0 0 0
1165 0 ▶ if ( defined $length ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length) { } 0 0 0
1166 0 $value = substr( $field, $start, $length );
1167 } else {
1168 0 $value = substr( $field, $start );
1169 }
1170 }
1171  
1172 0 return $value;
1173 }
1174 }
1175  
1176 # arrayat (array, index)
1177 0 ▶sub feature_array_at_child {
Subroutine feature_array_at_child: not called CC=3 SCAR=24.8
Pod undocumented
1178 0 my ( $self, $edge, $arguments ) = @_;
1179  
1180 # arrayat takes two arguments
1181 0 ▶ if ( @{$arguments} != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$arguments;} != 2) { } 0 0 0
1182 0 croak "arrayat() takes TWO arguments!!!";
1183 } else {
1184 0 my ( $array_field, $index_field ) = @{$arguments};
1185 0 my $array = $edge->child->fields->[$array_field];
1186 0 my $index = $edge->child->fields->[$index_field];
1187  
1188 0 my @array = split / /, $array;
1189 0 my $value = $array[$index];
1190 0 ▶ if ( !defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 0 0
1191 0 $value = '';
1192 }
1193  
1194 0 return $value;
1195 }
1196 }
1197  
1198 0 ▶sub feature_array_at_parent {
Subroutine feature_array_at_parent: not called CC=3 SCAR=24.8
Pod undocumented
1199 0 my ( $self, $edge, $arguments ) = @_;
1200  
1201 # arrayat takes two arguments
1202 0 ▶ if ( @{$arguments} != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$arguments;} != 2) { } 0 0 0
1203 0 croak "arrayat() takes TWO arguments!!!";
1204 } else {
1205 0 my ( $array_field, $index_field ) = @{$arguments};
1206 0 my $array = $edge->parent->fields->[$array_field];
1207 0 my $index = $edge->parent->fields->[$index_field];
1208  
1209 0 my @array = split / /, $array;
1210 0 my $value = $array[$index];
1211 0 ▶ if ( !defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 0 0
1212 0 $value = '';
1213 }
1214  
1215 0 return $value;
1216 }
1217 }
1218  
1219 # arrayatcp (array, index)
1220 0 ▶sub feature_array_at_cp {
Subroutine feature_array_at_cp: not called CC=3 SCAR=24.8
Pod undocumented
1221 0 my ( $self, $edge, $arguments ) = @_;
1222  
1223 # arrayat takes two arguments
1224 0 ▶ if ( @{$arguments} != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$arguments;} != 2) { } 0 0 0
1225 0 croak "arrayat() takes TWO arguments!!!";
1226 } else {
1227 0 my ( $array_field, $index_field ) = @{$arguments};
1228 0 my $array = $edge->child->fields->[$array_field];
1229 0 my $index = $edge->parent->fields->[$index_field];
1230  
1231 0 my @array = split / /, $array;
1232 0 my $value = $array[$index];
1233 0 ▶ if ( !defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 0 0
1234 0 $value = '';
1235 }
1236  
1237 0 return $value;
1238 }
1239 }
1240  
1241 520 ▶sub feature_child_is_first_in_sentence {
Subroutine feature_child_is_first_in_sentence: called CC=2 SCAR=6.9
Pod undocumented
1242 520 my ( $self, $edge ) = @_;
1243  
1244 520 ▶ if ( $edge->child->ord == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edge->child->ord == 1) { } 38 482 520
1245 38 return 1;
1246 } else {
1247 482 return 0;
1248 }
1249 }
1250  
1251 0 ▶sub feature_parent_is_first_in_sentence {
Subroutine feature_parent_is_first_in_sentence: not called CC=2 SCAR=17.9
Pod undocumented
1252 0 my ( $self, $edge ) = @_;
1253  
1254 0 ▶ if ( $edge->parent->ord == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edge->parent->ord == 1) { } 0 0 0
1255 0 return 1;
1256 } else {
1257 0 return 0;
1258 }
1259 }
1260  
1261 520 ▶sub feature_child_is_last_in_sentence {
Subroutine feature_child_is_last_in_sentence: called CC=2 SCAR=6.9
Pod undocumented
1262 520 my ( $self, $edge ) = @_;
1263  
1264 # last ord = number of nodes (because ords are 1-based, 0 is the root node)
1265 520 ▶ if ( $edge->child->ord == scalar( @{ $edge->sentence->nodes } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edge->child->ord == scalar @{$edge->sentence->nodes;}) { } 24 496 520
1266 24 return 1;
1267 } else {
1268 496 return 0;
1269 }
1270 }
1271  
1272 0 ▶sub feature_parent_is_last_in_sentence {
Subroutine feature_parent_is_last_in_sentence: not called CC=2 SCAR=17.9
Pod undocumented
1273 0 my ( $self, $edge ) = @_;
1274  
1275 # last ord = number of nodes (because ords are 1-based, 0 is the root node)
1276 0 ▶ if ( $edge->parent->ord == scalar( @{ $edge->sentence->nodes } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edge->parent->ord == scalar @{$edge->sentence->nodes;}) { } 0 0 0
1277 0 return 1;
1278 } else {
1279 0 return 0;
1280 }
1281 }
1282  
1283 520 ▶sub feature_child_is_first_child {
Subroutine feature_child_is_first_child: called CC=2 SCAR=6.9
Pod undocumented
1284 520 my ( $self, $edge ) = @_;
1285  
1286 520 my $children = $edge->parent->children;
1287 520 ▶ if ( $children->[0]->child->ord == $edge->child->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($children->[0]->child->ord == $edge->child->ord) { } 290 230 520
1288 290 return 1;
1289 } else {
1290 230 return 0;
1291 }
1292 }
1293  
1294 520 ▶sub feature_child_is_last_child {
Subroutine feature_child_is_last_child: called CC=2 SCAR=6.9
Pod undocumented
1295 520 my ( $self, $edge ) = @_;
1296  
1297 520 my $children = $edge->parent->children;
1298 520 my $childrenNum = scalar(@$children);
1299 520 ▶ if ( $children->[ $childrenNum - 1 ]->child->ord == $edge->child->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$children[$childrenNum - 1]->child->ord == $edge->child->ord) { } 290 230 520
1300 290 return 1;
1301 } else {
1302 230 return 0;
1303 }
1304 }
1305  
1306 520 ▶sub feature_child_is_first_right_child {
Subroutine feature_child_is_first_right_child: called CC=5 SCAR=16.1
Pod undocumented
1307 520 my ( $self, $edge ) = @_;
1308  
1309 520 my $is_right = ( $edge->parent->ord < $edge->child->ord );
1310 520 ▶ if ($is_right) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_right) { } 339 181 520
1311 339 my $siblings = $edge->parent->children;
1312 339 my $is_first = ( $siblings->[0]->child->ord == $edge->child->ord );
1313 339 ▶ if ($is_first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_first) { } 127 212 339
1314  
1315 # is right & is first (= leftmost) of all siblings
1316 127 return 1;
1317 } else {
1318  
1319 # find my position among parent's children (is at least 1)
1320 212 my $my_index = 1;
1321 212 ▶ while ( $siblings->[$my_index]->child->ord != $edge->child->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($siblings->[$my_index]->child->ord != $edge->child->ord) 182 212 394
1322 182 $my_index++;
1323 }
1324  
1325 # now ($my_index-1) is the index of my (closest) left sibling
1326 212 my $sibling_is_left =
1327 (
1328 $siblings->[ $my_index - 1 ]->child->ord
1329 < $edge->parent->ord
1330 );
1331 212 ▶ if ($sibling_is_left) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sibling_is_left) { } 84 128 212
1332  
1333 # is right and closest left sibling is left
1334 84 return 1;
1335 } else {
1336  
1337 # is right but not the first one
1338 128 return 0;
1339 }
1340 }
1341 } else {
1342  
1343 # is left
1344 181 return 0;
1345 }
1346 }
1347  
1348 520 ▶sub feature_child_is_last_left_child {
Subroutine feature_child_is_last_left_child: called CC=5 SCAR=16.1
Pod undocumented
1349 520 my ( $self, $edge ) = @_;
1350  
1351 520 my $is_left = ( $edge->child->ord < $edge->parent->ord );
1352 520 ▶ if ($is_left) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_left) { } 181 339 520
1353 181 my $siblings = $edge->parent->children;
1354 181 my $last_sibling_index = scalar(@$siblings) - 1;
1355 181 my $is_last = (
1356 $siblings->[$last_sibling_index]->child->ord
1357 == $edge->child->ord
1358 );
1359 181 ▶ if ($is_last) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_last) { } 79 102 181
1360  
1361 # is left & is last of all siblings
1362 79 return 1;
1363 } else {
1364  
1365 # find my position among parent's children
1366 # (is at most $last_sibling_index - 1)
1367 102 my $my_index = $last_sibling_index - 1;
1368 102 ▶ while ( $siblings->[$my_index]->child->ord != $edge->child->ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($siblings->[$my_index]->child->ord != $edge->child->ord) 108 102 210
1369 108 $my_index--;
1370 }
1371  
1372 # now ($my_index+1) is the index of my (closest) right sibling
1373 102 my $sibling_is_right =
1374 (
1375 $edge->parent->ord
1376 < $siblings->[ $my_index + 1 ]->child->ord
1377 );
1378 102 ▶ if ($sibling_is_right) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sibling_is_right) { } 84 18 102
1379  
1380 # is left and closest right sibling is right
1381 84 return 1;
1382 } else {
1383  
1384 # is left but not the last one
1385 18 return 0;
1386 }
1387 }
1388 } else {
1389  
1390 # is right
1391 339 return 0;
1392 }
1393 }
1394  
1395 520 ▶sub feature_number_of_childs_children {
Subroutine feature_number_of_childs_children: called CC=3 SCAR=11.0
Pod undocumented
1396 520 my ( $self, $edge ) = @_;
1397  
1398 520 my $children = $edge->child->children;
1399 520 ▶ if ( $children && scalar(@$children) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($children and scalar @$children) { } 249 271 520
Condition50%1/2
$children and scalar @$children
!ll
0520
MC/DC0%0/1
$children and scalar @$children
$children
Truth table50%1/2
A
A= $children
Aresult
00
11
1400 249 return scalar(@$children);
1401 } else {
1402 271 return 0;
1403 }
1404 }
1405  
1406 520 ▶sub feature_number_of_parents_children {
Subroutine feature_number_of_parents_children: called CC=3 SCAR=12.0
Pod undocumented
1407 520 my ( $self, $edge ) = @_;
1408  
1409 520 my $children = $edge->parent->children;
1410 520 ▶ if ( $children && scalar(@$children) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($children and scalar @$children) { } 520 0 520
Condition50%1/2
$children and scalar @$children
!ll
0520
MC/DC0%0/1
$children and scalar @$children
$children
Truth table50%1/2
A
A= $children
Aresult
00
11
1411 520 return scalar(@$children);
1412 } else {
1413 0 return 0;
1414 }
1415 }
1416  
1417 0 ▶sub feature_additional_model {
Subroutine feature_additional_model: not called CC=3 SCAR=24.8
Pod undocumented
1418 0 my ( $self, $edge, $field_index, $model ) = @_;
1419  
1420 0 my $child = $edge->child->fields->[$field_index];
1421 0 my $parent = $edge->parent->fields->[$field_index];
1422  
1423 0 ▶ if ( defined $child && defined $parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $child and defined $parent) { } 0 0 0
Condition0%0/3
defined $child and defined $parent
!ll&&!rl&&r
000
MC/DC0%0/2
defined $child and defined $parent
defined $child defined $parent
Truth table0%0/3
A and B
A= defined $childB= defined $parent
ABresult
0X0
100
111
1424 0 return $model->get_value( $child, $parent );
1425 } else {
1426 0 croak "Either child or parent is undefined in additional model feature, " .
1427 "this should not happen!";
1428 }
1429 }
1430  
1431 0 ▶sub feature_additional_model_bucketed {
Subroutine feature_additional_model_bucketed: not called CC=3 SCAR=24.8
Pod undocumented
1432 0 my ( $self, $edge, $field_index, $model ) = @_;
1433  
1434 0 my $child = $edge->child->fields->[$field_index];
1435 0 my $parent = $edge->parent->fields->[$field_index];
1436  
1437 0 ▶ if ( defined $child && defined $parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $child and defined $parent) { } 0 0 0
Condition0%0/3
defined $child and defined $parent
!ll&&!rl&&r
000
MC/DC0%0/2
defined $child and defined $parent
defined $child defined $parent
Truth table0%0/3
A and B
A= defined $childB= defined $parent
ABresult
0X0
100
111
1438 0 return $model->get_bucketed_value( $child, $parent );
1439 } else {
1440 0 croak "Either child or parent is undefined in additional model feature, " .
1441 "this should not happen!";
1442 }
1443 }
1444  
1445 0 ▶sub feature_additional_model_rounded {
Subroutine feature_additional_model_rounded: not called CC=3 SCAR=24.8
Pod undocumented
1446 0 my ( $self, $edge, $parameters, $model ) = @_;
1447  
1448 0 my ( $field_index, $rounding ) = @$parameters;
1449 0 my $child = $edge->child->fields->[$field_index];
1450 0 my $parent = $edge->parent->fields->[$field_index];
1451  
1452 0 ▶ if ( defined $child && defined $parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $child and defined $parent) { } 0 0 0
Condition0%0/3
defined $child and defined $parent
!ll&&!rl&&r
000
MC/DC0%0/2
defined $child and defined $parent
defined $child defined $parent
Truth table0%0/3
A and B
A= defined $childB= defined $parent
ABresult
0X0
100
111
1453 0 return $model->get_rounded_value( $child, $parent, $rounding );
1454 } else {
1455 0 croak "Either child or parent is undefined in additional model feature, " .
1456 "this should not happen!";
1457 }
1458 }
1459  
1460 0 ▶sub feature_additional_model_d {
Subroutine feature_additional_model_d: not called CC=3 SCAR=24.8
Pod undocumented
1461 0 my ( $self, $edge, $parameters, $model ) = @_;
1462  
1463 0 my ( $field_index_c, $field_index_p ) = @$parameters;
1464 0 my $child = $edge->child->fields->[$field_index_c];
1465 0 my $parent = $edge->parent->fields->[$field_index_p];
1466  
1467 0 ▶ if ( defined $child && defined $parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $child and defined $parent) { } 0 0 0
Condition0%0/3
defined $child and defined $parent
!ll&&!rl&&r
000
MC/DC0%0/2
defined $child and defined $parent
defined $child defined $parent
Truth table0%0/3
A and B
A= defined $childB= defined $parent
ABresult
0X0
100
111
1468 0 return $model->get_rounded_value( $child, $parent );
1469 } else {
1470 0 croak "Either child or parent is undefined in additional model feature, " .
1471 "this should not happen!";
1472 }
1473 }
1474  
1475 0 ▶sub feature_pmi {
Subroutine feature_pmi: not called CC=1 SCAR=6.9
Pod undocumented
1476 0 my ( $self, $edge, $field_index ) = @_;
1477  
1478 0 return $self->feature_additional_model( $edge, $field_index, $self->pmi_model );
1479 }
1480  
1481 0 ▶sub feature_pmi_bucketed {
Subroutine feature_pmi_bucketed: not called CC=1 SCAR=6.9
Pod undocumented
1482 0 my ( $self, $edge, $field_index ) = @_;
1483  
1484 0 return $self->feature_additional_model_bucketed( $edge, $field_index, $self->pmi_model );
1485 }
1486  
1487 0 ▶sub feature_pmi_rounded {
Subroutine feature_pmi_rounded: not called CC=1 SCAR=6.9
Pod undocumented
1488 0 my ( $self, $edge, $parameters ) = @_;
1489  
1490 0 return $self->feature_additional_model_rounded( $edge, $parameters, $self->pmi_model );
1491 }
1492  
1493 0 ▶sub feature_pmi_d {
Subroutine feature_pmi_d: not called CC=1 SCAR=6.9
Pod undocumented
1494 0 my ( $self, $edge, $parameters ) = @_;
1495  
1496 0 return $self->feature_additional_model_d( $edge, $parameters, $self->pmi_model );
1497 }
1498  
1499 0 ▶sub feature_pmi_2_rounded {
Subroutine feature_pmi_2_rounded: not called CC=1 SCAR=6.9
Pod undocumented
1500 0 my ( $self, $edge, $field_index ) = @_;
1501  
1502 0 my @params = ( $field_index, 1 );
1503 0 return $self->feature_pmi_rounded( $edge, \@params );
1504 }
1505  
1506 0 ▶sub feature_pmi_3_rounded {
Subroutine feature_pmi_3_rounded: not called CC=1 SCAR=6.9
Pod undocumented
1507 0 my ( $self, $edge, $field_index ) = @_;
1508  
1509 0 my @params = ( $field_index, 2 );
1510 0 return $self->feature_pmi_rounded( $edge, \@params );
1511 }
1512  
1513 0 ▶sub feature_cprob {
Subroutine feature_cprob: not called CC=1 SCAR=6.9
Pod undocumented
1514 0 my ( $self, $edge, $field_index ) = @_;
1515  
1516 0 return $self->feature_additional_model( $edge, $field_index, $self->cprob_model );
1517 }
1518  
1519 0 ▶sub feature_cprob_bucketed {
Subroutine feature_cprob_bucketed: not called CC=1 SCAR=6.9
Pod undocumented
1520 0 my ( $self, $edge, $field_index ) = @_;
1521  
1522 0 return $self->feature_additional_model_bucketed( $edge, $field_index, $self->cprob_model );
1523 }
1524  
1525 0 ▶sub feature_cprob_rounded {
Subroutine feature_cprob_rounded: not called CC=1 SCAR=6.9
Pod undocumented
1526 0 my ( $self, $edge, $parameters ) = @_;
1527  
1528 0 return $self->feature_additional_model_rounded( $edge, $parameters, $self->cprob_model );
1529 }
1530  
1531 0 ▶sub feature_cprob_2_rounded {
Subroutine feature_cprob_2_rounded: not called CC=1 SCAR=6.9
Pod undocumented
1532 0 my ( $self, $edge, $field_index ) = @_;
1533  
1534 0 my @params = ( $field_index, 1 );
1535 0 return $self->feature_cprob_rounded( $edge, \@params );
1536 }
1537  
1538 0 ▶sub feature_cprob_3_rounded {
Subroutine feature_cprob_3_rounded: not called CC=1 SCAR=6.9
Pod undocumented
1539 0 my ( $self, $edge, $field_index ) = @_;
1540  
1541 0 my @params = ( $field_index, 2 );
1542 0 return $self->feature_cprob_rounded( $edge, \@params );
1543 }
1544  
1545 4 1;
1546  
1547 __END__
« MSTperl/TrainerBase.pm ↑ Summary MSTperl/Parser.pm »