File Coverage

blib/lib/Lingua/EN/Inflexion/Indefinite.pm
Criterion Covered Total %
statement 26 26 100.0
branch 32 34 94.1
condition n/a
subroutine 4 4 100.0
pod 0 2 0.0
total 62 66 93.9


line stmt bran cond sub pod time code
1             package Lingua::EN::Inflexion::Indefinite;
2 24     24   553 use 5.010; use warnings;
  24     24   88  
  24         150  
  24         52  
  24         17686  
3              
4             # This module implements A/AN inflexion for nouns...
5              
6             # Special cases of A/AN...
7             my $ORDINAL_AN = qr{\A [aefhilmnorsx] -?th \Z}ix;
8             my $ORDINAL_A = qr{\A [bcdgjkpqtuvwyz] -?th \Z}ix;
9             my $EXPLICIT_AN = qr{\A (?: euler | hour(?!i) | heir | honest | hono )}ix;
10             my $SINGLE_AN = qr{\A [aefhilmnorsx] \Z}ix;
11             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             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             my $INITIAL_Y_AN = qr{\A y (?: b[lor] | cl[ea] | fere | gg | p[ios] | rou | tt)}xi;
31              
32             sub prepend_indefinite_article {
33 480     480 0 1271 my ($word) = @_;
34 480         1121 return select_indefinite_article($word) . " $word";
35             }
36              
37             sub select_indefinite_article {
38 480     480 0 1028 my ($word) = @_;
39              
40             # Handle ordinal forms...
41 480 100       3255 return "a" if $word =~ $ORDINAL_A;
42 424 100       2376 return "an" if $word =~ $ORDINAL_AN;
43              
44             # Handle special cases...
45 376 100       1832 return "an" if $word =~ $EXPLICIT_AN;
46 358 50       1478 return "an" if $word =~ $SINGLE_AN;
47 358 50       1445 return "a" if $word =~ $SINGLE_A;
48              
49             # Handle abbreviations...
50 358 100       2150 return "an" if $word =~ $ABBREV_AN;
51 342 100       1243 return "an" if $word =~ /\A [aefhilmnorsx][.-]/xi;
52 310 100       1128 return "a" if $word =~ /\A [a-z][.-]/xi;
53              
54             # Handle consonants
55              
56 288 100       1661 return "a" if $word =~ /\A [^aeiouy] /xi;
57              
58             # Handle special vowel-forms
59              
60 180 100       600 return "a" if $word =~ /\A e [uw] /xi;
61 168 100       500 return "a" if $word =~ /\A onc?e \b /xi;
62 164 100       724 return "a" if $word =~ /\A uni (?: [^nmd] | mo) /xi;
63 132 100       336 return "an" if $word =~ /\A ut[th] /xi;
64 130 100       554 return "a" if $word =~ /\A u [bcfhjkqrst] [aeiou] /xi;
65              
66             # Handle special capitals
67              
68 102 100       311 return "a" if $word =~ /\A U [NK] [AIEO]? /x;
69              
70             # Handle vowels
71              
72 98 100       1010 return "an" if $word =~ /\A [aeiou]/xi;
73              
74             # Handle Y... (before certain consonants implies (unnaturalized) "I.." sound)
75 20 100       213 return "an" if $word =~ $INITIAL_Y_AN;
76              
77             # Otherwise, guess "A"
78 10         107 return "a";
79             }
80              
81              
82             1; # Magic true value required at end of module
83             __END__