Inflexion/Indefinite.pm

filter: Statementstmt 100% 34 / 34 Branchbran 94.1% 32 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 94.5% 70 / 74 CC 18 SCAR 27.5
CC
18
Cov
97%
select_indefinite_article
18.0
BEGIN
1.0
BEGIN
1.0
CRAP 15.6
« Inflexion/Nouns.pm ↑ Summary Inflexion.pm »
1 package Lingua::EN::Inflexion::Indefinite;
2 33 ▶use 5.010; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 # This module implements A/AN inflexion for nouns...
5  
6 # Special cases of A/AN...
7 33 my $ORDINAL_AN = qr{\A [aefhilmnorsx] -?th \Z}ix;
8 33 my $ORDINAL_A = qr{\A [bcdgjkpqtuvwyz] -?th \Z}ix;
9 33 my $EXPLICIT_AN = qr{\A (?: euler | hour(?!i) | heir | honest | hono )}ix;
10 33 my $SINGLE_AN = qr{\A [aefhilmnorsx] \Z}ix;
11 33 my $SINGLE_A = qr{\A [bcdgjkpqtuvwyz] \Z}ix;
12  
13 # This pattern matches strings of capitals (i.e. abbreviations) that
14 # start with a "vowel-sound" consonant followed by another consonant,
15 # and which are not likely to be real words
16 # (oh, all right then, it's just magic!)...
17  
18 33 my $ABBREV_AN = qr{
19 \A
20 (?! FJO | [HLMNS]Y. | RY[EO] | SQU
21 | ( F[LR]? | [HL] | MN? | N | RH? | S[CHKLMNPTVW]? | X(YL)?) [AEIOU]
22 )
23 [FHLMNRSX][A-Z]
24 }xms;
25  
26 # This pattern codes the beginnings of all english words begining with a
27 # 'Y' followed by a consonant. Any other Y-consonant prefix therefore
28 # implies an abbreviation...
29  
30 33 my $INITIAL_Y_AN = qr{\A y (?: b[lor] | cl[ea] | fere | gg | p[ios] | rou | tt)}xi;
31  
32 487 ▶sub prepend_indefinite_article {
Subroutine prepend_indefinite_article: called CC=1 SCAR=0.0
Pod undocumented
33 487 my ($word) = @_;
34 487 return select_indefinite_article($word) . " $word";
35 }
36  
37 487 ▶sub select_indefinite_article {
Subroutine select_indefinite_article: called CC=18 SCAR=28.9
Pod undocumented
38 487 my ($word) = @_;
39  
40 # Handle ordinal forms...
41 487 ▶ return "a" if $word =~ $ORDINAL_A;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /$ORDINAL_A/ 56 431 487
42 431 ▶ return "an" if $word =~ $ORDINAL_AN;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /$ORDINAL_AN/ 48 383 431
43  
44 # Handle special cases...
45 383 ▶ return "an" if $word =~ $EXPLICIT_AN;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /$EXPLICIT_AN/ 18 365 383
46 365 ▶ return "an" if $word =~ $SINGLE_AN;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /$SINGLE_AN/ 0 365 365
47 365 ▶ return "a" if $word =~ $SINGLE_A;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /$SINGLE_A/ 0 365 365
48  
49 # Handle abbreviations...
50 365 ▶ return "an" if $word =~ $ABBREV_AN;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /$ABBREV_AN/ 16 349 365
51 349 ▶ return "an" if $word =~ /\A [aefhilmnorsx][.-]/xi;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /\A [aefhilmnorsx][.-]/xi 32 317 349
52 317 ▶ return "a" if $word =~ /\A [a-z][.-]/xi;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /\A [a-z][.-]/xi 22 295 317
53  
54 # Handle consonants
55  
56 295 ▶ return "a" if $word =~ /\A [^aeiouy] /xi;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /\A [^aeiouy] /xi 111 184 295
57  
58 # Handle special vowel-forms
59  
60 184 ▶ return "a" if $word =~ /\A e [uw] /xi;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /\A e [uw] /xi 12 172 184
61 172 ▶ return "a" if $word =~ /\A onc?e \b /xi;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /\A onc?e \b /xi 4 168 172
62 168 ▶ return "a" if $word =~ /\A uni (?: [^nmd] | mo) /xi;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /\A uni (?: [^nmd] | mo) /xi 32 136 168
63 136 ▶ return "an" if $word =~ /\A ut[th] /xi;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /\A ut[th] /xi 2 134 136
64 134 ▶ return "a" if $word =~ /\A u [bcfhjkqrst] [aeiou] /xi;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /\A u [bcfhjkqrst] [aeiou] /xi 28 106 134
65  
66 # Handle special capitals
67  
68 106 ▶ return "a" if $word =~ /\A U [NK] [AIEO]? /x;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /\A U [NK] [AIEO]? /x 4 102 106
69  
70 # Handle vowels
71  
72 102 ▶ return "an" if $word =~ /\A [aeiou]/xi;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /\A [aeiou]/xi 82 20 102
73  
74 # Handle Y... (before certain consonants implies (unnaturalized) "I.." sound)
75 20 ▶ return "an" if $word =~ $INITIAL_Y_AN;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /$INITIAL_Y_AN/ 10 10 20
76  
77 # Otherwise, guess "A"
78 10 return "a";
79 }
80  
81  
82 33 1; # Magic true value required at end of module
83 __END__
« Inflexion/Nouns.pm ↑ Summary Inflexion.pm »