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   458 use 5.010; use warnings;
  24     24   76  
  24         133  
  24         42  
  24         13369  
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 478     478 0 1148 my ($word) = @_;
34 478         1109 return select_indefinite_article($word) . " $word";
35             }
36              
37             sub select_indefinite_article {
38 478     478 0 859 my ($word) = @_;
39              
40             # Handle ordinal forms...
41 478 100       3009 return "a" if $word =~ $ORDINAL_A;
42 422 100       2168 return "an" if $word =~ $ORDINAL_AN;
43              
44             # Handle special cases...
45 374 100       1717 return "an" if $word =~ $EXPLICIT_AN;
46 356 50       1380 return "an" if $word =~ $SINGLE_AN;
47 356 50       1289 return "a" if $word =~ $SINGLE_A;
48              
49             # Handle abbreviations...
50 356 100       1833 return "an" if $word =~ $ABBREV_AN;
51 340 100       1108 return "an" if $word =~ /\A [aefhilmnorsx][.-]/xi;
52 308 100       1034 return "a" if $word =~ /\A [a-z][.-]/xi;
53              
54             # Handle consonants
55              
56 286 100       1508 return "a" if $word =~ /\A [^aeiouy] /xi;
57              
58             # Handle special vowel-forms
59              
60 180 100       656 return "a" if $word =~ /\A e [uw] /xi;
61 168 100       427 return "a" if $word =~ /\A onc?e \b /xi;
62 164 100       598 return "a" if $word =~ /\A uni (?: [^nmd] | mo) /xi;
63 132 100       329 return "an" if $word =~ /\A ut[th] /xi;
64 130 100       468 return "a" if $word =~ /\A u [bcfhjkqrst] [aeiou] /xi;
65              
66             # Handle special capitals
67              
68 102 100       272 return "a" if $word =~ /\A U [NK] [AIEO]? /x;
69              
70             # Handle vowels
71              
72 98 100       877 return "an" if $word =~ /\A [aeiou]/xi;
73              
74             # Handle Y... (before certain consonants implies (unnaturalized) "I.." sound)
75 20 100       123 return "an" if $word =~ $INITIAL_Y_AN;
76              
77             # Otherwise, guess "A"
78 10         60 return "a";
79             }
80              
81              
82             1; # Magic true value required at end of module
83             __END__