| 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 | sub prepend_indefinite_article { | ||||||||||
| 33 | 478 | ▶ | my ($word) = @_; | ||||||||
|
Subroutine
prepend_indefinite_article: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 34 | 478 | return select_indefinite_article($word) . " $word"; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | sub select_indefinite_article { | ||||||||||
| 38 | 478 | ▶ | my ($word) = @_; | ||||||||
|
Subroutine
select_indefinite_article: called CC=18 SCAR=28.9
Pod
undocumented
| |||||||||||
| 39 | |||||||||||
| 40 | # Handle ordinal forms... | ||||||||||
| 41 | 478 | ▶ | return "a" if $word =~ $ORDINAL_A; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 422 | ▶ | return "an" if $word =~ $ORDINAL_AN; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | # Handle special cases... | ||||||||||
| 45 | 374 | ▶ | return "an" if $word =~ $EXPLICIT_AN; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 356 | ▶ | return "an" if $word =~ $SINGLE_AN; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 356 | ▶ | return "a" if $word =~ $SINGLE_A; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | |||||||||||
| 49 | # Handle abbreviations... | ||||||||||
| 50 | 356 | ▶ | return "an" if $word =~ $ABBREV_AN; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 340 | ▶ | return "an" if $word =~ /\A [aefhilmnorsx][.-]/xi; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 308 | ▶ | return "a" if $word =~ /\A [a-z][.-]/xi; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | |||||||||||
| 54 | # Handle consonants | ||||||||||
| 55 | |||||||||||
| 56 | 286 | ▶ | return "a" if $word =~ /\A [^aeiouy] /xi; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | |||||||||||
| 58 | # Handle special vowel-forms | ||||||||||
| 59 | |||||||||||
| 60 | 180 | ▶ | return "a" if $word =~ /\A e [uw] /xi; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 168 | ▶ | return "a" if $word =~ /\A onc?e \b /xi; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 164 | ▶ | return "a" if $word =~ /\A uni (?: [^nmd] | mo) /xi; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 132 | ▶ | return "an" if $word =~ /\A ut[th] /xi; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 130 | ▶ | return "a" if $word =~ /\A u [bcfhjkqrst] [aeiou] /xi; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | |||||||||||
| 66 | # Handle special capitals | ||||||||||
| 67 | |||||||||||
| 68 | 102 | ▶ | return "a" if $word =~ /\A U [NK] [AIEO]? /x; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | |||||||||||
| 70 | # Handle vowels | ||||||||||
| 71 | |||||||||||
| 72 | 98 | ▶ | return "an" if $word =~ /\A [aeiou]/xi; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | |||||||||||
| 74 | # Handle Y... (before certain consonants implies (unnaturalized) "I.." sound) | ||||||||||
| 75 | 20 | ▶ | return "an" if $word =~ $INITIAL_Y_AN; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||