Natural/Extract.pm

filter: Statementstmt 100% 173 / 173 Branchbran 96.1% 75 / 78 Conditioncond 92.1% 47 / 51 MC/DCmcdc 80.0% 20 / 25 Subroutinesub 100% 15 / 15 Podpod n/a totaltotal 96.4% 330 / 342 CC 65 SCAR 31.7
CC
65
Cov
98%
_extract_expressions
40.0
_extract_duration
11.0
_finalize_expressions
11.0
CRAP 23.8
↑ Summary Natural.pm »
1 package DateTime::Format::Natural::Extract;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use base qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
6 DateTime::Format::Natural::Duration::Checks
7 DateTime::Format::Natural::Formatted
8 27 );
9 27 ▶use boolean qw(true false);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 27 ▶use constant DATE_TYPE => 0x01;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 27 ▶use constant GRAMMAR_TYPE => 0x02;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 27 ▶use constant DURATION_TYPE => 0x04;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 27 ▶use DateTime::Format::Natural::Utils qw(trim);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 27 our $VERSION = '0.14';
18  
19 27 my %grammar_durations = map { $_ => true } qw(for_count_unit);
20  
21 my $get_range = sub
22 412 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
23 412 my ($aref, $index) = @_;
24 412 return [ grep defined, @$aref[$index, $index + 1] ];
25 27 };
26  
27 my $extract_duration = sub
28 179 ▶{
Subroutine __ANON__: called CC=5 SCAR=16.6
29 179 my ($skip, $indexes, $index) = @_;
30  
31 179 ▶ return false unless defined $indexes->[$index] && defined $indexes->[$index + 1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $indexes->[$index] and defined $$indexes[$index + 1] 0 179 179
Condition33%1/3
defined $indexes->[$index] and defined $$indexes[$index + 1]
!ll&&!rl&&r
00179
MC/DC0%0/2
defined $indexes->[$index] and defined $$indexes[$index + 1]
defined $indexes->[$index] defined $$indexes[$index + 1]
Truth table33%1/3
A and B
A= defined $indexes->[$index]B= defined $$indexes[$index + 1]
ABresult
0X0
100
111
32 179 my ($left_index, $right_index) = ($indexes->[$index][1], $indexes->[$index + 1][0]);
33  
34 179 ▶ return ($skip->{$left_index} || $skip->{$right_index}) ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
$skip->{$left_index} || $skip->{$right_index} ? : 68 111 179
Condition100%3/3
$skip->{$left_index} or $skip->{$right_index}
l!l&&r!l&&!r
662111
MC/DC100%2/2
$skip->{$left_index} or $skip->{$right_index}
$skip->{$left_index} $skip->{$right_index}
Truth table100%3/3
A or B
A= $skip->{$left_index}B= $skip->{$right_index}
ABresult
1X1
011
000
35 27 };
36  
37 sub _extract_expressions
38 209 ▶{
Subroutine _extract_expressions: called CC=40 SCAR=36.9
39 209 my $self = shift;
40 209 my ($extract_string) = @_;
41  
42 209 $extract_string =~ s/^[,;.]//;
43 209 $extract_string =~ s/[,;.]$//;
44  
45 209 ▶ while ($extract_string =~ /([,;.])/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extract_string =~ /([,;.])/g) 18 209 227
46 18 my $mark = $1;
47 18 my %patterns = (
48 ',' => qr/(?!\d{4})/,
49 ';' => qr/(?=\w)/,
50 '.' => qr/(?=\w)/,
51 );
52 18 my $pattern = $patterns{$mark};
53 18 $extract_string =~ s/\Q$mark\E \s+? $pattern/ [token] /x; # pretend punctuation marks are tokens
54 }
55  
56 209 my $timespan_sep = $self->{data}->__timespan('literal');
57  
58 209 ▶ 1 while $extract_string =~ s/^$timespan_sep\s+//i;
Branch: 1 branch
BranchTrueFalseTotal
$extract_string =~ s/^$timespan_sep\s+//i and do { '???' } 3 209 212
59 209 ▶ 1 while $extract_string =~ s/\s+$timespan_sep$//i;
Branch: 1 branch
BranchTrueFalseTotal
$extract_string =~ s/\s+$timespan_sep$//i and do { '???' } 6 209 215
60  
61 209 $self->_rewrite(\$extract_string);
62  
63 209 my @tokens = split /\s+/, $extract_string;
64 209 my %entries = %{$self->{data}->__grammar('')};
65  
66 209 my (@expressions, %skip);
67  
68 209 ▶ if ($extract_string =~ /\s+ $timespan_sep \s+/ix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extract_string =~ /\s+ $timespan_sep \s+/xi) 97 112 209
69 97 $self->_extract_duration($extract_string, \@tokens, \@expressions, \%skip);
70 }
71  
72 209 my (%expand, %lengths);
73 209 foreach my $keyword (keys %entries) {
74 15048 $expand{$keyword} = $self->_expand_for($keyword);
75 15048 $lengths{$keyword} = @{$entries{$keyword}->[0]};
76 }
77  
78 209 my $seen_expression;
79 209 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$seen_expression and do { do { $seen_expression = &false(); my $date_index = undef; for (my $i = 0; $i < @tokens; ++$i) { next if $skip{$i}; if ($self->_check_for_date($tokens[$i], $i, \$date_index)) { last; } ; } ; GRAMMAR: foreach my $keyword (sort {$lengths{$b} <=> $lengths{$a};} grep({$lengths{$_} <= @tokens;} keys %entries)) { my(@grammar) = @{$entries{$keyword};}; my $types_entry = shift @grammar; my(@grammars) = [[@grammar], &false()]; if ($expand{$keyword} and @$types_entry + 1 <= @tokens) { @grammar = $self->_expand($keyword, $types_entry, \@grammar); unshift @grammars, [[@grammar], &true()]; } ; foreach my $grammar (@grammars) { my $expanded = $grammar->[1]; my $length = $lengths{$keyword}; ++$length if $expanded; foreach my $entry (@{$$grammar[0];}) { () = $expanded ? @$entry : ($types_entry, $entry); my $definition = $expression->[0]; my $matched = &false(); my $pos = 0; my @indexes; my $date_index = undef; for (my $i = 0; $i < @tokens; ++$i) { next if $skip{$i}; last unless defined $types->[$pos]; if ($self->_check_for_date($tokens[$i], $i, \$date_index)) { next; } ; if ($types->[$pos] eq "SCALAR" and defined $definition->{$pos} and $tokens[$i] =~ /^$definition->{$pos}$/i or $types->[$pos] eq "REGEXP" and $tokens[$i] =~ /$definition->{$pos}/ and @indexes ? $i - $indexes[-1] == 1 : &true()) { $matched = &true(); push @indexes, $i; ++$pos; } elsif ($matched) { last; } ; } ; if ($matched and @indexes == $length and defined $date_index ? $indexes[0] - $date_index == 1 : &true()) { my $expression = join(" ", (defined $date_index ? $tokens[$date_index] : (), @tokens[@indexes])); my $start_index = defined $date_index ? $indexes[0] - 1 : $indexes[0]; my $type = $grammar_durations{$keyword} ? 4 : 2; push @expressions, [[$start_index, $indexes[-1]], $expression, {"flags", $type}]; $skip{$_} = &true() foreach (defined $date_index ? $date_index : (), @indexes); $seen_expression = &true(); last GRAMMAR; } ; } ; } ; } ; if (defined $date_index and not $seen_expression) { push @expressions, [[($date_index) x 2], $tokens[$date_index], {"flags", 1}]; $skip{$date_index} = &true(); $seen_expression = &true(); } } } 230 209 439
80 439 $seen_expression = false;
81 439 my $date_index = undef;
82 439 ▶ for (my $i = 0; $i < @tokens; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @tokens) 1844 423 2267
83 1844 ▶ next if $skip{$i};
Branch: 1 branch
BranchTrueFalseTotal
if $skip{$i} 759 1085 1844
84 1085 ▶ if ($self->_check_for_date($tokens[$i], $i, \$date_index)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_check_for_date($tokens[$i], $i, \$date_index)) 16 1069 1085
85 16 last;
86 }
87 }
88 439 GRAMMAR: foreach my $keyword (sort { $lengths{$b} <=> $lengths{$a} } grep { $lengths{$_} <= @tokens } keys %entries) {
89 20503 my @grammar = @{$entries{$keyword}};
90 20503 my $types_entry = shift @grammar;
91 20503 my @grammars = [ [ @grammar ], false ];
92 20503 ▶ if ($expand{$keyword} && @$types_entry + 1 <= @tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expand{$keyword} and @$types_entry + 1 <= @tokens) 4433 16070 20503
Condition100%3/3
$expand{$keyword} and @$types_entry + 1 <= @tokens
!ll&&!rl&&r
151679034433
MC/DC100%2/2
$expand{$keyword} and @$types_entry + 1 <= @tokens
$expand{$keyword} @$types_entry + 1 <= @tokens
Truth table100%3/3
A and B
A= $expand{$keyword}B= @$types_entry + 1 <= @tokens
ABresult
0X0
100
111
93 4433 @grammar = $self->_expand($keyword, $types_entry, \@grammar);
94 4433 unshift @grammars, [ [ @grammar ], true ];
95 }
96 20503 foreach my $grammar (@grammars) {
97 24933 my $expanded = $grammar->[1];
98 24933 my $length = $lengths{$keyword};
99 24933 ▶ $length++ if $expanded;
Branch: 1 branch
BranchTrueFalseTotal
if $expanded 4433 20500 24933
100 24933 foreach my $entry (@{$grammar->[0]}) {
101 153288 ▶ my ($types, $expression) = $expanded ? @$entry : ($types_entry, $entry);
Branch: 1 branch
BranchTrueFalseTotal
$expanded ? : 66831 86457 153288
102 153288 my $definition = $expression->[0];
103 153288 my $matched = false;
104 153288 my $pos = 0;
105 153288 my @indexes;
106 153288 my $date_index = undef;
107 153288 ▶ for (my $i = 0; $i < @tokens; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @tokens) 857083 147948 1005031
108 857083 ▶ next if $skip{$i};
Branch: 1 branch
BranchTrueFalseTotal
if $skip{$i} 356290 500793 857083
109 500793 ▶ last unless defined $types->[$pos];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $types->[$pos] 92 500701 500793
110 500701 ▶ if ($self->_check_for_date($tokens[$i], $i, \$date_index)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_check_for_date($tokens[$i], $i, \$date_index)) 10047 490654 500701
111 10047 next;
112 }
113 490654 ▶ if ($types->[$pos] eq 'SCALAR' && defined $definition->{$pos} && $tokens[$i] =~ /^$definition->{$pos}$/i
Branch: 3 branches
BranchTrueFalseTotal
if ($types->[$pos] eq 'SCALAR' and defined $definition->{$pos} and $tokens[$i] =~ /^$definition->{$pos}$/i or $types->[$pos] eq 'REGEXP' and $tokens[$i] =~ /$definition->{$pos}/ and @indexes ? $i - $indexes[-1] == 1 : &true()) { } 7860 482794 490654
elsif ($matched) { } 5248 477546 482794
@indexes ? : 237 7416 7653
Condition86%13/15
$types->[$pos] eq "SCALAR" and defined $definition->{$pos} and $tokens[$i] =~ /^$definition->{$pos}$/i or $types->[$pos] eq "REGEXP" and $tokens[$i] =~ /$definition->{$pos}/ and @indexes ? $i - $indexes[-1] == 1 : &true()
l!l&&r!l&&!r
2077653482794
$types->[$pos] eq "SCALAR" and defined $definition->{$pos} and $tokens[$i] =~ /^$definition->{$pos}$/i
!ll&&!rl&&r
44874741700207
$types->[$pos] eq "SCALAR" and defined $definition->{$pos}
!ll&&!rl&&r
448747041907
$types->[$pos] eq "REGEXP" and $tokens[$i] =~ /$definition->{$pos}/ and @indexes ? $i - $indexes[-1] == 1 : &true()
!ll&&!rl&&r
48279407653
$types->[$pos] eq "REGEXP" and $tokens[$i] =~ /$definition->{$pos}/
!ll&&!rl&&r
417004410947653
MC/DC50%3/6
$types->[$pos] eq "SCALAR" and defined $definition->{$pos} and $tokens[$i] =~ /^$definition->{$pos}$/i or $types->[$pos] eq "REGEXP" and $tokens[$i] =~ /$definition->{$pos}/ and @indexes ? $i - $indexes[-1] == 1 : &true()
$types->[$pos] eq "SCALAR" defined $definition->{$pos} $tokens[$i] =~ /^$definition->{$pos}$/i $types->[$pos] eq "REGEXP" $tokens[$i] =~ /$definition->{$pos}/ @indexes ? $i - $indexes[-1] == 1 : &true()
Truth table30%4/13
A and B and C or D and E and F
A= $types->[$pos] eq "SCALAR"B= defined $definition->{$pos}C= $tokens[$i] =~ /^$definition->{$pos}$/iD= $types->[$pos] eq "REGEXP"E= $tokens[$i] =~ /$definition->{$pos}/F= @indexes ? $i - $indexes[-1] == 1 : &true()
ABCDEFresult
111XXX1
0XX1111
10X1111
1101111
0XX0XX0
0XX10X0
0XX1100
10X0XX0
10X10X0
10X1100
1100XX0
11010X0
1101100
114 or $types->[$pos] eq 'REGEXP' && $tokens[$i] =~ $definition->{$pos}
115 && (@indexes ? ($i - $indexes[-1] == 1) : true)
116 ) {
117 7860 $matched = true;
118 7860 push @indexes, $i;
119 7860 $pos++;
120 }
121 elsif ($matched) {
122 5248 last;
123 }
124 }
125 153288 ▶ if ($matched
Branch: 2 branches
BranchTrueFalseTotal
if ($matched and @indexes == $length and defined $date_index ? $indexes[0] - $date_index == 1 : &true()) 223 153065 153288
defined $date_index ? : 12 214 226
Condition100%6/6
$matched and @indexes == $length and defined $date_index ? $indexes[0] - $date_index == 1 : &true()
!ll&&!rl&&r
1530623223
$matched and @indexes == $length
!ll&&!rl&&r
1457327330226
MC/DC100%3/3
$matched and @indexes == $length and defined $date_index ? $indexes[0] - $date_index == 1 : &true()
$matched @indexes == $length defined $date_index ? $indexes[0] - $date_index == 1 : &true()
Truth table100%4/4
A and B and C
A= $matchedB= @indexes == $lengthC= defined $date_index ? $indexes[0] - $date_index == 1 : &true()
ABCresult
0XX0
10X0
1100
1111
126 && @indexes == $length
127 && (defined $date_index ? ($indexes[0] - $date_index == 1) : true)
128 ) {
129 223 ▶ my $expression = join ' ', (defined $date_index ? $tokens[$date_index] : (), @tokens[@indexes]);
Branch: 1 branch
BranchTrueFalseTotal
defined $date_index ? : 9 214 223
130 223 ▶ my $start_index = defined $date_index ? $indexes[0] - 1 : $indexes[0];
Branch: 1 branch
BranchTrueFalseTotal
defined $date_index ? : 9 214 223
131 223 ▶ my $type = $grammar_durations{$keyword} ? DURATION_TYPE : GRAMMAR_TYPE;
Branch: 1 branch
BranchTrueFalseTotal
$grammar_durations{$keyword} ? : 6 217 223
132 223 push @expressions, [ [ $start_index, $indexes[-1] ], $expression, { flags => $type } ];
133 223 ▶ $skip{$_} = true foreach (defined $date_index ? $date_index : (), @indexes);
Branch: 1 branch
BranchTrueFalseTotal
defined $date_index ? : 9 214 223
134 223 $seen_expression = true;
135 223 last GRAMMAR;
136 }
137 }
138 }
139 }
140 439 ▶ if (defined $date_index && !$seen_expression) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $date_index and not $seen_expression) 7 432 439
Condition100%3/3
defined $date_index and not $seen_expression
!ll&&!rl&&r
42397
MC/DC100%2/2
defined $date_index and not $seen_expression
defined $date_index not $seen_expression
Truth table100%3/3
A and not(B)
A= defined $date_indexB= not $seen_expression
ABresult
0X0
100
111
141 7 push @expressions, [ [ ($date_index) x 2 ], $tokens[$date_index], { flags => DATE_TYPE } ];
142 7 $skip{$date_index} = true;
143 7 $seen_expression = true;
144 }
145 } while ($seen_expression);
146  
147 209 return $self->_finalize_expressions(\@expressions, \@tokens);
148 }
149  
150 sub _extract_duration
151 97 ▶{
Subroutine _extract_duration: called CC=11 SCAR=24.0
152 97 my $self = shift;
153 97 my ($extract_string, $tokens, $expressions, $skip) = @_;
154  
155 97 my $timespan_sep = $self->{data}->__timespan('literal');
156  
157 97 my @strings = grep /\S/, map trim($_), split /\b $timespan_sep \b/ix, $extract_string;
158 97 ▶ if (@strings) {
Branch: 1 branch
BranchTrueFalseTotal
if (@strings) 97 0 97
159 97 my $index = 0;
160 97 my @indexes;
161 97 foreach my $string (@strings) {
162 208 my @string_tokens = split /\s+/, $string;
163 208 push @indexes, [ $index, $index + $#string_tokens ];
164 208 $index += $#string_tokens + 1;
165 208 ▶ $index++ while defined $tokens->[$index] && $tokens->[$index] =~ /^$timespan_sep$/i;
Branch: 1 branch
BranchTrueFalseTotal
defined $tokens->[$index] and $tokens->[$index] =~ /^$timespan_sep$/i and do { ++$index } 114 208 322
Condition100%3/3
defined $tokens->[$index] and $tokens->[$index] =~ /^$timespan_sep$/i
!ll&&!rl&&r
97111114
MC/DC100%2/2
defined $tokens->[$index] and $tokens->[$index] =~ /^$timespan_sep$/i
defined $tokens->[$index] $tokens->[$index] =~ /^$timespan_sep$/i
Truth table100%3/3
A and B
A= defined $tokens->[$index]B= $tokens->[$index] =~ /^$timespan_sep$/i
ABresult
0X0
100
111
166 }
167 DURATION: {
168 97 ▶ for (my $i = 0; $i <= $#strings - 1; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#strings - 1) 179 97 276
169 179 ▶ next unless $extract_duration->($skip, \@indexes, $i);
Branch: 1 branch
BranchTrueFalseTotal
unless &$extract_duration($skip, \@indexes, $i) 68 111 179
170 111 my $save_expression = false;
171 111 my @chunks;
172 111 foreach my $extract (qw(_first_to_last_extract _from_count_to_count_extract)) {
173 206 ▶ if ($self->$extract($get_range->(\@strings, $i), $get_range->(\@indexes, $i), $tokens, \@chunks)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->$extract(&$get_range(\@strings, $i), &$get_range(\@indexes, $i), $tokens, \@chunks)) 63 143 206
174 63 $save_expression = true;
175 63 last;
176 }
177 }
178 111 ▶ if ($save_expression) {
Branch: 1 branch
BranchTrueFalseTotal
if ($save_expression) 63 48 111
179 63 my $timespan_sep_index = $chunks[0]->[0][1] + 1;
180 63 my $expression = join ' ', ($chunks[0]->[1], $tokens->[$timespan_sep_index], $chunks[1]->[1]);
181 63 my @indexes = ($chunks[0]->[0][0], $chunks[1]->[0][1]);
182 63 push @$expressions, [ [ @indexes ], $expression, { flags => DURATION_TYPE } ];
183 63 $skip->{$_} = true foreach ($indexes[0] .. $indexes[1]);
184 63 redo DURATION;
185 }
186 }
187 }
188 }
189 }
190  
191 sub _finalize_expressions
192 209 ▶{
Subroutine _finalize_expressions: called CC=11 SCAR=24.0
193 209 my $self = shift;
194 209 my ($expressions, $tokens) = @_;
195  
196 209 my $timespan_sep = $self->{data}->__timespan('literal');
197 209 my (@duration_indexes, @final_expressions);
198  
199 209 my $seen_duration = false;
200  
201 209 my @expressions = sort { $a->[0][0] <=> $b->[0][0] } @$expressions;
202  
203 209 ▶ for (my $i = 0; $i < @expressions; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @expressions) 293 209 502
204 293 my $expression = $expressions[$i];
205  
206 293 my $prev = $expression->[0][0] - 1;
207 293 my $next = $expression->[0][1] + 1;
208  
209 293 ▶ if ($expression->[2]->{flags} & (DATE_TYPE|GRAMMAR_TYPE)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($expression->[2]{'flags'} & 3) { } 224 69 293
elsif ($expression->[2]{'flags'} & 4) { } 69 0 69
210 224 ▶ if (!$seen_duration
Branch: 2 branches
BranchTrueFalseTotal
if (not $seen_duration and defined $tokens->[$next] and $tokens->[$next] =~ /^$timespan_sep$/i and defined $expressions[$i + 1] and $expressions[$i + 1][2]{'flags'} & 3 and $expressions[$i + 1][0][0] - $next == 1) { } 31 193 224
elsif ($seen_duration) { } 31 162 193
Condition100%15/15
not $seen_duration and defined $tokens->[$next] and $tokens->[$next] =~ /^$timespan_sep$/i and defined $expressions[$i + 1] and $expressions[$i + 1][2]{"flags"} & 3 and $expressions[$i + 1][0][0] - $next == 1
!ll&&!rl&&r
190331
not $seen_duration and defined $tokens->[$next] and $tokens->[$next] =~ /^$timespan_sep$/i and defined $expressions[$i + 1] and $expressions[$i + 1][2]{"flags"} & 3
!ll&&!rl&&r
185534
not $seen_duration and defined $tokens->[$next] and $tokens->[$next] =~ /^$timespan_sep$/i and defined $expressions[$i + 1]
!ll&&!rl&&r
184139
not $seen_duration and defined $tokens->[$next] and $tokens->[$next] =~ /^$timespan_sep$/i
!ll&&!rl&&r
1374740
not $seen_duration and defined $tokens->[$next]
!ll&&!rl&&r
3110687
MC/DC100%6/6
not $seen_duration and defined $tokens->[$next] and $tokens->[$next] =~ /^$timespan_sep$/i and defined $expressions[$i + 1] and $expressions[$i + 1][2]{"flags"} & 3 and $expressions[$i + 1][0][0] - $next == 1
not $seen_duration defined $tokens->[$next] $tokens->[$next] =~ /^$timespan_sep$/i defined $expressions[$i + 1] $expressions[$i + 1][2]{"flags"} & 3 $expressions[$i + 1][0][0] - $next == 1
Truth table100%7/7
not(A) and B and C and D and E and F
A= not $seen_durationB= defined $tokens->[$next]C= $tokens->[$next] =~ /^$timespan_sep$/iD= defined $expressions[$i + 1]E= $expressions[$i + 1][2]{"flags"} & 3F= $expressions[$i + 1][0][0] - $next == 1
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
211 && defined $tokens->[$next]
212 && $tokens->[$next] =~ /^$timespan_sep$/i
213 && defined $expressions[$i + 1]
214 && $expressions[$i + 1]->[2]->{flags} & (DATE_TYPE|GRAMMAR_TYPE)
215 && $expressions[$i + 1]->[0][0] - $next == 1
216 ) {
217 31 push @duration_indexes, ($expression->[0][0] .. $expression->[0][1]);
218 31 $seen_duration = true;
219 }
220 elsif ($seen_duration) {
221 31 push @duration_indexes, ($prev, $expression->[0][0] .. $expression->[0][1]);
222 31 push @final_expressions, join ' ', @$tokens[@duration_indexes];
223 31 @duration_indexes = ();
224 31 $seen_duration = false;
225 }
226 else {
227 162 push @final_expressions, $expression->[1];
228 }
229 }
230 elsif ($expression->[2]->{flags} & DURATION_TYPE) {
231 69 push @final_expressions, $expression->[1];
232 }
233 }
234  
235 209 ▶ my $exclude = sub { $_[0] =~ /^\d{1,2}$/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
236  
237 209 return grep !$exclude->($_), @final_expressions;
238 }
239  
240 sub _check_for_date
241 501786 ▶{
Subroutine _check_for_date: called CC=2 SCAR=6.9
242 501786 my $self = shift;
243 501786 my ($token, $index, $date_index) = @_;
244  
245 501786 my ($formatted) = $token =~ $self->{data}->__regexes('format');
246 501786 my %count = $self->_count_separators($formatted);
247 501786 ▶ if ($self->_check_formatted('ymd', \%count)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_check_formatted('ymd', \%count)) { } 10063 491723 501786
248 10063 $$date_index = $index;
249 10063 return true;
250 }
251 else {
252 491723 return false;
253 }
254 }
255  
256 27 1;
257 __END__
↑ Summary Natural.pm »