blib/lib/Lingua/EN/Conjugate.pm

filter: Statementstmt 81.3% 200 / 246 Branchbran 71.7% 99 / 138 Conditioncond 72.2% 26 / 36 MC/DCmcdc 50.0% 9 / 18 Subroutinesub 92.0% 23 / 25 Podpod 40.0% 6 / 15 totaltotal 75.9% 363 / 478 CC 88 SCAR 32.0
CC
88
Cov
77%
conjugations
110.0
_conj
30.3
conjugate
24.7
CRAP 24.5
↑ Summary
1
2 package Lingua::EN::Conjugate;
3
4 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 require Exporter;
6
7 2 @ISA = qw( Exporter );
8
9 2 @EXPORT_OK = qw(
10 conjugate
11 conjugations
12 participle
13 past
14 gerund
15 s_form
16 @tenses
17 @pron
18 %irreg
19 %no_double
20 );
21
22 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 #use diagnostics;
25
26 2 ▶use Lingua::EN::Contraction qw(contract_n_t contract_other);
Subroutine BEGIN: called CC=1 SCAR=0.0
27
28
29 2 ▶if (eval "use Memoize") {
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (eval "use Memoize") 0 2 2
30 0 memoize('stem');
31 0 memoize('participle');
32 0 memoize('past');
33 0 memoize('gerund');
34 0 memoize('s_form');
35 }
36
37 2 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
38 $VERSION
39 %irreg
40 @pron
41 @tenses
42 %conj
43 %no_double
44 %tense_patterns
45
46 2 );
47
48 2 $VERSION = '0.311';
49 2 @pron = qw(I you we he she it they);
50
51
52 2 our @modal = qw(may might must be being been am are is was were do does did should could would have has had will can shall);
53
54
55
56 2 our $modal_re = '\b(?:' . join("|", @modal) . ')';
57 2 $modal_re = qr/$modal_re/i;
58 2 our $pronoun_re = '\b(?:' . join("|", @pron) . ')\b';
59 2 $pronoun_re = qr/$pronoun_re/i;
60
61
62
63 2 @tenses = qw (
64 present present_prog
65 past past_prog
66 past_prog used_to
67 perfect past_perfect
68 perfect_prog past_perfect_prog
69 modal modal_prog
70 modal_perf_prog conjunctive_present
71 imperative
72 );
73
74 2 %tense_patterns = (
75
76 ACTIVE => {
77 # TENSE STATEMENT QUESTION
78 present => [ '@ PRESENT *', 'PRESENT @ *' ],
79 present_do => [ '@ DO * INF', 'DO @ * INF' ],
80 present_prog => [ '@ BE * GERUND', 'BE @ * GERUND' ],
81 past => [ '@ PAST *', 'PAST @ *' ],
82 past_do => [ '@ did * INF', 'did @ * INF' ],
83 past_prog => [ '@ WAS * GERUND', 'WAS @ * GERUND' ],
84 used_to => [ '@ used to * INF', 'N/A' ],
85 perfect => [ '@ HAVE * PART', 'HAVE @ * PART' ],
86 past_perfect => [ '@ had * PART', 'had @ * PART' ],
87 perfect_prog => [ '@ HAVE * been GERUND', 'HAVE @ * been GERUND' ],
88 past_perfect_prog =>
89 [ '@ had * been GERUND', 'had @ * been GERUND' ],
90 modal => [ '@ MODAL * INF', 'MODAL @ * INF' ],
91 modal_prog => [ '@ MODAL * be GERUND', 'MODAL @ * be GERUND' ],
92 modal_perf => [ '@ MODAL * have PART', 'MODAL @ * have PART' ],
93 modal_perf_prog =>
94 [ '@ MODAL * have been GERUND', 'MODAL @ * have been GERUND' ],
95 conjunctive_present => [ '@ INF', 'N/A' ],
96 imperative => [ 'IMPERATIVE', 'N/A' ] },
97
98 PASSIVE => {
99 present => [ '@ BE * PART', 'BE @ * PART' ],
100 present_prog => [ '@ BE * being PART', 'BE @ * being PART' ],
101 past => [ '@ WAS * PART', 'WAS @ * PART' ],
102 past_prog => [ '@ WAS * being PART', 'WAS @ * being PART' ],
103 perfect => [ '@ HAVE * been PART', 'HAVE @ * been PART' ],
104 past_perfect => [ '@ had * been PART', 'had @ * been PART' ],
105 modal => [ '@ MODAL * be PART', 'MODAL @ * be PART' ],
106 modal_perf => [ '@ MODAL * have been PART', 'MODAL @ * have been PART' ]
107 }
108 # @ = pronoun, * = not
109 );
110
111 2 %irreg = _irreg();
112
113
114 2 $no_double{$_} = 1 for _no_double();
115
116
117
118
119 26 ▶sub conjugate {
Subroutine conjugate: called CC=23 SCAR=32.1
Pod documented
120
121 26 my %params = @_;
122
123 #parameters:
124 26 our ($inf, $modal, $passive, $allow_contractions, $question, $negation, $no_pronoun);
125
126 #forms of the verb determined by "init_verb":
127 #our ($part, $past, $gerund, $s_form,);
128
129 $inf =
130 26 ▶ defined $params{verb} ? $params{verb} : warn "must define a verb!!\n",
Branch: 1 branch
BranchTrueFalseTotal
defined $params{'verb'} ? : 26 0 26
131 return undef;
132 26 $inf =~ s/^ *| *$//g;
133 26 $inf =~ s/ *//g;
134
135 26 ▶ $modal = defined $params{modal} ? $params{modal} : 'will';
Branch: 1 branch
BranchTrueFalseTotal
defined $params{'modal'} ? : 2 24 26
136 26 ▶ $passive = defined $params{passive} ? $params{passive} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $params{'passive'} ? : 1 25 26
137 26 ▶ $allow_contractions = defined $params{allow_contractions}? $params{allow_contractions}: undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $params{'allow_contractions'} ? : 3 23 26
138 26 ▶ $no_pronoun = defined $params{no_pronoun}? $params{no_pronoun} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $params{'no_pronoun'} ? : 1 25 26
139
140
141 26 ▶ unless ( $modal =~ $modal_re ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Lingua::EN::Conjugate::modal =~ /$Lingua::EN::Conjugate::modal_re/) 0 26 26
142 0 warn "$modal is not a modal verb!!\n";
143 0 return 0;
144 }
145
146 26 ▶ $question = defined $params{question} ? $params{question} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $params{'question'} ? : 2 24 26
147 26 ▶ $negation = defined $params{negation} ? $params{negation} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $params{'negation'} ? : 8 18 26
148
149 # ( $part, $past, $gerund, $s_form ) = init_verb($inf);
150
151 26 ▶ if ( ref $params{pronoun}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $params{"pronoun"} or ref $params{"tense"} or not defined $params{"pronoun"} or not defined $params{"tense"}) 2 24 26
Condition77%7/9
ref $params{"pronoun"} or ref $params{"tense"} or not defined $params{"pronoun"} or not defined $params{"tense"}
l!l&&r!l&&!r
2024
ref $params{"pronoun"} or ref $params{"tense"} or not defined $params{"pronoun"}
l!l&&r!l&&!r
2024
ref $params{"pronoun"} or ref $params{"tense"}
l!l&&r!l&&!r
1124
MC/DC50%2/4
ref $params{"pronoun"} or ref $params{"tense"} or not defined $params{"pronoun"} or not defined $params{"tense"}
ref $params{"pronoun"} ref $params{"tense"} not defined $params{"pronoun"} not defined $params{"tense"}
Truth table60%3/5
A or B or not(C) or not(D)
A= ref $params{"pronoun"}B= ref $params{"tense"}C= not defined $params{"pronoun"}D= not defined $params{"tense"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
152 or ref $params{tense}
153 or !defined $params{pronoun}
154 or !defined $params{tense} )
155 {
156 2 my $ret = {};
157 my @t =
158 2 ▶ ref $params{tense} ? @{ $params{tense} }
Branch: 1 branch
BranchTrueFalseTotal
defined $params{'tense'} ? : 0 0 0
159 : defined $params{tense} ? $params{tense}
160 2 ▶ : @tenses;
Branch: 1 branch
BranchTrueFalseTotal
ref $params{'tense'} ? : 2 0 2
161
162 2 for my $t (@t) {
163
164 my @p =
165 4 ref $params{pronoun} ? grep { defined _conj($inf, $t, $_ ) }
166 2 ▶ @{ $params{pronoun} }
Branch: 1 branch
BranchTrueFalseTotal
defined $params{'pronoun'} ? : 0 2 2
167 : defined $params{pronoun} ? $params{pronoun}
168 4 ▶ : grep { defined _conj( $inf, $t, $_ ) } @pron;
Branch: 1 branch
BranchTrueFalseTotal
ref $params{'pronoun'} ? : 2 2 4
169
170 4 for my $p (@p) {
171 18 ▶ next unless defined _conj($inf, $t, $p );
Branch: 1 branch
BranchTrueFalseTotal
unless defined _conj($Lingua::EN::Conjugate::inf, $t, $p) 0 18 18
172 18 $ret->{$t}{$p} = _conj($inf, $t, $p );
173 }
174 }
175
176 2 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1 1 2
177 1 my @return = ();
178 1 for my $t ( keys %{$ret} ) {
179 2 for my $p ( keys %{ $ret->{$t} } ) {
180
181 4 push @return, $ret->{$t}{$p};
182 }
183 }
184 1 return @return;
185 }
186 1 else { return $ret }
187 }
188
189 24 return _conj($inf, $params{tense}, $params{pronoun} );
190
191
192 78 ▶sub _conj {
Subroutine _conj: called CC=29 SCAR=34.1
193
194 78 my ( $inf, $tense, $pronoun ) = @_;
195 78 my $part = participle($inf);
196 78 my $past = past($inf);
197 78 my $gerund = gerund($inf);
198 78 my $s_form = s_form($inf);
199
200
201 # special cases...
202 78 ▶ if ( match_any( $inf, qw(should could would can shall will may might must))) {
Branch: 1 branch
BranchTrueFalseTotal
if (match_any($inf, ("should", "could", "would", "can", "shall", "will", "may", "might", "must"))) 2 76 78
203 2 ▶ return undef unless $tense eq 'present';
Branch: 1 branch
BranchTrueFalseTotal
unless $tense eq "present" 1 1 2
204 }
205 77 ▶ if ( $inf !~ $modal_re ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($inf =~ /$Lingua::EN::Conjugate::modal_re/) 58 19 77
206 58 ▶ if ( $tense eq 'present' and (defined $negation or $question) and not defined $passive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tense eq "present" and defined $Lingua::EN::Conjugate::negation || $Lingua::EN::Conjugate::question and not defined $Lingua::EN::Conjugate::passive) 1 57 58
Condition88%8/9
$tense eq "present" and defined $Lingua::EN::Conjugate::negation || $Lingua::EN::Conjugate::question and not defined $Lingua::EN::Conjugate::passive
!ll&&!rl&&r
5611
$tense eq "present" and defined $Lingua::EN::Conjugate::negation || $Lingua::EN::Conjugate::question
!ll&&!rl&&r
5512
defined $Lingua::EN::Conjugate::negation or $Lingua::EN::Conjugate::question
l!l&&r!l&&!r
201
MC/DC75%3/4
$tense eq "present" and defined $Lingua::EN::Conjugate::negation || $Lingua::EN::Conjugate::question and not defined $Lingua::EN::Conjugate::passive
$tense eq "present" defined $Lingua::EN::Conjugate::negation $Lingua::EN::Conjugate::question not defined $Lingua::EN::Conjugate::passive
Truth table66%4/6
A and B or C and not(D)
A= $tense eq "present"B= defined $Lingua::EN::Conjugate::negationC= $Lingua::EN::Conjugate::questionD= not defined $Lingua::EN::Conjugate::passive
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
207 1 $tense = 'present_do';
208 }
209 58 ▶ if ( $tense eq 'past' and (defined $negation or $question) and not defined $passive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tense eq "past" and defined $Lingua::EN::Conjugate::negation || $Lingua::EN::Conjugate::question and not defined $Lingua::EN::Conjugate::passive) 2 56 58
Condition88%8/9
$tense eq "past" and defined $Lingua::EN::Conjugate::negation || $Lingua::EN::Conjugate::question and not defined $Lingua::EN::Conjugate::passive
!ll&&!rl&&r
5602
$tense eq "past" and defined $Lingua::EN::Conjugate::negation || $Lingua::EN::Conjugate::question
!ll&&!rl&&r
5242
defined $Lingua::EN::Conjugate::negation or $Lingua::EN::Conjugate::question
l!l&&r!l&&!r
114
MC/DC75%3/4
$tense eq "past" and defined $Lingua::EN::Conjugate::negation || $Lingua::EN::Conjugate::question and not defined $Lingua::EN::Conjugate::passive
$tense eq "past" defined $Lingua::EN::Conjugate::negation $Lingua::EN::Conjugate::question not defined $Lingua::EN::Conjugate::passive
Truth table66%4/6
A and B or C and not(D)
A= $tense eq "past"B= defined $Lingua::EN::Conjugate::negationC= $Lingua::EN::Conjugate::questionD= not defined $Lingua::EN::Conjugate::passive
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
210 2 $tense = 'past_do';
211 }
212 }
213
214 77 ▶ if ( $tense eq 'conjunctive_present' and defined $negation ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tense eq "conjunctive_present" and defined $Lingua::EN::Conjugate::negation) 0 77 77
Condition33%1/3
$tense eq "conjunctive_present" and defined $Lingua::EN::Conjugate::negation
!ll&&!rl&&r
7700
MC/DC0%0/2
$tense eq "conjunctive_present" and defined $Lingua::EN::Conjugate::negation
$tense eq "conjunctive_present" defined $Lingua::EN::Conjugate::negation
Truth table33%1/3
A and B
A= $tense eq "conjunctive_present"B= defined $Lingua::EN::Conjugate::negation
ABresult
0X0
100
111
215 0 return undef;
216
217 }
218
219 77 ▶ my $active_passive = $passive ? 'PASSIVE' : 'ACTIVE';
Branch: 1 branch
BranchTrueFalseTotal
$Lingua::EN::Conjugate::passive ? : 1 76 77
220
221 77 ▶ my $pattern = $tense_patterns{$active_passive}{$tense}[$question] or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $pattern = $Lingua::EN::Conjugate::tense_patterns{$active_passive}{$tense}[$Lingua::EN::Conjugate::question] or return undef 77 0 77
222
223 77 ▶ if ($no_pronoun) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Lingua::EN::Conjugate::no_pronoun) 1 76 77
224 1 $pattern =~ s/^\@ //;
225 }
226
227 77 $pattern =~ s/\@/$pronoun/;
228
229
230 0 ▶ if ( $pattern eq 'N/A' ) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern eq "N/A") 0 77 77
231 77 $pattern =~ s/DO/DO($pronoun)/e;
232 77 $pattern =~ s/WAS/WAS($pronoun)/e;
233 77 $pattern =~ s/HAVE/HAVE($pronoun)/e;
234 77 $pattern =~ s/MODAL/$modal/;
235 77 $pattern =~ s/BE/BE($pronoun)/e;
236 77 $pattern =~ s/GERUND/$gerund/;
237 77 $pattern =~ s/PART/$part/;
238 77 ▶ if ( $pattern =~ /PRESENT/ ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($pattern =~ /PRESENT/) { } 10 67 77
elsif ($pattern =~ /IMPERATIVE/) { } 1 66 67
elsif ($pattern =~ /PAST/) { } 6 60 66
elsif ($pattern =~ /INF/) { } 25 35 60
239 10 ▶ my $p = PRESENT( $inf, $s_form, $pronoun ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $p = PRESENT($inf, $s_form, $pronoun) or return undef 10 0 10
240 10 $pattern =~ s/PRESENT/$p/;
241 }
242 elsif ( $pattern =~ /IMPERATIVE/ ) {
243 1 ▶ my $i = IMPERATIVE( $inf, $negation, $pronoun ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $i = IMPERATIVE($inf, $Lingua::EN::Conjugate::negation, $pronoun) or return undef 1 0 1
244 1 $pattern =~ s/IMPERATIVE/$i/;
245 }
246 elsif ( $pattern =~ /PAST/ ) {
247
248 6 ▶ my $p = $inf =~ /^be$/ ? WAS($pronoun) : $past ;
Branch: 1 branch
BranchTrueFalseTotal
$inf =~ /^be$/ ? : 0 6 6
249 6 $pattern =~ s/PAST/$p/;
250 }
251 elsif ( $pattern =~ /INF/ ) {
252 25 ▶ return undef unless defined $inf;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $inf 0 25 25
253 25 $pattern =~ s/INF/$inf/;
254 }
255
256 77 ▶ if ($negation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Lingua::EN::Conjugate::negation) { } 8 69 77
257 8 $pattern =~ s/\*/not/;
258 8 ▶ if ($negation eq 'n_t') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Lingua::EN::Conjugate::negation eq "n_t") 5 3 8
259 5 $pattern = contract_n_t($pattern);
260 }
261 }
262 else {
263 69 $pattern =~ s/ ?\*( ?)/$1/;
264 }
265
266 77 ▶ if ($allow_contractions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Lingua::EN::Conjugate::allow_contractions) 2 75 77
267 2 $pattern = contract_other($pattern);
268 }
269
270 77 return $pattern;
271
272 }
273
274
275 1 ▶sub IMPERATIVE {
Subroutine IMPERATIVE: called CC=5 SCAR=22.7
Pod undocumented
276 1 my $inf = shift;
277 1 my $negation = shift;
278 1 my $pronoun = shift;
279
280 1 ▶ if ( $pronoun =~ /we/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pronoun =~ /we/i) { } 0 1 1
elsif ($pronoun =~ /you/i) { } 1 0 1
281 0 my $retval = "let us";
282 0 ▶ if ( defined $negation ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $negation) 0 0 0
283 0 $retval .= " not";
284 }
285 0 $retval .= " $inf";
286 0 return $retval;
287 }
288 elsif ( $pronoun =~ /you/i ) {
289 1 ▶ if ( $negation ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($negation) { } 1 0 1
290 1 return "do not $inf";
291 }
292 else {
293 0 return "$inf";
294 }
295 }
296 else {
297 0 return undef;
298 }
299 }
300
301 }
302 120 ▶sub match_any {
Subroutine match_any: called CC=3 SCAR=11.0
Pod undocumented
303 120 my $a = shift;
304 120 my @b = @_;
305 120 ▶ for (@b) { return 1 if $a =~ /\b$_\b/i ; }
Branch: 1 branch
BranchTrueFalseTotal
if $a =~ /\b$_\b/i 27 775 802
306 93 return undef;
307 }
308
309
310 10 ▶sub PRESENT {
Subroutine PRESENT: called CC=5 SCAR=16.1
Pod undocumented
311 10 my $inf = shift;
312 10 my $s_form = shift;
313 10 my $pronoun = shift;
314
315 10 ▶ if ( $inf =~ /^be$/i ) { return BE($pronoun); }
Branch: 1 branch
BranchTrueFalseTotal
if ($inf =~ /^be$/i) 7 3 10
316 3 ▶ if ( $inf =~ /^have$/i ) { return HAVE($pronoun); }
Branch: 1 branch
BranchTrueFalseTotal
if ($inf =~ /^have$/i) 1 2 3
317 2 ▶ if (defined $s_form and match_any($pronoun, qw(he she it))) { return $s_form; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s_form and match_any($pronoun, ("he", "she", "it"))) 1 1 2
Condition66%2/3
defined $s_form and match_any($pronoun, ("he", "she", "it"))
!ll&&!rl&&r
011
MC/DC50%1/2
defined $s_form and match_any($pronoun, ("he", "she", "it"))
defined $s_form match_any($pronoun, ("he", "she", "it"))
Truth table66%2/3
A and B
A= defined $s_formB= match_any($pronoun, ("he", "she", "it"))
ABresult
0X0
100
111
318
319 1 return $inf;
320 }
321
322
323 12 ▶sub BE {
Subroutine BE: called CC=3 SCAR=11.0
Pod undocumented
324 12 my $pronoun = shift;
325 12 ▶ if ( $pronoun eq 'I' ) { return 'am' }
Branch: 1 branch
BranchTrueFalseTotal
if ($pronoun eq "I") 3 9 12
326
327 9 ▶ if (match_any($pronoun, qw(he she it))) { return 'is'; }
Branch: 1 branch
BranchTrueFalseTotal
if (match_any($pronoun, ("he", "she", "it"))) 6 3 9
328
329 3 return 'are';
330 }
331
332 28 ▶sub WAS {
Subroutine WAS: called CC=2 SCAR=6.9
Pod undocumented
333 28 my $pronoun = shift;
334 28 ▶ if (match_any($pronoun, qw(I he she it))) { return 'was'; }
Branch: 1 branch
BranchTrueFalseTotal
if (match_any($pronoun, ("I", "he", "she", "it"))) 15 13 28
335
336 13 return 'were';
337 }
338
339 2 ▶sub HAVE {
Subroutine HAVE: called CC=2 SCAR=7.6
Pod undocumented
340 2 my $pronoun = shift;
341 2 ▶ if (match_any($pronoun, qw(he she it))) { return 'has'; }
Branch: 1 branch
BranchTrueFalseTotal
if (match_any($pronoun, ("he", "she", "it"))) 2 0 2
342 0 return 'have';
343 }
344
345 1 ▶sub DO {
Subroutine DO: called CC=2 SCAR=7.6
Pod undocumented
346 1 my $pronoun = shift;
347 1 ▶ if (match_any($pronoun, qw(he she it))) { return 'does'; }
Branch: 1 branch
BranchTrueFalseTotal
if (match_any($pronoun, ("he", "she", "it"))) 1 0 1
348 0 return 'do';
349 }
350
351 0 ▶sub conjugations {
Subroutine conjugations: not called CC=10 SCAR=47.0
Pod documented
352
353 0 my ( $tense, $pronoun, $result, @_tenses );
354
355 0 my %params = @_;
356
357 my @pnouns = defined $params{pronoun} ?
358 0 (ref $params{pronoun}? @{ $params{pronoun} } : $params{pronoun})
359 0 ▶ : qw(I you he we they);
Branch: 2 branches
BranchTrueFalseTotal
defined $params{'pronoun'} ? : 0 0 0
ref $params{'pronoun'} ? : 0 0 0
360
361 0 my $conjugs = conjugate(@_);
362
363 0 @_tenses = grep { defined $conjugs->{$_} } @tenses;
364
365 0 $result = "";
366 0 ▶ foreach ( $tense = 0 ; $tense <= $#_tenses ; $tense += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tense <= $#_tenses) 0 0 0
367 0 my $t1 = $_tenses[$tense];
368 0 ▶ my $t2 = $tense < scalar @_tenses ? $_tenses[ $tense + 1 ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$tense < scalar @_tenses ? : 0 0 0
369 0 $result .= centered( uc( $_tenses[$tense] ), 35, "-" );
370 0 $result .= " ";
371 0 ▶ $result .= centered( uc( $_tenses[ $tense + 1 ] ), 35, "-" )
Branch: 1 branch
BranchTrueFalseTotal
if defined $t2 0 0 0
372 if defined $t2;
373 0 $result .= "\n";
374 0 for $pronoun (@pnouns) {
375 my $s1 =
376 defined $conjugs->{$t1}{$pronoun}
377 0 ▶ ? $conjugs->{$t1}{$pronoun}
Branch: 1 branch
BranchTrueFalseTotal
defined $conjugs->{$t1}{$pronoun} ? : 0 0 0
378 : '';
379 my $s2 =
380 defined $t2
381 && defined $conjugs->{$t2}{$pronoun}
382 0 ▶ ? $conjugs->{$t2}{$pronoun}
Branch: 1 branch
BranchTrueFalseTotal
defined $t2 && defined $conjugs->{$t2}{$pronoun} ? : 0 0 0
Condition0%0/3
defined $t2 and defined $conjugs->{$t2}{$pronoun}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $t2 and defined $conjugs->{$t2}{$pronoun}
defined $t2 defined $conjugs->{$t2}{$pronoun}
Truth table0%0/3
A and B
A= defined $t2B= defined $conjugs->{$t2}{$pronoun}
ABresult
0X0
100
111
383 : '';
384 0 $result .= sprintf "%-35s %-35s\n", $s1, $s2;
385
386 }
387 }
388 0 return $result;
389
390 0 ▶ sub centered {
Subroutine centered: not called CC=2 SCAR=17.9
Pod undocumented
391 0 my ( $string, $len, $fill ) = @_;
392 0 ▶ $fill = " " unless defined $fill;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fill 0 0 0
393 0 my $result = $fill x ( ( $len - length($string) ) / 2 - 1 );
394 0 $result .= " ";
395 0 $result .= $string;
396 0 $result .= " ";
397 0 $result .= $fill x ( $len - length($result) );
398 0 return $result;
399 }
400 }
401
402
403
404
405 106 ▶sub stem {
Subroutine stem: called CC=3 SCAR=11.0
Pod undocumented
406
407 106 my $inf = shift;
408 106 my $stem = $inf;
409
410 106 ▶ if ( $stem =~ /[bcdfghjklmnpqrstvwxyz][aeiou][bcdfghjklmnpqrstv]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stem =~ /[bcdfghjklmnpqrstvwxyz][aeiou][bcdfghjklmnpqrstv]$/) 20 86 106
411
412 #if the word ends in CVC pattern (but final consonant is not w,x,y, or z)
413 # and if the stress is not on the penultimate syllable, then double
414 # the final consonant.
415 #
416 # The stop list (stored in %no_double) is a list of words ending in CVC, with the stress
417 # on the penultimate syllable such as visit, happen, enter, etc.
418
419 20 ▶ $stem =~ s/(\w)$/$1$1/ unless $no_double{$stem};
Branch: 1 branch
BranchTrueFalseTotal
unless $Lingua::EN::Conjugate::no_double{$stem} 8 12 20
420
421 }
422 106 return $stem;
423 }
424
425 92 ▶sub participle {
Subroutine participle: called CC=2 SCAR=6.9
Pod documented
426
427 92 my $inf = shift;
428 92 ▶ return $irreg{$inf}{part} if defined $irreg{$inf};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Lingua::EN::Conjugate::irreg{$inf} 64 28 92
429
430 28 my $stem = stem($inf);
431
432 28 my $part = $stem . 'ed';
433 28 $part =~ s/([bcdfghjklmnpqrstvwxyz])eed$/$1ed/;
434 28 $part =~ s/([bcdfghjklmnpqrstvwxyz])yed$/$1ied/;
435 28 $part =~ s/eed$/ed/;
436
437
438 28 return $part;
439
440 }
441
442 79 ▶sub past {
Subroutine past: called CC=2 SCAR=6.9
Pod documented
443
444 79 my $inf = shift;
445 79 ▶ return $irreg{$inf}{past} if defined $irreg{$inf};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Lingua::EN::Conjugate::irreg{$inf} 65 14 79
446 14 return participle($inf);
447 }
448
449 78 ▶sub gerund {
Subroutine gerund: called CC=1 SCAR=0.0
Pod documented
450
451 78 my $inf = shift;
452 78 my $stem = stem($inf);
453
454
455 78 my $gerund = $stem . 'ing';
456 78 $gerund =~ s/(.[bcdfghjklmnpqrstvwxyz])eing$/$1ing/;
457 78 $gerund =~ s/ieing$/ying/;
458 78 return $gerund;
459
460 }
461
462 82 ▶sub s_form {
Subroutine s_form: called CC=7 SCAR=19.5
Pod documented
463
464 82 my $inf = shift;
465 82 my $s_form;
466 #may might must be being been am are is was were do does did should could would have has had will can shall
467 82 ▶ if ( $inf eq 'be') { $s_form = 'is'; }
Branch: 6 branches
BranchTrueFalseTotal
if ($inf eq 'be') { } 13 69 82
elsif ($inf eq 'do') { } 1 68 69
elsif ($inf eq 'have') { } 3 65 68
elsif ($inf =~ /$Lingua::EN::Conjugate::modal_re/) { } 4 61 65
elsif ($inf =~ /[ho]$|ss$/) { } 46 15 61
elsif ($inf =~ /[bcdfghjklmnpqrstvwxyz]y$/) { } 1 14 15
468 1 elsif ( $inf eq 'do') { $s_form = 'does'; }
469 3 elsif ( $inf eq 'have') { $s_form = 'has'; }
470 4 elsif ( $inf =~ $modal_re ) { $s_form = $inf; }
471
472 elsif ( $inf =~ /[ho]$|ss$/ ) {
473 46 $s_form = $inf . "es";
474 }
475 elsif ( $inf =~ /[bcdfghjklmnpqrstvwxyz]y$/ ) {
476 1 $s_form = $inf;
477 1 $s_form =~ s/y$/ies/;
478 }
479
480 else {
481 14 $s_form = $inf . "s";
482 }
483
484 82 return $s_form;
485
486 }
487
488
489 2 1;
490
491 =head1 NAME
492
493 Lingua::EN::Conjugate - Conjugation of English verbs
494
495 =head1 SYNOPSIS
496
497 use Lingua::EN::Conjugate qw( conjugate conjugations contraction);
498
499
500 print conjugate( 'verb'=>'look',
501 'tense'=>'perfect_prog',
502 'pronoun'=>'he',
503 'negation'=>'not' );
504
505 # "he was not looking"
506
507
508 my $go = conjugate( 'verb'=>'go',
509 'tense'=>[qw(past modal_perf)],
510 'modal'=>'might') ;
511
512 # returns a hashref
513
514 print $go->{modal_perf}{I}; # "I might have gone"
515
516
517
518 my @be = conjugate( 'verb'=>'be',
519 'pronoun'=>[qw(I we)],
520 'tense'=>'past_prog',
521 'negation'=>'n_t' );
522
523 # returns an array
524 print $be[0]; # "I wasn't going"
525
526
527 #pretty printed table of conjugations
528
529 print conjugations( 'verb'=>'walk',
530 'question'=>1,
531 'allow_contractions'=>1,
532 'modal'=>'should',
533 'negation'=>'n_t');
534 ------------- PRESENT ------------- ---------- PRESENT_PROG -----------
535 don't I walk am I not walking
536 don't you walk aren't you walking
537 doesn't he walk isn't he walking
538 don't we walk aren't we walking
539 don't they walk aren't they walking
540 -------------- PAST --------------- ------------ PAST_PROG ------------
541 didn't I walk wasn't I walking
542 didn't you walk weren't you walking
543 didn't he walk wasn't he walking
544 didn't we walk weren't we walking
545 didn't they walk weren't they walking
546 ----------- PRESENT_DO ------------ ------------- PAST_DO -------------
547 don't I walk didn't I walk
548 don't you walk didn't you walk
549 doesn't he walk didn't he walk
550 don't we walk didn't we walk
551 don't they walk didn't they walk
552 ------------ PAST_PROG ------------ ------------- PERFECT -------------
553 wasn't I walking haven't I walked
554 weren't you walking haven't you walked
555 wasn't he walking hasn't he walked
556 weren't we walking haven't we walked
557 weren't they walking haven't they walked
558 ---------- PAST_PERFECT ----------- ---------- PERFECT_PROG -----------
559 hadn't I walked haven't I been walking
560 hadn't you walked haven't you been walking
561 hadn't he walked hasn't he been walking
562 hadn't we walked haven't we been walking
563 hadn't they walked haven't they been walking
564 -------- PAST_PERFECT_PROG -------- -------------- MODAL --------------
565 hadn't I been walking shouldn't I walk
566 hadn't you been walking shouldn't you walk
567 hadn't he been walking shouldn't he walk
568 hadn't we been walking shouldn't we walk
569 hadn't they been walking shouldn't they walk
570 -------------- MODAL -------------- --------- MODAL_PERF_PROG ---------
571 shouldn't I walk shouldn't I have been walking
572 shouldn't you walk shouldn't you have been walking
573 shouldn't he walk shouldn't he have been walking
574 shouldn't we walk shouldn't we have been walking
575 shouldn't they walk shouldn't they have been walking
576
577
578
579
580
581 =head1 DESCRIPTION
582
583 This module constructs various verb tenses in English.
584
585 Thanks to Susan Jones for the list of irregular verbs and an explanation of English verb tenses L<http://www2.gsu.edu/~wwwesl/egw/grlists.htm>.
586
587 =over
588
589 =item past($infinitive)
590
591 past tense form of the verb: "go" -> "went"
592
593 =item participle($infinitive)
594
595 past participle form of the verb: "go" -> "gone"
596
597 =item gerund($infinitive)
598
599 "-ing" form of the verb: "go" -> "going"
600
601 =item s_form($infinitive)
602
603 third person singular form of the verb: "go" -> "goes"
604
605 =item conjugate('verb'=> 'go' , OPTIONS)
606
607 In scalar context with tense and pronoun defined as scalars, only one conjugation is returned.
608
609 In scalar context with tense and pronoun undefined or defined as array refs, a hashref keyed by tense and pronoun is returned.
610
611 In array context, it returns an array of conjugated forms ordered by tense, then pronoun.
612
613
614 =item verb
615
616 'verb'=>'coagulate'
617
618 The only required parameter. The verb should be in its infinitive form (no "is", "was" etc.) and without a "to" tacked on the front.
619
620 =item tense
621
622 'tense'=>'past'
623 'tense'=>['modal_perf', 'used_to']
624
625 If no 'tense' argument is supplied, all applicable tenses are returned.
626
627 =item passive
628
629 'passive' => 1
630 'passive' => undef (default)
631
632 If specified, the passive voice is used. Some tenses, such as Imperiative, are disabled when the passive option is used.
633
634
635 =item pronoun
636
637 'pronoun'=>'he'
638 'pronoun'=>[qw(I we you)]
639
640 If no 'pronoun' argument is supplied, all applicable pronouns are returned.
641
642 =item question
643
644 'question' => 1
645 'question' => 0 (default)
646
647 In case you're playing Jeapordy
648
649 =item negation
650
651 'negation'=> 'not'
652 'negation'=> 'n_t'
653 'negation'=> undef (default)
654
655 Changes "do" to "do not" or "don't" depending on which value you request.
656 For words where you can't use "n't" (like "am") or where it feels clumsy or antique (like "may"),
657 this will substitute "not" for "n_t" as appropriate.
658
659 =item modal
660
661 'modal' => one of: may, might, must, should, could, would, will (default), can, shall.
662
663 Specifies what modal verb to use for the modal tenses.
664
665
666 L<http://www.kyrene.k12.az.us/schools/brisas/sunda/verb/1help.htm>
667
668 =item allow_contractions
669
670 'allow_contractions'=>1 allows "I am"->"I'm", "they are"->"they're" and so on
671 'allow_contractions'=>0 (default)
672
673 The negation rule above is applied before the allow_contractions rule is checked:
674
675 allow_contractions =>1, negation=>n_t : "he isn't walking";
676 allow_contractions =>0, negation=>n_t : "he isn't walking";
677 allow_contractions =>1, negation=>not : "he's not walking";
678 allow_contractions =>0, negation=>not " "he is not walking";
679
680
681 =item conjugations()
682
683 returns a pretty-printed table of conjugations. (code stolen from L<Lingua::IT::Conjugate>)
684
685 =back
686
687 =head2 EXPORT
688
689 None by default. You can export the following functions and variables:
690
691 conjugate
692 conjugations
693 past
694 participle
695 gerund
696 s_form
697 @tenses
698 @pronouns
699
700 =head1 BUGS
701
702 =head1 TODO
703
704 HAVE TO + Verb
705 HAVE GOT TO + Verb
706 BE ABLE TO + Verb
707 OUGHT TO + Verb
708 BE SUPPOSED TO + Verb
709
710 =head1 AUTHOR
711
712 Russ Graham, russgraham@gmail.com
713
714 =head1 SEE ALSO
715
716 =over
717
718 =item
719
720 L<Lingua::IT::Conjugate>
721
722 =item
723
724 L<Lingua::PT::Conjugate>
725
726 =item
727
728 L<Lingua::EN::Contraction>
729
730 =back
731
732 =cut
733
734 2 ▶sub _irreg {
Subroutine _irreg: called CC=3 SCAR=11.0
735 2 my %irreg; for (split /\n/, _irreg_data()) {
736 354 ▶ next unless /\w/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\w/ 0 354 354
737 354 my ( $verb, $simp, $part ) = split /-/, $_;
738 354 $verb =~ s/\(.*//;
739 354 $simp =~ s/\/.*//;
740 354 $part =~ s/\/.*//;
741 ( $verb, $simp, $part ) =
742 354 map { s/^\s*|\s*$//g; $_ } ( $verb, $simp, $part );
743 354 $irreg{$verb} = { past => $simp, part => $part };
744 }
745  
746  
747 2 return %irreg;
748 #print "$verb, $simp, $part\n";
749
750 }
751  
752 2 ▶sub _irreg_data {
Subroutine _irreg_data: called CC=1 SCAR=0.0
753 2 return <<EOF;
754 awake - awoke - awoken
755 be - was, were - been
756 bear - bore - born
757 beat - beat - beat
758 become - became - become
759 begin - began - begun
760 bend - bent - bent
761 beset - beset - beset
762 bet - bet - bet
763 bid - bid/bade - bid/bidden
764 bind - bound - bound
765 bite - bit - bitten
766 bleed - bled - bled
767 blow - blew - blown
768 break - broke - broken
769 breed - bred - bred
770 bring - brought - brought
771 broadcast - broadcast - broadcast
772 build - built - built
773 burn - burned/burnt - burned/burnt
774 burst - burst - burst
775 buy - bought - bought
776 cast - cast - cast
777 catch - caught - caught
778 choose - chose - chosen
779 cling - clung - clung
780 come - came - come
781 cost - cost - cost
782 creep - crept - crept
783 cut - cut - cut
784 deal - dealt - dealt
785 dig - dug - dug
786 dive - dove/dived - dived
787 do - did - done
788 draw - drew - drawn
789 dream - dreamed/dreamt - dreamed/dreamt
790 drive - drove - driven
791 drink - drank - drunk
792 dye - dyed - dyed
793 eat - ate - eaten
794 fall - fell - fallen
795 feed - fed - fed
796 feel - felt - felt
797 fight - fought - fought
798 find - found - found
799 fit - fit - fit
800 flee - fled - fled
801 fling - flung - flung
802 fly - flew - flown
803 forbid - forbade - forbidden
804 forget - forgot - forgotten
805 forego - forewent - foregone
806 forgo - forwent - forgone
807 forgive - forgave - forgiven
808 forsake - forsook - forsaken
809 freeze - froze - frozen
810 get - got - gotten
811 give - gave - given
812 go - went - gone
813 grind - ground - ground
814 grow - grew - grown
815 hang - hung - hung
816 have - had - had
817 hear - heard - heard
818 hide - hid - hidden
819 hit - hit - hit
820 hold - held - held
821 hurt - hurt - hurt
822 keep - kept - kept
823 kneel - knelt - knelt
824 knit - knit - knit
825 know - knew - know
826 lay - laid - laid
827 lead - led - led
828 leap - leaped/lept - leaped/lept
829 learn - learned/learnt - learned/learnt
830 leave - left - left
831 lend - lent - lent
832 let - let - let
833 lie - lay - lain
834 light - lit/lighted - lighted
835 lose - lost - lost
836 make - made - made
837 mean - meant - meant
838 meet - met - met
839 misspell - misspelled/misspelt - misspelled/misspelt
840 mistake - mistook - mistaken
841 mow - mowed - mowed/mown
842 overcome - overcame - overcome
843 overdo - overdid - overdone
844 overtake - overtook - overtaken
845 overthrow - overthrew - overthrown
846 pay - paid - paid
847 plead - pled - pled
848 prove - proved - proved/proven
849 put - put - put
850 quit - quit - quit
851 read - read - read
852 rid - rid - rid
853 ride - rode - ridden
854 ring - rang - rung
855 rise - rose - risen
856 run - ran - run
857 saw - sawed - sawed/sawn
858 say - said - said
859 see - saw - seen
860 seek - sought - sought
861 sell - sold - sold
862 send - sent - sent
863 set - set - set
864 sew - sewed - sewed/sewn
865 shake - shook - shaken
866 shave - shaved - shaved/shaven
867 shear - shore - shorn
868 shed - shed - shed
869 shine - shone - shone
870 shoe - shoed - shoed/shod
871 shoot - shot - shot
872 show - showed - showed/shown
873 shrink - shrank - shrunk
874 shut - shut - shut
875 sing - sang - sung
876 sink - sank - sunk
877 sit - sat - sat
878 sleep - slept - slept
879 slay - slew - slain
880 slide - slid - slid
881 sling - slung - slung
882 slit - slit - slit
883 smite - smote - smitten
884 sow - sowed - sowed/sown
885 speak - spoke - spoken
886 speed - sped - sped
887 spend - spent - spent
888 spill - spilled/spilt - spilled/spilt
889 spin - spun - spun
890 spit - spit/spat - spit
891 split - split - split
892 spread - spread - spread
893 spring - sprang/sprung - sprung
894 stand - stood - stood
895 steal - stole - stolen
896 stick - stuck - stuck
897 sting - stung - stung
898 stink - stank - stunk
899 stride - strod - stridden
900 strike - struck - struck
901 string - strung - strung
902 strive - strove - striven
903 swear - swore - sworn
904 sweep - swept - swept
905 swell - swelled - swelled/swollen
906 swim - swam - swum
907 swing - swung - swung
908 take - took - taken
909 teach - taught - taught
910 tear - tore - torn
911 tell - told - told
912 think - thought - thought
913 thrive - thrived/throve - thrived
914 throw - threw - thrown
915 thrust - thrust - thrust
916 tread - trod - trodden
917 understand - understood - understood
918 uphold - upheld - upheld
919 upset - upset - upset
920 wake - woke - woken
921 wear - wore - worn
922 weave - weaved/wove - weaved/woven
923 wed - wed - wed
924 weep - wept - wept
925 wind - wound - wound
926 win - won - won
927 withhold - withheld - withheld
928 withstand - withstood - withstood
929 wring - wrung - wrung
930 write - wrote - written
931 EOF
932  
933 }
934 2 ▶sub _no_double{
Subroutine _no_double: called CC=1 SCAR=0.0
935 2 return qw(
936 abandon accouter accredit adhibit administer alter anchor answer attrit audit
937 author ballot banner batten bedizen bespatter betoken bewilder billet blacken
938 blither blossom bother brighten broaden broider burden caparison catalog censor
939 center charter chatter cheapen chipper chirrup christen clobber cluster coarsen
940 cocker coedit cohabit concenter corner cover covet cower credit custom dampen
941 deafen decipher deflower delimit deposit develop differ disaccustom discover
942 discredit disencumber dishearten disinherit dismember dispirit dither dizen
943 dodder edit elicit embitter embolden embosom embower empoison empower enamor
944 encipher encounter endanger enfetter engender enlighten enter envelop envenom
945 environ exhibit exit fasten fatten feather fester filter flatten flatter
946 flounder fluster flutter foreshorten founder fritter gammon gather gladden
947 glimmer glisten glower greaten hamper hanker happen harden harken hasten
948 hearten hoarsen honor imprison inhabit inhibit inspirit interpret iron laten
949 launder lengthen liken limber limit linger litter liven loiter lollop louden
950 lower lumber madden malinger market matter misinterpret misremember monitor
951 moulder murder murmur muster number offer open order outmaneuver overmaster
952 pamper pilot pivot plaster plunder powder power prohibit reckon reconsider
953 recover redden redeliver register rejigger remember renumber reopen reposit
954 rewaken richen roister roughen sadden savor scatter scupper sharpen shatter
955 shelter shimmer shiver shorten shower sicken smolder smoothen soften solicit
956 squander stagger stiffen stopper stouten straiten strengthen stutter suffer
957 sugar summon surrender swelter sypher tamper tauten tender thicken threaten
958 thunder totter toughen tower transit tucker unburden uncover unfetter unloosen
959 upholster utter visit vomit wander water weaken whiten winter wonder worsen
960 );
961 }
↑ Summary