.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Lingua::EN::Inflect 3pm" .TH Lingua::EN::Inflect 3pm "2012-09-19" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Lingua::EN::Inflect \- Convert singular to plural. Select "a" or "an". .SH "VERSION" .IX Header "VERSION" This document describes version 1.895 of Lingua::EN::Inflect .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 8 \& use Lingua::EN::Inflect qw ( PL PL_N PL_V PL_ADJ NO NUM \& PL_eq PL_N_eq PL_V_eq PL_ADJ_eq \& A AN \& PART_PRES \& ORD NUMWORDS \& WORDLIST \& inflect classical \& def_noun def_verb def_adj def_a def_an ); \& \& \& # UNCONDITIONALLY FORM THE PLURAL \& \& print "The plural of ", $word, " is ", PL($word), "\en"; \& \& \& # CONDITIONALLY FORM THE PLURAL \& \& print "I saw $cat_count ", PL("cat",$cat_count), "\en"; \& \& \& # FORM PLURALS FOR SPECIFIC PARTS OF SPEECH \& \& print PL_N("I",$N1), PL_V("saw",$N1), \& PL_ADJ("my",$N2), PL_N("saw",$N2), "\en"; \& \& \& # DEAL WITH "0/1/N" \-> "no/1/N" TRANSLATION: \& \& print "There ", PL_V("was",$errors), NO(" error",$errors), "\en"; \& \& \& # USE DEFAULT COUNTS: \& \& print NUM($N1,""), PL("I"), PL_V(" saw"), NUM($N2), PL_N(" saw"); \& print "There ", NUM($errors,\*(Aq\*(Aq), PL_V("was"), NO(" error"), "\en"; \& \& \& # COMPARE TWO WORDS "NUMBER\-INSENSITIVELY": \& \& print "same\en" if PL_eq($word1, $word2); \& print "same noun\en" if PL_N_eq($word1, $word2); \& print "same verb\en" if PL_V_eq($word1, $word2); \& print "same adj.\en" if PL_ADJ_eq($word1, $word2); \& \& \& # ADD CORRECT "a" OR "an" FOR A GIVEN WORD: \& \& print "Did you want ", A($thing), " or ", AN($idea), "\en"; \& \& \& # CONVERT NUMERALS INTO ORDINALS (i.e. 1\->1st, 2\->2nd, 3\->3rd, etc.) \& \& print "It was", ORD($position), " from the left\en"; \& \& # CONVERT NUMERALS TO WORDS (i.e. 1\->"one", 101\->"one hundred and one", etc.) \& # IN A SCALAR CONTEXT: GET BACK A SINGLE STRING... \& \& $words = NUMWORDS(1234); # "one thousand, two hundred and thirty\-four" \& $words = NUMWORDS(ORD(1234)); # "one thousand, two hundred and thirty\-fourth" \& \& \& # IN A LIST CONTEXT: GET BACK A LIST OF STRINGSi, ONE FOR EACH "CHUNK"... \& \& @words = NUMWORDS(1234); # ("one thousand","two hundred and thirty\-four") \& \& \& # OPTIONAL PARAMETERS CHANGE TRANSLATION: \& \& $words = NUMWORDS(12345, group=>1); \& # "one, two, three, four, five" \& \& $words = NUMWORDS(12345, group=>2); \& # "twelve, thirty\-four, five" \& \& $words = NUMWORDS(12345, group=>3); \& # "one twenty\-three, forty\-five" \& \& $words = NUMWORDS(1234, \*(Aqand\*(Aq=>\*(Aq\*(Aq); \& # "one thousand, two hundred thirty\-four" \& \& $words = NUMWORDS(1234, \*(Aqand\*(Aq=>\*(Aq, plus\*(Aq); \& # "one thousand, two hundred, plus thirty\-four" \& \& $words = NUMWORDS(555_1202, group=>1, zero=>\*(Aqoh\*(Aq); \& # "five, five, five, one, two, oh, two" \& \& $words = NUMWORDS(555_1202, group=>1, one=>\*(Aqunity\*(Aq); \& # "five, five, five, unity, two, oh, two" \& \& $words = NUMWORDS(123.456, group=>1, decimal=>\*(Aqmark\*(Aq); \& # "one two three mark four five six" .Ve .PP # \s-1LITERAL\s0 \s-1STYLE\s0 \s-1ONLY\s0 \s-1NAMES\s0 \s-1NUMBERS\s0 \s-1LESS\s0 \s-1THAN\s0 A \s-1CERTAIN\s0 \s-1THRESHOLD\s0... .PP .Vb 4 \& $words = NUMWORDS( 9, threshold=>10); # "nine" \& $words = NUMWORDS( 10, threshold=>10); # "ten" \& $words = NUMWORDS( 11, threshold=>10); # "11" \& $words = NUMWORDS(1000, threshold=>10); # "1,000" \& \& # JOIN WORDS INTO A LIST: \& \& $list = WORDLIST("apple", "banana", "carrot"); \& # "apple, banana, and carrot" \& \& $list = WORDLIST("apple", "banana"); \& # "apple and banana" \& \& $list = WORDLIST("apple", "banana", "carrot", {final_sep=>""}); \& # "apple, banana and carrot" \& \& \& # REQUIRE "CLASSICAL" PLURALS (EG: "focus"\->"foci", "cherub"\->"cherubim") \& \& classical; # USE ALL CLASSICAL PLURALS \& \& classical 1; # USE ALL CLASSICAL PLURALS \& classical 0; # USE ALL MODERN PLURALS (DEFAULT) \& \& classical \*(Aqzero\*(Aq; # "no error" INSTEAD OF "no errors" \& classical zero=>1; # "no error" INSTEAD OF "no errors" \& classical zero=>0; # "no errors" INSTEAD OF "no error" \& \& classical \*(Aqherd\*(Aq; # "2 buffalo" INSTEAD OF "2 buffalos" \& classical herd=>1; # "2 buffalo" INSTEAD OF "2 buffalos" \& classical herd=>0; # "2 buffalos" INSTEAD OF "2 buffalo" \& \& classical \*(Aqpersons\*(Aq; # "2 chairpersons" INSTEAD OF "2 chairpeople" \& classical persons=>1; # "2 chairpersons" INSTEAD OF "2 chairpeople" \& classical persons=>0; # "2 chairpeople" INSTEAD OF "2 chairpersons" \& \& classical \*(Aqancient\*(Aq; # "2 formulae" INSTEAD OF "2 formulas" \& classical ancient=>1; # "2 formulae" INSTEAD OF "2 formulas" \& classical ancient=>0; # "2 formulas" INSTEAD OF "2 formulae" \& \& \& \& # INTERPOLATE "PL()", "PL_N()", "PL_V()", "PL_ADJ()", A()", "AN()" \& # "NUM()" AND "ORD()" WITHIN STRINGS: \& \& print inflect("The plural of $word is PL($word)\en"); \& print inflect("I saw $cat_count PL("cat",$cat_count)\en"); \& print inflect("PL(I,$N1) PL_V(saw,$N1) PL(a,$N2) PL_N(saw,$N2)"); \& print inflect("NUM($N1,)PL(I) PL_V(saw) NUM($N2,)PL(a) PL_N(saw)"); \& print inflect("I saw NUM($cat_count) PL("cat")\enNUM()"); \& print inflect("There PL_V(was,$errors) NO(error,$errors)\en"); \& print inflect("There NUM($errors,) PL_V(was) NO(error)\en"; \& print inflect("Did you want A($thing) or AN($idea)\en"); \& print inflect("It was ORD($position) from the left\en"); \& \& \& # ADD USER\-DEFINED INFLECTIONS (OVERRIDING INBUILT RULES): \& \& def_noun "VAX" => "VAXen"; # SINGULAR => PLURAL \& \& def_verb "will" => "shall", # 1ST PERSON SINGULAR => PLURAL \& "will" => "will", # 2ND PERSON SINGULAR => PLURAL \& "will" => "will", # 3RD PERSON SINGULAR => PLURAL \& \& def_adj "hir" => "their", # SINGULAR => PLURAL \& \& def_a "h" # "AY HALWAYS SEZ \*(AqHAITCH\*(Aq!" \& \& def_an "horrendous.*" # "AN HORRENDOUS AFFECTATION" .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The exportable subroutines of Lingua::EN::Inflect provide plural inflections, \*(L"a\*(R"/\*(L"an\*(R" selection for English words, and manipulation of numbers as words .PP Plural forms of all nouns, most verbs, and some adjectives are provided. Where appropriate, \*(L"classical\*(R" variants (for example: \*(L"brother\*(R" \-> \&\*(L"brethren\*(R", \*(L"dogma\*(R" \-> \*(L"dogmata\*(R", etc.) are also provided. .PP Pronunciation-based \*(L"a\*(R"/\*(L"an\*(R" selection is provided for all English words, and most initialisms. .PP It is also possible to inflect numerals (1,2,3) to ordinals (1st, 2nd, 3rd) and to English words (\*(L"one\*(R", \*(L"two\*(R", "three). .PP In generating these inflections, Lingua::EN::Inflect follows the Oxford English Dictionary and the guidelines in Fowler's Modern English Usage, preferring the former where the two disagree. .PP The module is built around standard British spelling, but is designed to cope with common American variants as well. Slang, jargon, and other English dialects are \fInot\fR explicitly catered for. .PP Where two or more inflected forms exist for a single word (typically a \&\*(L"classical\*(R" form and a \*(L"modern\*(R" form), Lingua::EN::Inflect prefers the more common form (typically the \*(L"modern\*(R" one), unless \*(L"classical\*(R" processing has been specified (see \*(L"\s-1MODERN\s0 \s-1VS\s0 \s-1CLASSICAL\s0 \s-1INFLECTIONS\s0\*(R"). .SH "FORMING PLURALS" .IX Header "FORMING PLURALS" .SS "Inflecting Plurals" .IX Subsection "Inflecting Plurals" All of the \f(CW\*(C`PL_...\*(C'\fR plural inflection subroutines take the word to be inflected as their first argument and return the corresponding inflection. Note that all such subroutines expect the \fIsingular\fR form of the word. The results of passing a plural form are undefined (and unlikely to be correct). .PP The \f(CW\*(C`PL_...\*(C'\fR subroutines also take an optional second argument, which indicates the grammatical \*(L"number\*(R" of the word (or of another word with which the word being inflected must agree). If the \*(L"number\*(R" argument is supplied and is not \f(CW1\fR (or \f(CW"one"\fR or \f(CW"a"\fR, or some other adjective that implies the singular), the plural form of the word is returned. If the \&\*(L"number\*(R" argument \fIdoes\fR indicate singularity, the (uninflected) word itself is returned. If the number argument is omitted, the plural form is returned unconditionally. .PP The various subroutines are: .ie n .IP """PL_N($;$)""" 8 .el .IP "\f(CWPL_N($;$)\fR" 8 .IX Item "PL_N($;$)" The exportable subroutine \f(CW\*(C`PL_N()\*(C'\fR takes a \fIsingular\fR English noun or pronoun and returns its plural. Pronouns in the nominative (\*(L"I\*(R" \-> \&\*(L"we\*(R") and accusative (\*(L"me\*(R" \-> \*(L"us\*(R") cases are handled, as are possessive pronouns (\*(L"mine\*(R" \-> \*(L"ours\*(R"). .ie n .IP """PL_V($;$)""" 8 .el .IP "\f(CWPL_V($;$)\fR" 8 .IX Item "PL_V($;$)" The exportable subroutine \f(CW\*(C`PL_V()\*(C'\fR takes the \fIsingular\fR form of a conjugated verb (that is, one which is already in the correct \*(L"person\*(R" and \*(L"mood\*(R") and returns the corresponding plural conjugation. .ie n .IP """PL_ADJ($;$)""" 8 .el .IP "\f(CWPL_ADJ($;$)\fR" 8 .IX Item "PL_ADJ($;$)" The exportable subroutine \f(CW\*(C`PL_ADJ()\*(C'\fR takes the \fIsingular\fR form of certain types of adjectives and returns the corresponding plural form. Adjectives that are correctly handled include: \*(L"numerical\*(R" adjectives (\*(L"a\*(R" \-> \*(L"some\*(R"), demonstrative adjectives (\*(L"this\*(R" \-> \*(L"these\*(R", \*(L"that\*(R" \-> \&\*(L"those\*(R"), and possessives (\*(L"my\*(R" \-> \*(L"our\*(R", \*(L"cat's\*(R" \-> \*(L"cats'\*(R", \*(L"child's\*(R" \&\-> \*(L"childrens'\*(R", etc.) .ie n .IP """PL($;$)""" 8 .el .IP "\f(CWPL($;$)\fR" 8 .IX Item "PL($;$)" The exportable subroutine \f(CW\*(C`PL()\*(C'\fR takes a \fIsingular\fR English noun, pronoun, verb, or adjective and returns its plural form. Where a word has more than one inflection depending on its part of speech (for example, the noun \*(L"thought\*(R" inflects to \*(L"thoughts\*(R", the verb \*(L"thought\*(R" to \*(L"thought\*(R"), the (singular) noun sense is preferred to the (singular) verb sense. .Sp Hence \f(CW\*(C`PL("knife")\*(C'\fR will return \*(L"knives\*(R" (\*(L"knife\*(R" having been treated as a singular noun), whereas \f(CW\*(C`PL("knifes")\*(C'\fR will return \*(L"knife\*(R" (\*(L"knifes\*(R" having been treated as a 3rd person singular verb). .Sp The inherent ambiguity of such cases suggests that, where the part of speech is known, \f(CW\*(C`PL_N\*(C'\fR, \f(CW\*(C`PL_V\*(C'\fR, and \&\f(CW\*(C`PL_ADJ\*(C'\fR should be used in preference to \f(CW\*(C`PL\*(C'\fR. .PP Note that all these subroutines ignore any whitespace surrounding the word being inflected, but preserve that whitespace when the result is returned. For example, \f(CW\*(C`PL("\ cat\ \ ")\*(C'\fR returns \*(L"\ cats\ \ \*(R". .SS "Numbered plurals" .IX Subsection "Numbered plurals" The \f(CW\*(C`PL_...\*(C'\fR subroutines return only the inflected word, not the count that was used to inflect it. Thus, in order to produce \*(L"I saw 3 ducks\*(R", it is necessary to use: .PP .Vb 1 \& print "I saw $N ", PL_N($animal,$N), "\en"; .Ve .PP Since the usual purpose of producing a plural is to make it agree with a preceding count, Lingua::EN::Inflect provides an exportable subroutine (\f(CW\*(C`NO($;$)\*(C'\fR) which, given a word and a(n optional) count, returns the count followed by the correctly inflected word. Hence the previous example can be rewritten: .PP .Vb 1 \& print "I saw ", NO($animal,$N), "\en"; .Ve .PP In addition, if the count is zero (or some other term which implies zero, such as \f(CW"zero"\fR, \f(CW"nil"\fR, etc.) the count is replaced by the word \*(L"no\*(R". Hence, if \f(CW$N\fR had the value zero, the previous example would print the somewhat more elegant: .PP .Vb 1 \& I saw no animals .Ve .PP rather than: .PP .Vb 1 \& I saw 0 animals .Ve .PP Note that the name of the subroutine is a pun: the subroutine returns either a number (a \fINo.\fR) or a \f(CW"no"\fR, in front of the inflected word. .PP \fIWordy and comma'd plurals\fR .IX Subsection "Wordy and comma'd plurals" .PP The \f(CW\*(C`NO()\*(C'\fR subroutine takes an optional third argument: a hash of named options that configure its behaviour. .PP The \f(CW\*(Aqwords_below\*(Aq\fR option informs \f(CW\*(C`NO()\*(C'\fR what other numbers (i.e. apart from zero) it should convert to words. For example:S .PP .Vb 3 \& for my $count (0..12) { \& print NO(\*(Aqcat\*(Aq, $count, {words_below => 10}), "\en"; \& } .Ve .PP would print: .PP .Vb 10 \& no cats \& one cat \& two cats \& three cats \& four cats \& five cats \& six cats \& seven cats \& eight cats \& nine cats \& 10 cats \& 11 cats \& 12 cats .Ve .PP The \f(CW\*(Aqcomma\*(Aq\fR and \f(CW\*(Aqcomma_every\*(Aq\fR options determine whether or not the numbers produced by \f(CW\*(C`NO()\*(C'\fR have commas in them. That is: .PP .Vb 1 \& 2001 space odysseys .Ve .PP versus: .PP .Vb 1 \& 2,001 space odysseys .Ve .PP Normally, numbers are produced without commas, but if \f(CW\*(Aqcomma\*(Aq\fR or \&\f(CW\*(Aqcomma_every\*(Aq\fR is specified, then commas are added as requested. .PP The \f(CW\*(Aqcomma\*(Aq\fR option specifies which character to use as a comma. It defaults to \f(CW\*(Aq,\*(Aq\fR, but may be set to anything convenient: .PP .Vb 1 \& print NO(\*(AqEuro\*(Aq, $amount, {comma=>\*(Aq.\*(Aq}); \& \& # prints: 1.000.000 Euros .Ve .PP The \f(CW\*(Aqcomma_every\*(Aq\fR option specifies how many characters between commas. It defaults to 3, but may be set to any positive number: .PP .Vb 1 \& print NO(\*(AqEuro\*(Aq, $amount, {comma_every=>4}); \& \& # prints: 100,0000 Euros .Ve .PP Note that you can set both options at once, if you wish: .PP .Vb 1 \& print NO(\*(AqEuro\*(Aq, $amount, {comma_every=>2, comma=>\*(Aq_\*(Aq}); \& \& # prints: 1_00_00_00 Euros .Ve .SS "Reducing the number of counts required" .IX Subsection "Reducing the number of counts required" In some contexts, the need to supply an explicit count to the various \&\f(CW\*(C`PL_...\*(C'\fR subroutines makes for tiresome repetition. For example: .PP .Vb 2 \& print PL_ADJ("This",$errors), PL_N(" error",$errors), \& PL_V(" was",$errors), " fatal.\en"; .Ve .PP Lingua::EN::Inflect therefore provides an exportable subroutine (\f(CW\*(C`NUM($;$)\*(C'\fR) which may be used to set a persistent \*(L"default number\*(R" value. If such a value is set, it is subsequently used whenever an optional second \*(L"number\*(R" argument is omitted. The default value thus set can subsequently be removed by calling \f(CW\*(C`NUM()\*(C'\fR with no arguments. Hence we could rewrite the previous example: .PP .Vb 3 \& NUM($errors); \& print PL_ADJ("This"), PL_N(" error"), PL_V(" was"), "fatal.\en"; \& NUM(); .Ve .PP Normally, \f(CW\*(C`NUM()\*(C'\fR returns its first argument, so that it may also be \*(L"inlined\*(R" in contexts like: .PP .Vb 3 \& print NUM($errors), PL_N(" error"), PL_V(" was"), " detected.\en" \& print PL_ADJ("This"), PL_N(" error"), PL_V(" was"), "fatal.\en" \& if $severity > 1; .Ve .PP However, in certain contexts (see \*(L"\s-1INTERPOLATING\s0 \s-1INFLECTIONS\s0 \s-1IN\s0 \s-1STRINGS\s0\*(R") it is preferable that \f(CW\*(C`NUM()\*(C'\fR return an empty string. Hence \f(CW\*(C`NUM()\*(C'\fR provides an optional second argument. If that argument is supplied (that is, if it is defined) and evaluates to false, \f(CW\*(C`NUM\*(C'\fR returns an empty string instead of its first argument. For example: .PP .Vb 3 \& print NUM($errors,0), NO("error"), PL_V(" was"), " detected.\en"; \& print PL_ADJ("This"), PL_N(" error"), PL_V(" was"), "fatal.\en" \& if $severity > 1; .Ve .SS "Number-insensitive equality" .IX Subsection "Number-insensitive equality" Lingua::EN::Inflect also provides a solution to the problem of comparing words of differing plurality through the exportable subroutines \&\f(CW\*(C`PL_eq($$)\*(C'\fR, \f(CW\*(C`PL_N_eq($$)\*(C'\fR, \f(CW\*(C`PL_V_eq($$)\*(C'\fR, and \f(CW\*(C`PL_ADJ_eq($$)\*(C'\fR. Each of these subroutines takes two strings, and compares them using the corresponding plural-inflection subroutine (\f(CW\*(C`PL()\*(C'\fR, \f(CW\*(C`PL_N()\*(C'\fR, \&\f(CW\*(C`PL_V()\*(C'\fR, and \f(CW\*(C`PL_ADJ()\*(C'\fR respectively). .PP The comparison returns true if: .IP "\(bu" 8 the strings are \f(CW\*(C`eq\*(C'\fR\-equal, or .IP "\(bu" 8 one string is \f(CW\*(C`eq\*(C'\fR\-equal to a plural form of the other, or .IP "\(bu" 8 the strings are two different plural forms of the one word. .PP Hence all of the following return true: .PP .Vb 8 \& PL_eq("index","index") # RETURNS "eq" \& PL_eq("index","indexes") # RETURNS "s:p" \& PL_eq("index","indices") # RETURNS "s:p" \& PL_eq("indexes","index") # RETURNS "p:s" \& PL_eq("indices","index") # RETURNS "p:s" \& PL_eq("indices","indexes") # RETURNS "p:p" \& PL_eq("indexes","indices") # RETURNS "p:p" \& PL_eq("indices","indices") # RETURNS "eq" .Ve .PP As indicated by the comments in the previous example, the actual value returned by the various \f(CW\*(C`PL_eq\*(C'\fR subroutines encodes which of the three equality rules succeeded: \*(L"eq\*(R" is returned if the strings were identical, \*(L"s:p\*(R" if the strings were singular and plural respectively, \&\*(L"p:s\*(R" for plural and singular, and \*(L"p:p\*(R" for two distinct plurals. Inequality is indicated by returning an empty string. .PP It should be noted that two distinct singular words which happen to take the same plural form are \fInot\fR considered equal, nor are cases where one (singular) word's plural is the other (plural) word's singular. Hence all of the following return false: .PP .Vb 3 \& PL_eq("base","basis") # ALTHOUGH BOTH \-> "bases" \& PL_eq("syrinx","syringe") # ALTHOUGH BOTH \-> "syringes" \& PL_eq("she","he") # ALTHOUGH BOTH \-> "they" \& \& PL_eq("opus","operas") # ALTHOUGH "opus" \-> "opera" \-> "operas" \& PL_eq("taxi","taxes") # ALTHOUGH "taxi" \-> "taxis" \-> "taxes" .Ve .PP Note too that, although the comparison is \*(L"number-insensitive\*(R" it is \fInot\fR case-insensitive (that is, \f(CW\*(C`PL("time","Times")\*(C'\fR returns false. To obtain both number and case insensitivity, prefix both arguments with \f(CW\*(C`lc\*(C'\fR (that is, \f(CW\*(C`PL(lc "time", lc "Times")\*(C'\fR returns true). .SH "OTHER VERB FORMS" .IX Header "OTHER VERB FORMS" .SS "Present participles" .IX Subsection "Present participles" \&\f(CW\*(C`Lingua::EN::Inflect\*(C'\fR also provides the \f(CW\*(C`PART_PRES\*(C'\fR subroutine, which can take a 3rd person singular verb and correctly inflect it to its present participle: .PP .Vb 5 \& PART_PRES("runs") # "running" \& PART_PRES("loves") # "loving" \& PART_PRES("eats") # "eating" \& PART_PRES("bats") # "batting" \& PART_PRES("spies") # "spying" .Ve .SH "PROVIDING INDEFINITE ARTICLES" .IX Header "PROVIDING INDEFINITE ARTICLES" .SS "Selecting indefinite articles" .IX Subsection "Selecting indefinite articles" Lingua::EN::Inflect provides two exportable subroutines (\f(CW\*(C`A($;$)\*(C'\fR and \&\f(CW\*(C`AN($;$)\*(C'\fR) which will correctly prepend the appropriate indefinite article to a word, depending on its pronunciation. For example: .PP .Vb 6 \& A("cat") # \-> "a cat" \& AN("cat") # \-> "a cat" \& A("euphemism") # \-> "a euphemism" \& A("Euler number") # \-> "an Euler number" \& A("hour") # \-> "an hour" \& A("houri") # \-> "a houri" .Ve .PP The two subroutines are \fIidentical\fR in function and may be used interchangeably. The only reason that two versions are provided is to enhance the readability of code such as: .PP .Vb 2 \& print "That is ", AN($errortype), " error\en; \& print "That is ", A($fataltype), " fatal error\en; .Ve .PP Note that in both cases the actual article provided depends \fIonly\fR on the pronunciation of the first argument, \fInot\fR on the name of the subroutine. .PP \&\f(CW\*(C`A()\*(C'\fR and \f(CW\*(C`AN()\*(C'\fR will ignore any indefinite article that already exists at the start of the string. Thus: .PP .Vb 6 \& @half_arked = ( \& "a elephant", \& "a giraffe", \& "an ewe", \& "a orangutan", \& ); \& \& print A($_), "\en" for @half_arked; \& \& # prints: \& # an elephant \& # a giraffe \& # a ewe \& # an orangutan .Ve .PP \&\f(CW\*(C`A()\*(C'\fR and \f(CW\*(C`AN()\*(C'\fR both take an optional second argument. As with the \&\f(CW\*(C`PL_...\*(C'\fR subroutines, this second argument is a \*(L"number\*(R" specifier. If its value is \f(CW1\fR (or some other value implying singularity), \f(CW\*(C`A()\*(C'\fR and \&\f(CW\*(C`AN()\*(C'\fR insert \*(L"a\*(R" or \*(L"an\*(R" as appropriate. If the number specifier implies plurality, (\f(CW\*(C`A()\*(C'\fR and \f(CW\*(C`AN()\*(C'\fR insert the actual second argument instead. For example: .PP .Vb 4 \& A("cat",1) # \-> "a cat" \& A("cat",2) # \-> "2 cat" \& A("cat","one") # \-> "one cat" \& A("cat","no") # \-> "no cat" .Ve .PP Note that, as implied by the previous examples, \f(CW\*(C`A()\*(C'\fR and \&\f(CW\*(C`AN()\*(C'\fR both assume that their job is merely to provide the correct qualifier for a word (that is: \*(L"a\*(R", \*(L"an\*(R", or the specified count). In other words, they assume that the word they are given has already been correctly inflected for plurality. Hence, if \f(CW$N\fR has the value 2, then: .PP .Vb 1 \& print A("cat",$N); .Ve .PP prints \*(L"2 cat\*(R", instead of \*(L"2 cats\*(R". The correct approach is to use: .PP .Vb 1 \& print A(PL("cat",$N),$N); .Ve .PP or, better still: .PP .Vb 1 \& print NO("cat",$N); .Ve .PP Note too that, like the various \f(CW\*(C`PL_...\*(C'\fR subroutines, whenever \f(CW\*(C`A()\*(C'\fR and \f(CW\*(C`AN()\*(C'\fR are called with only one argument they are subject to the effects of any preceding call to \f(CW\*(C`NUM()\*(C'\fR. Hence, another possible solution is: .PP .Vb 2 \& NUM($N); \& print A(PL("cat")); .Ve .SS "Indefinite articles and initialisms" .IX Subsection "Indefinite articles and initialisms" \&\*(L"Initialisms\*(R" (sometimes inaccurately called \*(L"acronyms\*(R") are terms which have been formed from the initial letters of words in a phrase (for example, \*(L"\s-1NATO\s0\*(R", \*(L"\s-1NBL\s0\*(R", \*(L"S.O.S.\*(R", \*(L"\s-1SCUBA\s0\*(R", etc.) .PP Such terms present a particular challenge when selecting between \*(L"a\*(R" and \*(L"an\*(R", since they are sometimes pronounced as if they were a single word (\*(L"nay-tow\*(R", \*(L"sku-ba\*(R") and sometimes as a series of letter names (\*(L"en-eff-ell\*(R", \*(L"ess-oh-ess\*(R"). .PP \&\f(CW\*(C`A()\*(C'\fR and \f(CW\*(C`AN()\*(C'\fR cope with this dichotomy using a series of inbuilt rules, which may be summarized as: .IP "1." 8 If the word starts with a single letter, followed by a period or dash (for example, \*(L"R.I.P.\*(R", \*(L"C.O.D.\*(R", \*(L"e\-mail\*(R", \*(L"X\-ray\*(R", \*(L"T\-square\*(R"), then choose the appropriate article for the \fIsound\fR of the first letter (\*(L"an R.I.P.\*(R", \*(L"a C.O.D.\*(R", \*(L"an e\-mail\*(R", \*(L"an X\-ray\*(R", \*(L"a T\-square\*(R"). .IP "2." 8 If the first two letters of the word are capitals, consonants, and do not appear at the start of any known English word, (for example, \*(L"\s-1LCD\s0\*(R", \*(L"\s-1XML\s0\*(R", \*(L"\s-1YWCA\s0\*(R"), then once again choose \*(L"a\*(R" or \&\*(L"an\*(R" depending on the \fIsound\fR of the first letter (\*(L"an \s-1LCD\s0\*(R", \*(L"an \&\s-1XML\s0\*(R", \*(L"a \s-1YWCA\s0\*(R"). .IP "3." 8 Otherwise, assume the string is a capitalized word or a pronounceable initialism (for example, \*(L"\s-1LED\s0\*(R", \*(L"\s-1OPEC\s0\*(R", \*(L"\s-1FAQ\s0\*(R", \*(L"\s-1UNESCO\s0\*(R"), and therefore takes \*(L"a\*(R" or \*(L"an\*(R" according to the (apparent) pronunciation of the entire word (\*(L"a \s-1LED\s0\*(R", \*(L"an \s-1OPEC\s0\*(R", \*(L"a \s-1FAQ\s0\*(R", \*(L"a \s-1UNESCO\s0\*(R"). .PP Note that rules 1 and 3 together imply that the presence or absence of punctuation may change the selection of indefinite article for a particular initialism (for example, \*(L"a \s-1FAQ\s0\*(R" but \*(L"an F.A.Q.\*(R"). .ie n .SS "Indefinite articles and ""soft H's""" .el .SS "Indefinite articles and ``soft H's''" .IX Subsection "Indefinite articles and soft H's" Words beginning in the letter 'H' present another type of difficulty when selecting a suitable indefinite article. In a few such words (for example, \*(L"hour\*(R", \*(L"honour\*(R", \*(L"heir\*(R") the 'H' is not voiced at all, and so such words inflect with \*(L"an\*(R". The remaining cases (\*(L"voiced H's\*(R") may be divided into two categories: \&\*(L"hard H's\*(R" (such as \*(L"hangman\*(R", \*(L"holograph\*(R", \*(L"hat\*(R", etc.) and \&\*(L"soft H's\*(R" (such as \*(L"hysterical\*(R", \*(L"horrendous\*(R", \*(L"holy\*(R", etc.) .PP Hard H's always take \*(L"a\*(R" as their indefinite article, and soft H's normally do so as well. But \fIsome\fR English speakers prefer \&\*(L"an\*(R" for soft H's (although the practice is now generally considered an affectation, rather than a legitimate grammatical alternative). .PP At present, the \f(CW\*(C`A()\*(C'\fR and \f(CW\*(C`AN()\*(C'\fR subroutines ignore soft H's and use \&\*(L"a\*(R" for any voiced 'H'. The author would, however, welcome feedback on this decision (envisaging a possible future \*(L"soft H\*(R" mode). .SH "INFLECTING ORDINALS" .IX Header "INFLECTING ORDINALS" Occasionally it is useful to present an integer value as an ordinal rather than as a numeral. For example: .PP .Vb 4 \& Enter password (1st attempt): ******** \& Enter password (2nd attempt): ********* \& Enter password (3rd attempt): ********* \& No 4th attempt. Access denied. .Ve .PP To this end, Lingua::EN::Inflect provides the \f(CW\*(C`ORD()\*(C'\fR subroutine. <\s-1\fIORD\s0()\fR> takes a single argument and forms its ordinal equivalent. If the argument isn't a numerical integer, it just adds \*(L"\-th\*(R". .SH "CONVERTING NUMBERS TO WORDS" .IX Header "CONVERTING NUMBERS TO WORDS" The exportable subroutine \f(CW\*(C`NUMWORDS\*(C'\fR takes a number (cardinal or ordinal) and returns an English representation of that number. In a scalar context a string is returned. Hence: .PP .Vb 1 \& use Lingua::EN::Inflect qw( NUMWORDS ); \& \& $words = NUMWORDS(1234567); .Ve .PP puts the string: .PP .Vb 1 \& "one million, two hundred and thirty\-four thousand, five hundred and sixty\-seven" .Ve .PP into \f(CW$words\fR. .PP In a list context each comma-separated chunk is returned as a separate element. Hence: .PP .Vb 1 \& @words = NUMWORDS(1234567); .Ve .PP puts the list: .PP .Vb 3 \& ("one million", \& "two hundred and thirty\-four thousand", \& "five hundred and sixty\-seven") .Ve .PP into \f(CW@words\fR. .PP Non-digits (apart from an optional leading plus or minus sign, any decimal points, and ordinal suffixes \*(-- see below) are silently ignored, so the following all produce identical results: .PP .Vb 4 \& NUMWORDS(5551202); \& NUMWORDS(5_551_202); \& NUMWORDS("5,551,202"); \& NUMWORDS("555\-1202"); .Ve .PP That last case is a little awkward since it's almost certainly a phone number, and \*(L"five million, five hundred and fifty-one thousand, two hundred and two\*(R" probably isn't what's wanted. .PP To overcome this, \f(CW\*(C`NUMWORDS()\*(C'\fR takes an optional named argument, 'group', which changes how numbers are translated. The argument must be a positive integer less than four, which indicated how the digits of the number are to be grouped. If the argument is \f(CW1\fR, then each digit is translated separately. If the argument is \f(CW2\fR, pairs of digits (starting from the \fIleft\fR) are grouped together. If the argument is \&\f(CW3\fR, triples of numbers (again, from the \fIleft\fR) are grouped. Hence: .PP .Vb 1 \& NUMWORDS("555\-1202", group=>1) .Ve .PP returns \f(CW"five, five, five, one, two, zero, two"\fR, whilst: .PP .Vb 1 \& NUMWORDS("555\-1202", group=>2) .Ve .PP returns \f(CW"fifty\-five, fifty\-one, twenty, two"\fR, and: .PP .Vb 1 \& NUMWORDS("555\-1202", group=>3) .Ve .PP returns \f(CW"five fifty\-five, one twenty, two"\fR. .PP Phone numbers are often written in words as \&\f(CW"five..five..five..one..two..zero..two"\fR, which is also easy to achieve: .PP .Vb 1 \& join \*(Aq..\*(Aq, NUMWORDS("555\-1202", group=>1) .Ve .PP \&\f(CW\*(C`NUMWORDS\*(C'\fR also handles decimal fractions. Hence: .PP .Vb 1 \& NUMWORDS("1.2345") .Ve .PP returns \f(CW"one point two three four five"\fR in a scalar context and \f(CW\*(C`("one","point","two","three","four","five")\*(C'\fR) in an array context. Exponent form (\f(CW"1.234e56"\fR) is not yet handled. .PP Multiple decimal points are only translated in one of the \*(L"grouping\*(R" modes. Hence: .PP .Vb 1 \& NUMWORDS(101.202.303) .Ve .PP returns \f(CW"one hundred and one point two zero two three zero three"\fR, whereas: .PP .Vb 1 \& NUMWORDS(101.202.303, group=>1) .Ve .PP returns \f(CW"one zero one point two zero two point three zero three"\fR. .PP The digit \f(CW\*(Aq0\*(Aq\fR is unusual in that in may be translated to English as \*(L"zero\*(R", \&\*(L"oh\*(R", or \*(L"nought\*(R". To cater for this diversity, \f(CW\*(C`NUMWORDS\*(C'\fR may be passed a named argument, 'zero', which may be set to the desired translation of \f(CW\*(Aq0\*(Aq\fR. For example: .PP .Vb 1 \& print join "..", NUMWORDS("555\-1202", group=>3, zero=>\*(Aqoh\*(Aq) .Ve .PP prints \f(CW"five..five..five..one..two..oh..two"\fR. By default, zero is rendered as \*(L"zero\*(R". .PP Likewise, the digit \f(CW\*(Aq1\*(Aq\fR may be rendered as \*(L"one\*(R" or \*(L"a/an\*(R" (or very occasionally other variants), depending on the context. So there is a \&\f(CW\*(Aqone\*(Aq\fR argument as well: .PP .Vb 3 \& print NUMWORDS($_, one=>\*(Aqa solitary\*(Aq, zero=>\*(Aqno more\*(Aq), \& PL(" bottle of beer on the wall\en", $_) \& for (3,2,1,0); \& \& # prints: \& # three bottles of beer on the wall \& # two bottles of beer on the wall \& # a solitary bottle of beer on the wall \& # no more bottles of beer on the wall .Ve .PP Care is needed if the word \*(L"a/an\*(R" is to be used as a \f(CW\*(Aqone\*(Aq\fR value. Unless the next word is known in advance, it's almost always necessary to use the \f(CW\*(C`A\*(C'\fR function as well: .PP .Vb 2 \& print A( NUMWORDS(1, one=>\*(Aqa\*(Aq) . " $_\en") \& for qw(cat aardvark ewe hour); \& \& # prints: \& # a cat \& # an aardvark \& # a ewe \& # an hour .Ve .PP Another major regional variation in number translation is the use of \&\*(L"and\*(R" in certain contexts. The named argument 'and' allows the programmer to specify how \*(L"and\*(R" should be handled. Hence: .PP .Vb 1 \& print scalar NUMWORDS("765", \*(Aqand\*(Aq=>\*(Aq\*(Aq) .Ve .PP prints \*(L"seven hundred sixty-five\*(R", instead of \*(L"seven hundred and sixty-five\*(R". By default, the \*(L"and\*(R" is included. .PP The translation of the decimal point is also subject to variation (with \*(L"point\*(R", \*(L"dot\*(R", and \*(L"decimal\*(R" being the favorites). The named argument 'decimal' allows the programmer to how the decimal point should be rendered. Hence: .PP .Vb 1 \& print scalar NUMWORDS("666.124.64.101", group=>3, decimal=>\*(Aqdot\*(Aq) .Ve .PP prints \*(L"six sixty-six, dot, one twenty-four, dot, sixty-four, dot, one zero one\*(R" By default, the decimal point is rendered as \*(L"point\*(R". .PP \&\f(CW\*(C`NUMWORDS\*(C'\fR also handles the ordinal forms of numbers. So: .PP .Vb 4 \& print scalar NUMWORDS(\*(Aq1st\*(Aq); \& print scalar NUMWORDS(\*(Aq3rd\*(Aq); \& print scalar NUMWORDS(\*(Aq202nd\*(Aq); \& print scalar NUMWORDS(\*(Aq1000000th\*(Aq); .Ve .PP print: .PP .Vb 4 \& first \& third \& two hundred and twenty\-second \& one millionth .Ve .PP Two common idioms in this regard are: .PP .Vb 1 \& print scalar NUMWORDS(ORD($number)); .Ve .PP and: .PP .Vb 1 \& print scalar ORD(NUMWORDS($number)); .Ve .PP These are identical in effect, except when \f(CW$number\fR contains a decimal: .PP .Vb 3 \& $number = 99.09; \& print scalar NUMWORDS(ORD($number)); # ninety\-ninth point zero nine \& print scalar ORD(NUMWORDS($number)); # ninety\-nine point zero ninth .Ve .PP Use whichever you feel is most appropriate. .SH "CONVERTING LISTS OF WORDS TO PHRASES" .IX Header "CONVERTING LISTS OF WORDS TO PHRASES" When creating a list of words, commas are used between adjacent items, except if the items contain commas, in which case semicolons are used. But if there are less than two items, the commas/semicolons are omitted entirely. The final item also has a conjunction (usually \*(L"and\*(R" or \*(L"or\*(R") before it. And although it's technically incorrect (and sometimes misleading), some people prefer to omit the comma before that final conjunction, even when there are more than two items. .PP That's complicated enough to warrant its own subroutine: \f(CW\*(C`WORDLIST()\*(C'\fR. This subroutine expects a list of words, possibly with one or more hash references containing options. It returns a string that joins the list together in the normal English usage. For example: .PP .Vb 2 \& print "You chose ", WORDLIST(@selected_items), "\en"; \& # You chose barley soup, roast beef, and Yorkshire pudding \& \& print "You chose ", WORDLIST(@selected_items, {final_sep=>""}), "\en"; \& # You chose barley soup, roast beef and Yorkshire pudding \& \& print "Please chose ", WORDLIST(@side_orders, {conj=>"or"}), "\en"; \& # Please chose salad, vegetables, or ice\-cream .Ve .PP The available options are: .PP .Vb 1 \& Option named Specifies Default value \& \& conj Final conjunction "and" \& sep Inter\-item separator "," \& last_sep Final separator value of \*(Aqsep\*(Aq option .Ve .SH "INTERPOLATING INFLECTIONS IN STRINGS" .IX Header "INTERPOLATING INFLECTIONS IN STRINGS" By far the commonest use of the inflection subroutines is to produce message strings for various purposes. For example: .PP .Vb 3 \& print NUM($errors), PL_N(" error"), PL_V(" was"), " detected.\en"; \& print PL_ADJ("This"), PL_N(" error"), PL_V(" was"), "fatal.\en" \& if $severity > 1; .Ve .PP Unfortunately the need to separate each subroutine call detracts significantly from the readability of the resulting code. To ameliorate this problem, Lingua::EN::Inflect provides an exportable string-interpolating subroutine (\f(CWinflect($)\fR), which recognizes calls to the various inflection subroutines within a string and interpolates them appropriately. .PP Using \f(CW\*(C`inflect\*(C'\fR the previous example could be rewritten: .PP .Vb 3 \& print inflect "NUM($errors) PL_N(error) PL_V(was) detected.\en"; \& print inflect "PL_ADJ(This) PL_N(error) PL_V(was) fatal.\en" \& if $severity > 1; .Ve .PP Note that \f(CW\*(C`inflect\*(C'\fR also correctly handles calls to the \f(CW\*(C`NUM()\*(C'\fR subroutine (whether interpolated or antecedent). The \f(CW\*(C`inflect()\*(C'\fR subroutine has a related extra feature, in that it \fIautomatically\fR cancels any \*(L"default number\*(R" value before it returns its interpolated string. This means that calls to \f(CW\*(C`NUM()\*(C'\fR which are embedded in an \f(CW\*(C`inflect()\*(C'\fR\-interpolated string do not \*(L"escape\*(R" and interfere with subsequent inflections. .SH "MODERN VS CLASSICAL INFLECTIONS" .IX Header "MODERN VS CLASSICAL INFLECTIONS" Certain words, mainly of Latin or Ancient Greek origin, can form plurals either using the standard English \*(L"\-s\*(R" suffix, or with their original Latin or Greek inflections. For example: .PP .Vb 6 \& PL("stigma") # \-> "stigmas" or "stigmata" \& PL("torus") # \-> "toruses" or "tori" \& PL("index") # \-> "indexes" or "indices" \& PL("millennium") # \-> "millenniums" or "millennia" \& PL("ganglion") # \-> "ganglions" or "ganglia" \& PL("octopus") # \-> "octopuses" or "octopodes" .Ve .PP Lingua::EN::Inflect caters to such words by providing an \&\*(L"alternate state\*(R" of inflection known as \*(L"classical mode\*(R". By default, words are inflected using their contemporary English plurals, but if classical mode is invoked, the more traditional plural forms are returned instead. .PP The exportable subroutine \f(CW\*(C`classical()\*(C'\fR controls this feature. If \f(CW\*(C`classical()\*(C'\fR is called with no arguments, it unconditionally invokes classical mode. If it is called with a single argument, it turns all classical inflects on or off (depending on whether the argument is true or false). If called with two or more arguments, those arguments specify which aspects of classical behaviour are to be used. .PP Thus: .PP .Vb 2 \& classical; # SWITCH ON CLASSICAL MODE \& print PL("formula"); # \-> "formulae" \& \& classical 0; # SWITCH OFF CLASSICAL MODE \& print PL("formula"); # \-> "formulas" \& \& classical $cmode; # CLASSICAL MODE IFF $cmode \& print PL("formula"); # \-> "formulae" (IF $cmode) \& # \-> "formulas" (OTHERWISE) \& \& classical herd=>1; # SWITCH ON CLASSICAL MODE FOR "HERD" NOUNS \& print PL("wilderbeest"); # \-> "wilderbeest" \& \& classical names=>1; # SWITCH ON CLASSICAL MODE FOR NAMES \& print PL("sally"); # \-> "sallies" \& print PL("Sally"); # \-> "Sallys" .Ve .PP Note however that \f(CW\*(C`classical()\*(C'\fR has no effect on the inflection of words which are now fully assimilated. Hence: .PP .Vb 2 \& PL("forum") # ALWAYS \-> "forums" \& PL("criterion") # ALWAYS \-> "criteria" .Ve .PP \&\s-1LEI\s0 assumes that a capitalized word is a person's name. So it forms the plural according to the rules for names (which is that you don't inflect, you just add \-s or \-es). You can choose to turn that behaviour off (it's on by the default, even when the module isn't in classical mode) by calling \f(CW\*(C`classical(names=>0)\*(C'\fR. .SH "USER-DEFINED INFLECTIONS" .IX Header "USER-DEFINED INFLECTIONS" .SS "Adding plurals at run-time" .IX Subsection "Adding plurals at run-time" Lingua::EN::Inflect provides five exportable subroutines which allow the programmer to override the module's behaviour for specific cases: .ie n .IP """def_noun($$)""" 8 .el .IP "\f(CWdef_noun($$)\fR" 8 .IX Item "def_noun($$)" The \f(CW\*(C`def_noun\*(C'\fR subroutine takes a pair of string arguments: the singular and plural forms of the noun being specified. The singular form specifies a pattern to be interpolated (as \f(CW\*(C`m/^(?:$first_arg)$/i\*(C'\fR). Any noun matching this pattern is then replaced by the string in the second argument. The second argument specifies a string which is interpolated after the match succeeds, and is then used as the plural form. For example: .Sp .Vb 3 \& def_noun \*(Aqcow\*(Aq => \*(Aqkine\*(Aq; \& def_noun \*(Aq(.+i)o\*(Aq => \*(Aq$1i\*(Aq; \& def_noun \*(Aqspam(mer)?\*(Aq => \*(Aq\e\e$\e\e%\e\e@#\e\e$\e\e@#!!\*(Aq; .Ve .Sp Note that both arguments should usually be specified in single quotes, so that they are not interpolated when they are specified, but later (when words are compared to them). As indicated by the last example, care also needs to be taken with certain characters in the second argument, to ensure that they are not unintentionally interpolated during comparison. .Sp The second argument string may also specify a second variant of the plural form, to be used when \*(L"classical\*(R" plurals have been requested. The beginning of the second variant is marked by a '|' character: .Sp .Vb 3 \& def_noun \*(Aqcow\*(Aq => \*(Aqcows|kine\*(Aq; \& def_noun \*(Aq(.+i)o\*(Aq => \*(Aq$1os|$1i\*(Aq; \& def_noun \*(Aqspam(mer)?\*(Aq => \*(Aq\e\e$\e\e%\e\e@#\e\e$\e\e@#!!|varmints\*(Aq; .Ve .Sp If no classical variant is given, the specified plural form is used in both normal and \*(L"classical\*(R" modes. .Sp If the second argument is \f(CW\*(C`undef\*(C'\fR instead of a string, then the current user definition for the first argument is removed, and the standard plural inflection(s) restored. .Sp Note that in all cases, later plural definitions for a particular singular form replace earlier definitions of the same form. For example: .Sp .Vb 2 \& # FIRST, HIDE THE MODERN FORM.... \& def_noun \*(Aqaviatrix\*(Aq => \*(Aqaviatrices\*(Aq; \& \& # LATER, HIDE THE CLASSICAL FORM... \& def_noun \*(Aqaviatrix\*(Aq => \*(Aqaviatrixes\*(Aq; \& \& # FINALLY, RESTORE THE DEFAULT BEHAVIOUR... \& def_noun \*(Aqaviatrix\*(Aq => undef; .Ve .Sp Special care is also required when defining general patterns and associated specific exceptions: put the more specific cases \fIafter\fR the general pattern. For example: .Sp .Vb 2 \& def_noun \*(Aq(.+)us\*(Aq => \*(Aq$1i\*(Aq; # EVERY "\-us" TO "\-i" \& def_noun \*(Aqbus\*(Aq => \*(Aqbuses\*(Aq; # EXCEPT FOR "bus" .Ve .Sp This \*(L"try-most-recently-defined-first\*(R" approach to matching user-defined words is also used by \f(CW\*(C`def_verb\*(C'\fR, \f(CW\*(C`def_a\*(C'\fR and \f(CW\*(C`def_an\*(C'\fR. .ie n .IP """def_verb($$$$$$)""" 8 .el .IP "\f(CWdef_verb($$$$$$)\fR" 8 .IX Item "def_verb($$$$$$)" The \f(CW\*(C`def_verb\*(C'\fR subroutine takes three pairs of string arguments (that is, six arguments in total), specifying the singular and plural forms of the three \&\*(L"persons\*(R" of verb. As with \f(CW\*(C`def_noun\*(C'\fR, the singular forms are specifications of run-time-interpolated patterns, whilst the plural forms are specifications of (up to two) run-time-interpolated strings: .Sp .Vb 3 \& def_verb \*(Aqam\*(Aq => \*(Aqare\*(Aq, \& \*(Aqare\*(Aq => \*(Aqare|art", \& \*(Aqis\*(Aq => \*(Aqare\*(Aq; \& \& def_verb \*(Aqhave\*(Aq => \*(Aqhave\*(Aq, \& \*(Aqhave\*(Aq => \*(Aqhave", \& \*(Aqha(s|th)\*(Aq => \*(Aqhave\*(Aq; .Ve .Sp Note that as with \f(CW\*(C`def_noun\*(C'\fR, modern/classical variants of plurals may be separately specified, subsequent definitions replace previous ones, and \f(CW\*(C`undef\*(C'\fR'ed plural forms revert to the standard behaviour. .ie n .IP """def_adj($$)""" 8 .el .IP "\f(CWdef_adj($$)\fR" 8 .IX Item "def_adj($$)" The \f(CW\*(C`def_adj\*(C'\fR subroutine takes a pair of string arguments, which specify the singular and plural forms of the adjective being defined. As with \f(CW\*(C`def_noun\*(C'\fR and \f(CW\*(C`def_adj\*(C'\fR, the singular forms are specifications of run-time-interpolated patterns, whilst the plural forms are specifications of (up to two) run-time-interpolated strings: .Sp .Vb 2 \& def_adj \*(Aqthis\*(Aq => \*(Aqthese\*(Aq, \& def_adj \*(Aqred\*(Aq => \*(Aqred|gules\*(Aq, .Ve .Sp As previously, modern/classical variants of plurals may be separately specified, subsequent definitions replace previous ones, and \f(CW\*(C`undef\*(C'\fR'ed plural forms revert to the standard behaviour. .ie n .IP "def_a($) and def_an($)" 8 .el .IP "\f(CWdef_a($)\fR and \f(CWdef_an($)\fR" 8 .IX Item "def_a($) and def_an($)" The \f(CW\*(C`def_a\*(C'\fR and \f(CW\*(C`def_an\*(C'\fR subroutines each take a single argument, which specifies a pattern. If a word passed to \f(CW\*(C`A()\*(C'\fR or \f(CW\*(C`AN()\*(C'\fR matches this pattern, it will be prefixed (unconditionally) with the corresponding indefinite article. For example: .Sp .Vb 2 \& def_a \*(Aqerror\*(Aq; \& def_a \*(Aqin.+\*(Aq; \& \& def_an \*(Aqmistake\*(Aq; \& def_an \*(Aqerror\*(Aq; .Ve .Sp As with the other \f(CW\*(C`def_...\*(C'\fR subroutines, such redefinitions are sequential in effect so that, after the above example, \*(L"error\*(R" will be inflected with \*(L"an\*(R". .ie n .SS "The \fI\fP\fI$HOME\fP\fI/.inflectrc\fP file" .el .SS "The \fI\fP\f(CI$HOME\fP\fI/.inflectrc\fP file" .IX Subsection "The $HOME/.inflectrc file" When it is imported, Lingua::EN::Inflect executes (as Perl code) the contents of any file named \fI.inflectrc\fR which it finds in the in the directory where \fILingua/EN/Inflect.pm\fR is installed, or in the current home directory (\f(CW$ENV{HOME}\fR), or in both. Note that the code is executed within the Lingua::EN::Inflect namespace. .PP Hence the user or the local Perl guru can make appropriate calls to \&\f(CW\*(C`def_noun\*(C'\fR, \f(CW\*(C`def_verb\*(C'\fR, etc. in one of these \fI.inflectrc\fR files, to permanently and universally modify the behaviour of the module. For example .PP .Vb 1 \& > cat /usr/local/lib/perl5/Text/Inflect/.inflectrc \& \& def_noun "UNIX" => "UN*X|UNICES"; \& \& def_verb "teco" => "teco", # LITERALLY: "to edit with TECO" \& "teco" => "teco", \& "tecos" => "teco"; \& \& def_a "Euler.*"; # "Yewler" TURNS IN HIS GRAVE .Ve .PP Note that calls to the \f(CW\*(C`def_...\*(C'\fR subroutines from within a program will take precedence over the contents of the home directory \&\fI.inflectrc\fR file, which in turn takes precedence over the system-wide \&\fI.inflectrc\fR file. .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" On loading, if the Perl code in a \fI.inflectrc\fR file is invalid (syntactically or otherwise), an appropriate fatal error is issued. A common problem is not ending the file with something that evaluates to true (as the five \f(CW\*(C`def_...\*(C'\fR subroutines do). .PP Using the five \f(CW\*(C`def_...\*(C'\fR subroutines directly in a program may also result in fatal diagnostics, if a (singular) pattern or an interpolated (plural) string is somehow invalid. .PP Specific diagnostics related to user-defined inflections are: .ie n .IP """Bad user\-defined singular pattern:\en\et %s""" 8 .el .IP "\f(CW``Bad user\-defined singular pattern:\en\et %s''\fR" 8 .IX Item """Bad user-defined singular pattern:nt %s""" The singular form of a user-defined noun or verb (as defined by a call to \f(CW\*(C`def_noun\*(C'\fR, \f(CW\*(C`def_verb\*(C'\fR, \f(CW\*(C`def_adj\*(C'\fR, \&\f(CW\*(C`def_a\*(C'\fR or \f(CW\*(C`def_an\*(C'\fR) is not a valid Perl regular expression. The actual Perl error message is also given. .ie n .IP """Bad user\-defined plural string: \*(Aq%s\*(Aq""" 8 .el .IP "\f(CW``Bad user\-defined plural string: \*(Aq%s\*(Aq''\fR" 8 .IX Item """Bad user-defined plural string: %s""" The plural form(s) of a user-defined noun or verb (as defined by a call to \f(CW\*(C`def_noun\*(C'\fR, \f(CW\*(C`def_verb\*(C'\fR or \f(CW\*(C`def_adj\*(C'\fR) is not a valid Perl interpolated string (usually because it interpolates some undefined variable). .ie n .IP """Bad .inflectrc file (%s):\en %s""" 8 .el .IP "\f(CW``Bad .inflectrc file (%s):\en %s''\fR" 8 .IX Item """Bad .inflectrc file (%s):n %s""" Some other problem occurred in loading the named local or global \fI.inflectrc\fR file. The Perl error message (including the line number) is also given. .PP There are \fIno\fR diagnosable run-time error conditions for the actual inflection subroutines, except \f(CW\*(C`NUMWORDS\*(C'\fR and hence no run-time diagnostics. If the inflection subroutines are unable to form a plural via a user-definition or an inbuilt rule, they just \*(L"guess\*(R" the commonest English inflection: adding \*(L"\-s\*(R" for nouns, removing \*(L"\-s\*(R" for verbs, and no inflection for adjectives. .PP \&\f(CW\*(C`Lingua::EN::Inflect::NUMWORDS()\*(C'\fR can \f(CW\*(C`die\*(C'\fR with the following messages: .ie n .IP """Bad grouping option: %s""" 8 .el .IP "\f(CW``Bad grouping option: %s''\fR" 8 .IX Item """Bad grouping option: %s""" The optional argument to \f(CW\*(C`NUMWORDS()\*(C'\fR wasn't 1, 2 or 3. .ie n .IP """Number out of range""" 8 .el .IP "\f(CW``Number out of range''\fR" 8 .IX Item """Number out of range""" \&\f(CW\*(C`NUMWORDS()\*(C'\fR was passed a number larger than 999,999,999,999,999,999,999,999,999,999,999,999 (that is: nine hundred and ninety-nine decillion, nine hundred and ninety-nine nonillion, nine hundred and ninety-nine octillion, nine hundred and ninety-nine septillion, nine hundred and ninety-nine sextillion, nine hundred and ninety-nine quintillion, nine hundred and ninety-nine quadrillion, nine hundred and ninety-nine trillion, nine hundred and ninety-nine billion, nine hundred and ninety-nine million, nine hundred and ninety-nine thousand, nine hundred and ninety-nine :\-) .Sp The problem is that \f(CW\*(C`NUMWORDS\*(C'\fR doesn't know any words for number components bigger than \*(L"decillion\*(R". .SH "OTHER ISSUES" .IX Header "OTHER ISSUES" .SS "2nd Person precedence" .IX Subsection "2nd Person precedence" If a verb has identical 1st and 2nd person singular forms, but different 1st and 2nd person plural forms, then when its plural is constructed, the 2nd person plural form is always preferred. .PP The author is not currently aware of any such verbs in English, but is not quite arrogant enough to assume \fIipso facto\fR that none exist. .SS "Nominative precedence" .IX Subsection "Nominative precedence" The singular pronoun \*(L"it\*(R" presents a special problem because its plural form can vary, depending on its \*(L"case\*(R". For example: .PP .Vb 3 \& It ate my homework \-> They ate my homework \& It ate it \-> They ate them \& I fed my homework to it \-> I fed my homework to them .Ve .PP As a consequence of this ambiguity, \f(CW\*(C`PL()\*(C'\fR or \f(CW\*(C`PL_N\*(C'\fR have been implemented so that they always return the \fInominative\fR plural (that is, \*(L"they\*(R"). .PP However, when asked for the plural of an unambiguously \fIaccusative\fR \&\*(L"it\*(R" (namely, \f(CW\*(C`PL("to it")\*(C'\fR, \f(CW\*(C`PL_N("from it")\*(C'\fR, \f(CW\*(C`PL("with it")\*(C'\fR, etc.), both subroutines will correctly return the accusative plural (\*(L"to them\*(R", \*(L"from them\*(R", \*(L"with them\*(R", etc.) .SS "The plurality of zero" .IX Subsection "The plurality of zero" The rules governing the choice between: .PP .Vb 1 \& There were no errors. .Ve .PP and .PP .Vb 1 \& There was no error. .Ve .PP are complex and often depend more on \fIintent\fR rather than \fIcontent\fR. Hence it is infeasible to specify such rules algorithmically. .PP Therefore, Lingua::EN::Text contents itself with the following compromise: If the governing number is zero, inflections always return the plural form unless the appropriate \*(L"classical\*(R" inflection is in effect, in which case the singular form is always returned. .PP Thus, the sequence: .PP .Vb 2 \& NUM(0); \& print inflect "There PL(was) NO(choice)"; .Ve .PP produces \*(L"There were no choices\*(R", whereas: .PP .Vb 3 \& classical \*(Aqzero\*(Aq; # or: classical(zero=>1); \& NUM(0); \& print inflect "There PL(was) NO(choice)"; .Ve .PP it will print \*(L"There was no choice\*(R". .SS "Homographs with heterogeneous plurals" .IX Subsection "Homographs with heterogeneous plurals" Another context in which intent (and not content) sometimes determines plurality is where two distinct meanings of a word require different plurals. For example: .PP .Vb 2 \& Three basses were stolen from the band\*(Aqs equipment trailer. \& Three bass were stolen from the band\*(Aqs aquarium. \& \& I put the mice next to the cheese. \& I put the mouses next to the computers. \& \& Several thoughts about leaving crossed my mind. \& Several thought about leaving across my lawn. .Ve .PP Lingua::EN::Inflect handles such words in two ways: .IP "\(bu" 8 If both meanings of the word are the \fIsame\fR part of speech (for example, \*(L"bass\*(R" is a noun in both sentences above), then one meaning is chosen as the \*(L"usual\*(R" meaning, and only that meaning's plural is ever returned by any of the inflection subroutines. .IP "\(bu" 8 If each meaning of the word is a different part of speech (for example, \*(L"thought\*(R" is both a noun and a verb), then the noun's plural is returned by \f(CW\*(C`PL()\*(C'\fR and \f(CW\*(C`PL_N()\*(C'\fR and the verb's plural is returned only by \f(CW\*(C`PL_V()\*(C'\fR. .PP Such contexts are, fortunately, uncommon (particularly \&\*(L"same-part-of-speech\*(R" examples). An informal study of nearly 600 \&\*(L"difficult plurals\*(R" indicates that \f(CW\*(C`PL()\*(C'\fR can be relied upon to \*(L"get it right\*(R" about 98% of the time (although, of course, ichthyophilic guitarists or cyber-behaviouralists may experience higher rates of confusion). .PP If the choice of a particular \*(L"usual inflection\*(R" is considered inappropriate, it can always be reversed with a preliminary call to the corresponding \f(CW\*(C`def_...\*(C'\fR subroutine. .SH "NOTE" .IX Header "NOTE" I'm not taking any further correspondence on: .ie n .IP """octopi""." 4 .el .IP "``octopi''." 4 .IX Item "octopi." Despite the populist pandering of certain New World dictionaries, the plural is \*(L"octopuses\*(R" or (for the pedantic classicist) \*(L"octopodes\*(R". The suffix \*(L"\-pus\*(R" is Greek, not Latin, so the plural is \*(L"\-podes\*(R", not \*(L"pi\*(R". .ie n .IP """virus""." 4 .el .IP "``virus''." 4 .IX Item "virus." Had no plural in Latin (possibly because it was a mass noun). The only plural is the Anglicized \*(L"viruses\*(R". .SH "AUTHORS" .IX Header "AUTHORS" Damian Conway (damian@conway.org) Matthew Persico (\s-1ORD\s0 inflection) .SH "BUGS AND IRRITATIONS" .IX Header "BUGS AND IRRITATIONS" The endless inconsistencies of English. .PP (\fIPlease\fR report words for which the correct plural or indefinite article is not formed, so that the reliability of Lingua::EN::Inflect can be improved.) .SH "COPYRIGHT" .IX Header "COPYRIGHT" .Vb 3 \& Copyright (c) 1997\-2009, Damian Conway. All Rights Reserved. \& This module is free software. It may be used, redistributed \& and/or modified under the same terms as Perl itself. .Ve