Lingua-EN-Inflect-1.895/000755 000765 000765 00000000000 12023645160 015376 5ustar00damiandamian000000 000000 Lingua-EN-Inflect-1.895/Build.PL000644 000765 000765 00000000705 11271417441 016677 0ustar00damiandamian000000 000000 use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'Lingua::EN::Inflect', license => 'perl', dist_author => 'Damian Conway ', dist_version_from => 'lib/Lingua/EN/Inflect.pm', requires => { 'Test::More' => 0, 'version' => 0, }, add_to_cleanup => [ 'Lingua-EN-Inflect-*' ], ); $builder->create_build_script(); Lingua-EN-Inflect-1.895/Changes000755 000765 000765 00000012374 12023645152 016704 0ustar00damiandamian000000 000000 Revision history for Perl extension Lingua::EN::Inflect. 1.00 Fri Mar 27 16:37:10 1998 - First public release. 1.01 Tue Mar 31 05:55:14 1998 - Fixed glitch in Makefile.PL 1.02 Tue Mar 31 06:14:20 1998 - Fixed same glitch in Makefile.PL :-) 1.81 Thu Apr 30 19:43:07 1998 - Corrected irregular plural possessives (-'s instead of -s') - Simplified and corrected handling of -o suffixes - Changed behaviour of interpolated NUM() (interpolated NUM()s are now scoped to the enclosing string) - fixed bug in comparison of variant plural genitive forms ("brothers'" and "brethren's" now compare equal ["p:p"]) - added "kine" as classical plural of "cow" - fixed handling of empty strings - fixed version numbers to ensure CPAN.pm downloads latest version 1.82 Thu Aug 27 10:45:50 1998 - corrected inflection of "human" and "German" ('-man' -> '-mans') [spotted by Tom Christiansen] - Added a comprehensive test.pl (776 tests) 1.83 Mon Aug 31 05:50:41 1998 - Put in work-around for change (bug?) in 5.005 Perl parser (added brackets to call to export_ok_tags) 1.84 Mon Aug 31 09:49:15 1998 - Maintenance release (1.83 never made it into the CPAN) 1.85 Wed Sep 8 17:58:42 1999 - added classical "-umbrae" for "-umbra" - added "pragma" -> "pragmata" - fixed behaviour of user-defined nouns (spotted and patched by Hugh Kennedy.) - added tests of user-definition subroutines to test.pl - Added ORD() subroutine supplied by Matthew O. Persico. - Added more -man to -mans inflections (thanks Sean!) - Moved test.pl to t/inflections.t - Added PART_PRES subroutine (see docs) - Added NUMWORDS subroutine (see docs) 1.86 Fri Sep 10 14:11:30 1999 - Fixed handling of postfix prepositions: "passers-by", etc. - Removed superfluous prototyping (thanks Jarkko) - Fixed "modification of read-only value" bug 1.86 Fri Oct 20 11:39:57 2000 - Cleaned up for perl 5.6 (thanks Matthew and Brent) - Doc tweak (thanks Nathan) - Fixed handling of '-ses' -> '-se' verb form - Fixed missing handling of PL_ADJ and NUMWORDS in &infect. 1.87 Thu Apr 26 13:22:09 2001 - Innumerable individual word fixes (thanks Shevek) - Added classical '-ix' -> '-ices' (thanks again Shevek) - Generalized handling of postfix adjectives like "Postmaster General" and "courts martial" (thanks Steve) - Added many other nationalities: "Javanese", "Timorese", etc. (thanks Jarkko) - Added "eyas" (thanks Jarkko) - Unified Inflect.pm and Inflect.pod 1.88 Sun Dec 9 08:47:33 2001 - Enabled NUMWORDS to handle ordinals correctly (thanks Jay) - Changed to standard Licence 1.89 Fri May 20 00:45:02 2005 - Fixed "millennium" (thanks Tim) - Fixed "casinos" (thanks Roel) - Fixed verbal "..oes -> ..oe" (thanks Roel) - Fixed "auto" -> "autos" (thanks Emad) - Added 'one' option to NUMWORDS (see docs) (thanks Decklin) - Allowed A and AN to cope with (i.e. ignore) an existing indefinite article (see docs) - Added finer-grain control over classical modes - Fixed "macro" -> "macros" - Fixed "zero" => "zeros" - Fixed "a UK", "a UNESCO" (thanks SKV!) 1.891 Tue Oct 27 09:22:10 2009 - Fixed "yes" -> "yeses" (thanks Rob) - Fixed "*iz" -> "*izzes" (thanks Rob) - Fixed A/AN for single letters (thanks Sam) - Extended o->os exceptions (thanks Sam) - Fixed "Roman" -> "Romans" (thanks Brent) - Added WORDLIST functionality (thanks Matthew) - Fixed "thief" -> "thiefs|thieves" (thanks Michael) - Fixed "..o" -> "..oes" (thanks Michael) - Added first cut of 'threshold' option to NUMWORDS (thanks Andrew) - Numerous fixes (thanks Tom) - Fixed return value of PL_eq (thanks smylers) - Handled indefinite article for x-th, Nth etc. (thanks Tom) - Numerous special-case fixes (thanks Marc) 1.892 Mon Jun 28 11:01:52 2010 - Swatted POD nits (thanks Frank and Paul) - Fixed A() handling of def_A() (thanks Paul) - Fixed PL_eq() handling of adjectives (thanks Paul) - Removed redundant military terms (thanks Paul) - Fixed single-pronumeral ordinals: an a-th, a b-th, etc. (thanks Paul) - Added present participle fixes for 'is/am/are/was/were/have/had/alibi/hoe' (thanks Paul) - Fixed pluralization of verb "quizzes" (thanks Paul) 1.893 Thu Nov 4 06:24:06 2010 - Fixed major glitch in WORDLIST (thanks calimo) 1.894 Thu Jun 14 10:22:30 2012 - Fixed several dozen obscure plurals (thanks Tom) - Greatly improved the list of prepositions (thanks Tom) - Several minor doc nits cleaned up - Fixed 'miniseries', 'tv series' etc (thanks Lady Aleena) - NON-BACKWARDS COMPATIBLE CHANGE: WORDLIST now always add spaces around its final conjunction. Please report any cases where this is an adverse change. 1.895 Wed Sep 12 00:27:54 2012 - Fixed a POD nit (thanks Gregor) - Added 'words_below', 'comma', and 'comma_every' options to NO() (Thanks Lady Aleena). Lingua-EN-Inflect-1.895/demo/000755 000765 000765 00000000000 12023645160 016322 5ustar00damiandamian000000 000000 Lingua-EN-Inflect-1.895/lib/000755 000765 000765 00000000000 12023645160 016144 5ustar00damiandamian000000 000000 Lingua-EN-Inflect-1.895/Makefile.PL000755 000765 000765 00000001033 11271417471 017356 0ustar00damiandamian000000 000000 use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Lingua::EN::Inflect', AUTHOR => 'Damian Conway ', VERSION_FROM => 'lib/Lingua/EN/Inflect.pm', ABSTRACT_FROM => 'lib/Lingua/EN/Inflect.pm', PL_FILES => {}, PREREQ_PM => { 'Test::More' => 0, 'version' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Lingua-EN-Inflect-*' }, ); Lingua-EN-Inflect-1.895/MANIFEST000755 000765 000765 00000001011 12023645160 016523 0ustar00damiandamian000000 000000 Changes MANIFEST Build.PL Makefile.PL README demo/demo_NO.pl demo/demo_NUM.pl demo/demo_PL.pl demo/demo_eq.pl demo/demo_inflect.pl lib/Lingua/EN/Inflect.pm t/inflections.t t/classical_all.t t/classical_ancient.t t/classical_ancient_1.t t/classical_herd.t t/classical_herd_1.t t/classical_names.t t/classical_names_1.t t/classical_person.t t/classical_person_1.t t/classical_zero.t t/classical_zero_1.t t/numwords.t t/wordlist.t t/no_commas.t META.yml Module meta-data (added by MakeMaker) Lingua-EN-Inflect-1.895/META.yml000644 000765 000765 00000001122 12023645160 016643 0ustar00damiandamian000000 000000 --- #YAML:1.0 name: Lingua-EN-Inflect version: 1.895 abstract: Convert singular to plural. Select "a" or "an". author: - Damian Conway license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: Test::More: 0 version: 0 no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.57_05 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 Lingua-EN-Inflect-1.895/README000644 000765 000765 00000002562 12023645152 016264 0ustar00damiandamian000000 000000 Lingua::EN::Inflect version 1.895 The exportable subroutines of Lingua::EN::Inflect provide plural inflections and "a"/"an" selection for English words. Plural forms of all nouns, most verbs, and some adjectives are provided. Where appropriate, "classical" variants (for example: "brother" -> "brethren", "dogma" -> "dogmata", etc.) are also provided. Pronunciation-based "a"/"an" selection is provided for all English words, and most initialisms. Lingua::EN::Inflect also provides facilities for comparing words in a "number-insensitive" manner (that is, an eq-like comparison in which "ox" and "oxen" compare equal). 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. 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 *not* explicitly catered for. However, the module does provide the ability to define new plural forms (or redefine existing ones). Where two or more inflected forms exist for a single word (typically a "classical" form and a "modern" form), by default Lingua::EN::Inflect returns the more common form (typically the "modern" one). The programmer can, however, specify that "classical" plurals should be preferred. Lingua-EN-Inflect-1.895/t/000755 000765 000765 00000000000 12023645160 015641 5ustar00damiandamian000000 000000 Lingua-EN-Inflect-1.895/t/classical_all.t000755 000765 000765 00000007717 10157440637 020643 0ustar00damiandamian000000 000000 use Lingua::EN::Inflect qw(PL_N classical); use Test::More 'no_plan'; # DEFAULT... is PL_N('error', 0) => 'errors'; # classical 'zero' not active is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brothers'; # classical others not active is PL_N('person') => 'people'; # classical 'persons' not active is PL_N('formula') => 'formulas'; # classical 'ancient' not active # CLASSICAL PLURALS ACTIVATED... classical 'all'; is PL_N('error', 0) => 'error'; # classical 'zero' active is PL_N('wildebeest') => 'wildebeest'; # classical 'herd' active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brethren'; # classical others active is PL_N('person') => 'persons'; # classical 'persons' active is PL_N('formula') => 'formulae'; # classical 'ancient' active # CLASSICAL PLURALS DEACTIVATED... classical all => 0; is PL_N('error', 0) => 'errors'; # classical 'zero' not active is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active is PL_N('Sally') => 'Sallies'; # classical 'names' not active is PL_N('brother') => 'brothers'; # classical others not active is PL_N('person') => 'people'; # classical 'persons' not active is PL_N('formula') => 'formulas'; # classical 'ancient' not active # CLASSICAL PLURALS REACTIVATED... classical all => 1; is PL_N('error', 0) => 'error'; # classical 'zero' active is PL_N('wildebeest') => 'wildebeest'; # classical 'herd' active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brethren'; # classical others active is PL_N('person') => 'persons'; # classical 'persons' active is PL_N('formula') => 'formulae'; # classical 'ancient' active # CLASSICAL PLURALS REDEACTIVATED... classical 0; is PL_N('error', 0) => 'errors'; # classical 'zero' not active is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active is PL_N('Sally') => 'Sallies'; # classical 'names' not active is PL_N('brother') => 'brothers'; # classical others not active is PL_N('person') => 'people'; # classical 'persons' not active is PL_N('formula') => 'formulas'; # classical 'ancient' not active # CLASSICAL PLURALS REREACTIVATED... classical 1; is PL_N('error', 0) => 'error'; # classical 'zero' active is PL_N('wildebeest') => 'wildebeest'; # classical 'herd' active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brethren'; # classical others active is PL_N('person') => 'persons'; # classical 'persons' active is PL_N('formula') => 'formulae'; # classical 'ancient' active # CLASSICAL PLURALS REREDEACTIVATED... classical 0; is PL_N('error', 0) => 'errors'; # classical 'zero' not active is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active is PL_N('Sally') => 'Sallies'; # classical 'names' not active is PL_N('brother') => 'brothers'; # classical others not active is PL_N('person') => 'people'; # classical 'persons' not active is PL_N('formula') => 'formulas'; # classical 'ancient' not active # CLASSICAL PLURALS REREREACTIVATED... classical; is PL_N('error', 0) => 'error'; # classical 'zero' active is PL_N('wildebeest') => 'wildebeest'; # classical 'herd' active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brethren'; # classical others active is PL_N('person') => 'persons'; # classical 'persons' active is PL_N('formula') => 'formulae'; # classical 'ancient' active Lingua-EN-Inflect-1.895/t/classical_ancient.t000755 000765 000765 00000001307 10157440642 021475 0ustar00damiandamian000000 000000 use Lingua::EN::Inflect qw(PL_N classical); use Test::More 'no_plan'; # DEFAULT... is PL_N('formula') => 'formulas'; # classical 'ancient' not active # "person" PLURALS ACTIVATED... classical 'ancient'; is PL_N('formula') => 'formulae'; # classical 'ancient' active # OTHER CLASSICALS NOT ACTIVATED... is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active is PL_N('error', 0) => 'errors'; # classical 'zero' not active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brothers'; # classical 'all' not active is PL_N('person') => 'people'; # classical 'persons' not active Lingua-EN-Inflect-1.895/t/classical_ancient_1.t000755 000765 000765 00000001312 10157440643 021712 0ustar00damiandamian000000 000000 use Lingua::EN::Inflect qw(PL_N classical); use Test::More 'no_plan'; # DEFAULT... is PL_N('formula') => 'formulas'; # classical 'ancient' not active # "person" PLURALS ACTIVATED... classical ancient => 1; is PL_N('formula') => 'formulae'; # classical 'ancient' active # OTHER CLASSICALS NOT ACTIVATED... is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active is PL_N('error', 0) => 'errors'; # classical 'zero' not active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brothers'; # classical 'all' not active is PL_N('person') => 'people'; # classical 'persons' not active Lingua-EN-Inflect-1.895/t/classical_herd.t000755 000765 000765 00000001311 10157440645 020774 0ustar00damiandamian000000 000000 use Lingua::EN::Inflect qw(PL_N classical); use Test::More 'no_plan'; # DEFAULT... is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active # HERD PLURALS ACTIVATED... classical 'herd'; is PL_N('wildebeest') => 'wildebeest'; # classical 'herd' active # OTHER CLASSICALS NOT ACTIVATED... is PL_N('person') => 'people'; # classical 'persons' not active is PL_N('formula') => 'formulas'; # classical 'ancient' not active is PL_N('error', 0) => 'errors'; # classical 'zero' not active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brothers'; # classical 'all' not active Lingua-EN-Inflect-1.895/t/classical_herd_1.t000755 000765 000765 00000001314 10157440651 021214 0ustar00damiandamian000000 000000 use Lingua::EN::Inflect qw(PL_N classical); use Test::More 'no_plan'; # DEFAULT... is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active # HERD PLURALS ACTIVATED... classical herd => 1; is PL_N('wildebeest') => 'wildebeest'; # classical 'herd' active # OTHER CLASSICALS NOT ACTIVATED... is PL_N('person') => 'people'; # classical 'persons' not active is PL_N('formula') => 'formulas'; # classical 'ancient' not active is PL_N('error', 0) => 'errors'; # classical 'zero' not active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brothers'; # classical 'all' not active Lingua-EN-Inflect-1.895/t/classical_names.t000755 000765 000765 00000002044 10157440772 021162 0ustar00damiandamian000000 000000 use Lingua::EN::Inflect qw(PL_N classical); use Test::More 'no_plan'; # DEFAULT... is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('Jones', 0) => 'Joneses'; # always inflects that way # "person" PLURALS ACTIVATED... classical 'names'; is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('Jones', 0) => 'Joneses'; # always inflects that way # OTHER CLASSICALS NOT ACTIVATED... is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active is PL_N('error', 0) => 'errors'; # classical 'zero' not active is PL_N('brother') => 'brothers'; # classical 'all' not active is PL_N('person') => 'people'; # classical 'persons' not active is PL_N('formula') => 'formulas'; # classical 'ancient' not active # "person" PLURALS DEACTIVATED... classical names=>0; is PL_N('Sally') => 'Sallies'; # classical 'names' not active is PL_N('Jones', 0) => 'Joneses'; # always inflects that way Lingua-EN-Inflect-1.895/t/classical_names_1.t000755 000765 000765 00000001526 10157440777 021413 0ustar00damiandamian000000 000000 use Lingua::EN::Inflect qw(PL_N classical); use Test::More 'no_plan'; # DEFAULT... is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('Jones') => 'Joneses'; # always inflects that way # "person" PLURALS ACTIVATED... classical names=>1; is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('Jones') => 'Joneses'; # always inflects that way # OTHER CLASSICALS NOT ACTIVATED... is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active is PL_N('error', 0) => 'errors'; # classical 'zero' not active is PL_N('brother') => 'brothers'; # classical 'all' not active is PL_N('person') => 'people'; # classical 'persons' not active is PL_N('formula') => 'formulas'; # classical 'ancient' not active Lingua-EN-Inflect-1.895/t/classical_person.t000755 000765 000765 00000001306 10157440726 021364 0ustar00damiandamian000000 000000 use Lingua::EN::Inflect qw(PL_N classical); use Test::More 'no_plan'; # DEFAULT... is PL_N('person') => 'people'; # classical 'persons' not active # "person" PLURALS ACTIVATED... classical 'persons'; is PL_N('person') => 'persons'; # classical 'persons' active # OTHER CLASSICALS NOT ACTIVATED... is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active is PL_N('formula') => 'formulas'; # classical 'ancient' not active is PL_N('error', 0) => 'errors'; # classical 'zero' not active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brothers'; # classical 'all' not active Lingua-EN-Inflect-1.895/t/classical_person_1.t000755 000765 000765 00000001307 10157440537 021605 0ustar00damiandamian000000 000000 use Lingua::EN::Inflect qw(PL_N classical); use Test::More 'no_plan'; # DEFAULT... is PL_N('person') => 'people'; # classical 'persons' not active # "person" PLURALS ACTIVATED... classical persons=>1; is PL_N('person') => 'persons'; # classical 'persons' active # OTHER CLASSICALS NOT ACTIVATED... is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active is PL_N('formula') => 'formulas'; # classical 'ancient' not active is PL_N('error', 0) => 'errors'; # classical 'zero' not active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brothers'; # classical 'all' not active Lingua-EN-Inflect-1.895/t/classical_zero.t000755 000765 000765 00000001301 10157440554 021027 0ustar00damiandamian000000 000000 use Lingua::EN::Inflect qw(PL_N classical); use Test::More 'no_plan'; # DEFAULT... is PL_N('error', 0) => 'errors'; # classical 'zero' not active # "person" PLURALS ACTIVATED... classical 'zero'; is PL_N('error', 0) => 'error'; # classical 'zero' active # OTHER CLASSICALS NOT ACTIVATED... is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brothers'; # classical 'all' not active is PL_N('person') => 'people'; # classical 'persons' not active is PL_N('formula') => 'formulas'; # classical 'ancient' not active Lingua-EN-Inflect-1.895/t/classical_zero_1.t000755 000765 000765 00000001304 10157440570 021250 0ustar00damiandamian000000 000000 use Lingua::EN::Inflect qw(PL_N classical); use Test::More 'no_plan'; # DEFAULT... is PL_N('error', 0) => 'errors'; # classical 'zero' not active # "person" PLURALS ACTIVATED... classical zero => 1; is PL_N('error', 0) => 'error'; # classical 'zero' active # OTHER CLASSICALS NOT ACTIVATED... is PL_N('wildebeest') => 'wildebeests'; # classical 'herd' not active is PL_N('Sally') => 'Sallys'; # classical 'names' active is PL_N('brother') => 'brothers'; # classical 'all' not active is PL_N('person') => 'people'; # classical 'persons' not active is PL_N('formula') => 'formulas'; # classical 'ancient' not active Lingua-EN-Inflect-1.895/t/inflections.t000755 000765 000765 00000120702 11565413072 020355 0ustar00damiandamian000000 000000 # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) END {print "not ok 1\n" unless $loaded;} use Lingua::EN::Inflect qw( :ALL ); $loaded = 1; print "ok 1\n"; my $count = 2; sub ok($;$$) { my $ok = $_[0]; print "not " unless $ok; print "ok $count"; print "\t# $_[1]" if $_[1]; print " -> $_[2]" if $_[2]; print "\n"; $count++; return $ok; } ######################### End of black magic. sub test_eq($$) { PL_eq($_[0],$_[1]) || PL_N_eq($_[0],$_[1]) || PL_V_eq($_[0],$_[1]) || PL_ADJ_eq($_[0],$_[1]); } foreach () { # 1 2 3 4 5 if (/^\s*(.*?)\s*->\s*(.*?)\s*(?:\|\s*(.*?)\s*)?(#\s*(.*))?$/) { $singular = $1; $mod_plural = $2; $class_plural = $3 || $2; $comment = $5 || ''; $is_nv = ($comment =~ /verb/i) ? '_V' : ($comment =~ /noun/i) ? '_N' : ''; classical all=>0, names=>0; $mod_PL_V = PL_V($singular); $mod_PL_N = PL_N($singular); $mod_PL = PL($singular); $mod_PL_val = ($is_nv eq '_V') ? $mod_PL_V : ($is_nv eq '_N') ? $mod_PL_N : $mod_PL; classical all=>1; $class_PL_V = PL_V($singular); $class_PL_N = PL_N($singular); $class_PL = PL($singular); $class_PL_val = ($is_nv eq '_V') ? $class_PL_V : ($is_nv eq '_N') ? $class_PL_N : $class_PL; ok ( ($mod_plural eq $mod_PL_val) && ($class_plural eq $class_PL_val) && ( test_eq($singular,$mod_plural) && test_eq($mod_plural,$singular) ) && ( test_eq($singular,$class_plural) && test_eq($class_plural,$singular) ) , $singular , $mod_PL_val eq $class_PL_val ? $mod_PL_val : "$mod_PL_val|$class_PL_val" ) } elsif (/^\s+(an?)\s+(.*?)\s*$/) { $article = $1; $word = $2; $Aword = A($word); ok ("$article $word" eq $Aword, "$article $word"); } } classical 0; def_noun "kin" => "kine"; def_noun '(.*)x' => '$1xen'; def_verb 'foobar' => 'feebar', 'foobar' => 'feebar', 'foobars' => 'feebar'; def_adj 'red' => 'red|gules'; ok ( NO("kin",0) eq "no kine", "kin -> kine (user defined)..." ); ok ( NO("kin",1) eq "1 kin" ); ok ( NO("kin",2) eq "2 kine" ); ok ( NO("regex",0) eq "no regexen", "regex -> regexen (user defined)" ); ok ( PL("foobar",2) eq "feebar", "foobar -> feebar (user defined)..." ); ok ( PL("foobars",2) eq "feebar" ); ok ( PL("red",0) eq "red", "red -> red..." ); ok ( PL("red",1) eq "red" ); ok ( PL("red",2) eq "red" ); classical 1; ok ( PL("red",0) eq "red" , "red -> gules..."); ok ( PL("red",1) eq "red" ); ok ( PL("red",2) eq "gules" ); ok ( ORD(0) eq "0th", "0 -> 0th..." ); ok ( ORD(1) eq "1st" ); ok ( ORD(2) eq "2nd" ); ok ( ORD(3) eq "3rd" ); ok ( ORD(4) eq "4th" ); ok ( ORD(5) eq "5th" ); ok ( ORD(6) eq "6th" ); ok ( ORD(7) eq "7th" ); ok ( ORD(8) eq "8th" ); ok ( ORD(9) eq "9th" ); ok ( ORD(10) eq "10th" ); ok ( ORD(11) eq "11th" ); ok ( ORD(12) eq "12th" ); ok ( ORD(13) eq "13th" ); ok ( ORD(14) eq "14th" ); ok ( ORD(15) eq "15th" ); ok ( ORD(16) eq "16th" ); ok ( ORD(17) eq "17th" ); ok ( ORD(18) eq "18th" ); ok ( ORD(19) eq "19th" ); ok ( ORD(20) eq "20th" ); ok ( ORD(21) eq "21st" ); ok ( ORD(22) eq "22nd" ); ok ( ORD(23) eq "23rd" ); ok ( ORD(24) eq "24th" ); ok ( ORD(100) eq "100th" ); ok ( ORD(101) eq "101st" ); ok ( ORD(102) eq "102nd" ); ok ( ORD(103) eq "103rd" ); ok ( ORD(104) eq "104th" ); ok ( ORD('zero') eq "zeroth", "zero -> zeroth..." ); ok ( ORD('one') eq "first" ); ok ( ORD('two') eq "second" ); ok ( ORD('three') eq "third" ); ok ( ORD('four') eq "fourth" ); ok ( ORD('five') eq "fifth" ); ok ( ORD('six') eq "sixth" ); ok ( ORD('seven') eq "seventh" ); ok ( ORD('eight') eq "eighth" ); ok ( ORD('nine') eq "ninth" ); ok ( ORD('ten') eq "tenth" ); ok ( ORD('eleven') eq "eleventh" ); ok ( ORD('twelve') eq "twelfth" ); ok ( ORD('thirteen') eq "thirteenth" ); ok ( ORD('fourteen') eq "fourteenth" ); ok ( ORD('fifteen') eq "fifteenth" ); ok ( ORD('sixteen') eq "sixteenth" ); ok ( ORD('seventeen') eq "seventeenth" ); ok ( ORD('eighteen') eq "eighteenth" ); ok ( ORD('nineteen') eq "nineteenth" ); ok ( ORD('twenty') eq "twentieth" ); ok ( ORD('twenty-one') eq "twenty-first" ); ok ( ORD('twenty-two') eq "twenty-second" ); ok ( ORD('twenty-three') eq "twenty-third" ); ok ( ORD('twenty-four') eq "twenty-fourth" ); ok ( ORD('one hundred') eq "one hundredth" ); ok ( ORD('one hundred and one') eq "one hundred and first" ); ok ( ORD('one hundred and two') eq "one hundred and second" ); ok ( ORD('one hundred and three') eq "one hundred and third" ); ok ( ORD('one hundred and four') eq "one hundred and fourth" ); ok ( PART_PRES("sees") eq "seeing", "sees -> seeing..." ); ok ( PART_PRES("eats") eq "eating" ); ok ( PART_PRES("bats") eq "batting" ); ok ( PART_PRES("hates") eq "hating" ); ok ( PART_PRES("spies") eq "spying" ); ok ( PART_PRES("skis") eq "skiing" ); BEGIN { $| = 1; print "1..962\n"; } __DATA__ brother-german -> brothers-german | brethren-german Tornese -> Tornesi put-off -> put-offs set-off -> set-offs set-out -> set-outs set-to -> set-tos a -> as # NOUN FORM a -> some # INDEFINITE ARTICLE A.C.R.O.N.Y.M. -> A.C.R.O.N.Y.M.s abscissa -> abscissas|abscissae Achinese -> Achinese acropolis -> acropolises adieu -> adieus|adieux adjutant general -> adjutant generals aegis -> aegises afflatus -> afflatuses afreet -> afreets|afreeti afrit -> afrits|afriti agendum -> agenda aide-de-camp -> aides-de-camp Alabaman -> Alabamans albino -> albinos album -> albums Alfurese -> Alfurese alga -> algae alias -> aliases alto -> altos|alti alumna -> alumnae alumnus -> alumni alveolus -> alveoli am -> are am going -> are going ambassador-at-large -> ambassadors-at-large Amboinese -> Amboinese Americanese -> Americanese amoeba -> amoebas|amoebae Amoyese -> Amoyese an -> some # INDEFINITE ARTICLE analysis -> analyses anathema -> anathemas|anathemata Andamanese -> Andamanese Angolese -> Angolese Annamese -> Annamese antenna -> antennas|antennae anus -> anuses apex -> apexes|apices apex's -> apexes'|apices' # POSSESSIVE FORM aphelion -> aphelia aphis -> aphides apparatus -> apparatuses|apparatus appendix -> appendixes|appendices apple -> apples aquarium -> aquariums|aquaria Aragonese -> Aragonese Arakanese -> Arakanese archipelago -> archipelagos are -> are are made -> are made armadillo -> armadillos arpeggio -> arpeggios arthritis -> arthritises|arthritides asbestos -> asbestoses asparagus -> asparaguses ass -> asses Assamese -> Assamese asylum -> asylums asyndeton -> asyndeta at it -> at them # ACCUSATIVE ataman -> atamans ate -> ate atlas -> atlases|atlantes atman -> atmas attorney general -> attorneys general attorney of record -> attorneys of record aurora -> auroras|aurorae Auslese -> Auslesen auto -> autos auto-da-fe -> autos-da-fe aviatrix -> aviatrixes|aviatrices aviatrix's -> aviatrixes'|aviatrices' Avignonese -> Avignonese axe -> axes axis -> axes axman -> axmen Azerbaijanese -> Azerbaijanese bacillus -> bacilli bacterium -> bacteria Bahaman -> Bahamans Balinese -> Balinese bamboo -> bamboos banjo -> banjoes bass -> basses # INSTRUMENT, NOT FISH basso -> bassos|bassi bathos -> bathoses batz -> batzes beau -> beaus|beaux beef -> beefs|beeves beerenauslese -> beerenauslesen beneath it -> beneath them # ACCUSATIVE Bengalese -> Bengalese bent -> bent # VERB FORM bent -> bents # NOUN FORM Bernese -> Bernese Bhutanese -> Bhutanese bias -> biases biceps -> biceps bison -> bisons|bison blouse -> blouses Bolognese -> Bolognese bonus -> bonuses Borghese -> Borghese boss -> bosses Bostonese -> Bostonese box -> boxes boy -> boys bravo -> bravoes bream -> bream breeches -> breeches bride-to-be -> brides-to-be Brigadier General -> Brigadier Generals britches -> britches bronchitis -> bronchitises|bronchitides bronchus -> bronchi brother -> brothers|brethren brother's -> brothers'|brethren's buffalo -> buffaloes|buffalo Buginese -> Buginese buoy -> buoys bureau -> bureaus|bureaux Burman -> Burmans Burmese -> Burmese bursitis -> bursitises|bursitides bus -> buses buzz -> buzzes buzzes -> buzz # VERB FORM by it -> by them # ACCUSATIVE caddis -> caddises caiman -> caimans cake -> cakes Calabrese -> Calabrese calf -> calves callus -> calluses Camaldolese -> Camaldolese cameo -> cameos campus -> campuses can -> can # VERB FORM (all pers.) can -> cans # NOUN FORM can't -> can't # VERB FORM candelabrum -> candelabra cannabis -> cannabises canoes -> canoe canto -> cantos Cantonese -> Cantonese cantus -> cantus canvas -> canvases CAPITAL -> CAPITALS carcinoma -> carcinomas|carcinomata care -> cares cargo -> cargoes caribou -> caribous|caribou Carlylese -> Carlylese carmen -> carmina carp -> carp Cassinese -> Cassinese cat -> cats catfish -> catfish cayman -> caymans Celanese -> Celanese ceriman -> cerimans cervid -> cervids Ceylonese -> Ceylonese chairman -> chairmen chamois -> chamois chaos -> chaoses chapeau -> chapeaus|chapeaux charisma -> charismas|charismata chases -> chase chassis -> chassis chateau -> chateaus|chateaux cherub -> cherubs|cherubim chervonetz -> chervontzi cheval -> chevaux cheval de bataille -> chevaux de bataille chickenpox -> chickenpox chief -> chiefs child -> children Chinese -> Chinese chorus -> choruses chrysalis -> chrysalises|chrysalides church -> churches cicatrix -> cicatrixes|cicatrices circus -> circuses class -> classes classes -> class # VERB FORM clippers -> clippers clitoris -> clitorises|clitorides cod -> cod codex -> codices coitus -> coitus commando -> commandos compendium -> compendiums|compendia coney -> coneys Congoese -> Congoese Congolese -> Congolese conspectus -> conspectuses contralto -> contraltos|contralti contretemps -> contretemps conundrum -> conundrums corps -> corps corpus -> corpuses|corpora cortex -> cortexes|cortices cosmos -> cosmoses court martial -> courts martial cow -> cows|kine cranium -> craniums|crania crescendo -> crescendos criterion -> criteria curriculum -> curriculums|curricula cystoma -> cystomas | cystomata czech -> czechs dais -> daises data point -> data points datum -> data debris -> debris decorum -> decorums deer -> deer delphinium -> delphiniums desideratum -> desiderata desman -> desmans diabetes -> diabetes dictum -> dictums|dicta did -> did did need -> did need digitalis -> digitalises dingo -> dingoes diploma -> diplomas|diplomata discus -> discuses dish -> dishes ditto -> dittos djinn -> djinn does -> do doesn't -> don't # VERB FORM dog -> dogs dogma -> dogmas|dogmata dolman -> dolmans dominatrix -> dominatrixes|dominatrices domino -> dominoes Dongolese -> Dongolese dormouse -> dormice drama -> dramas|dramata drum -> drums dwarf -> dwarves dynamo -> dynamos edema -> edemas|edemata editio princeps -> editiones principes eland -> elands|eland elf -> elves elk -> elks|elk embryo -> embryos emporium -> emporiums|emporia encephalitis -> encephalitises|encephalitides enconium -> enconiums|enconia enema -> enemas|enemata enigma -> enigmas|enigmata epidermis -> epidermises epididymis -> epididymises|epididymides epiphenomenon -> epiphenomena erratum -> errata ethos -> ethoses eucalyptus -> eucalyptuses eunuch -> eunuchs extremum -> extrema eyas -> eyases factotum -> factotums farman -> farmans Faroese -> Faroese fauna -> faunas|faunae fax -> faxes felo-de-se -> felones-de-se Ferrarese -> Ferrarese ferry -> ferries fetus -> fetuses fiance -> fiances fiancee -> fiancees fiasco -> fiascos fish -> fish fizz -> fizzes flamingo -> flamingoes flittermouse -> flittermice floes -> floe flora -> floras|florae flounder -> flounder focus -> focuses|foci foetus -> foetuses folio -> folios Foochowese -> Foochowese foot -> feet foot's -> feet's # POSSESSIVE FORM foramen -> foramens|foramina foreshoes -> foreshoe formula -> formulas|formulae forum -> forums fought -> fought fox -> foxes from him -> from them from it -> from them # ACCUSATIVE fungus -> funguses|fungi Gabunese -> Gabunese gallows -> gallows ganglion -> ganglions|ganglia gas -> gases gateau -> gateaus|gateaux gave -> gave general -> generals generalissimo -> generalissimos Genevese -> Genevese genie -> genies|genii genius -> geniuses|genii Genoese -> Genoese genus -> genera German -> Germans ghetto -> ghettos Gilbertese -> Gilbertese gliosarcoma -> gliosarcomas|gliosarcomata glottis -> glottises Goanese -> Goanese goat -> goats goose -> geese Governor General -> Governors General goy -> goys|goyim graffiti -> graffiti graffito -> graffiti grizzly -> grizzlies guano -> guanos guardsman -> guardsmen Guianese -> Guianese gumma -> gummas|gummata gumshoes -> gumshoe gunman -> gunmen gymnasium -> gymnasiums|gymnasia had -> had had thought -> had thought Hainanese -> Hainanese hammertoes -> hammertoe handkerchief -> handkerchiefs hapax legomenon -> hapax legomena Hararese -> Hararese Harlemese -> Harlemese harman -> harmans harmonium -> harmoniums has -> have has become -> have become has been -> have been has-been -> has-beens hasn't -> haven't # VERB FORM Havanese -> Havanese have -> have have conceded -> have conceded he -> they headquarters -> headquarters Heavenese -> Heavenese helix -> helices hepatitis -> hepatitises|hepatitides her -> their # POSSESSIVE ADJ her -> them # PRONOUN hero -> heroes herpes -> herpes hers -> theirs # POSSESSIVE NOUN herself -> themselves hetman -> hetmans hiatus -> hiatuses|hiatus highlight -> highlights hijinks -> hijinks him -> them himself -> themselves hippopotamus -> hippopotamuses|hippopotami Hiroshiman -> Hiroshimans his -> their # POSSESSIVE ADJ his -> theirs # POSSESSIVE NOUN hoes -> hoe honorarium -> honorariums|honoraria hoof -> hoofs|hooves Hoosierese -> Hoosierese horseshoes -> horseshoe Hottentotese -> Hottentotese house -> houses housewife -> housewives hubris -> hubrises human -> humans Hunanese -> Hunanese hydra -> hydras|hydrae hyperbaton -> hyperbata hyperbola -> hyperbolas|hyperbolae I -> we ibis -> ibises ignoramus -> ignoramuses impetus -> impetuses|impetus incubus -> incubuses|incubi index -> indexes|indices Indochinese -> Indochinese inferno -> infernos innings -> innings Inspector General -> Inspectors General intermedium -> intermedia interphenomenon -> interphenomena interradius -> interradii interregnum -> interregnums|interregna iris -> irises|irides is -> are is eaten -> are eaten isn't -> aren't # VERB FORM it -> they # NOMINATIVE its -> their # POSSESSIVE FORM itself -> themselves jackanapes -> jackanapes Japanese -> Japanese Javanese -> Javanese jerry -> jerries Jerry -> Jerrys jinx -> jinxes jinxes -> jinx # VERB FORM Johnsonese -> Johnsonese Jones -> Joneses jumbo -> jumbos Kanarese -> Kanarese kibbutz -> kibbutzes | kibbutzim Kiplingese -> Kiplingese knife -> knife # VERB FORM (1st/2nd pers.) knife -> knives # NOUN FORM knifes -> knife # VERB FORM (3rd pers.) Kongoese -> Kongoese Kongolese -> Kongolese kuvasz -> kuvaszok lactobacillus -> lactobacilli lacuna -> lacunas|lacunae lady in waiting -> ladies in waiting Lapponese -> Lapponese larynx -> larynxes|larynges latex -> latexes|latices lawman -> lawmen layman -> laymen leaf -> leaf # VERB FORM (1st/2nd pers.) leaf -> leaves # NOUN FORM leafs -> leaf # VERB FORM (3rd pers.) Lebanese -> Lebanese leman -> lemans lemma -> lemmas|lemmata lens -> lenses Leonese -> Leonese lick of the cat -> licks of the cat Lieutenant General -> Lieutenant Generals life -> lives Liman -> Limans lingo -> lingos loaf -> loaves locus -> loci Londonese -> Londonese Lorrainese -> Lorrainese lothario -> lotharios louse -> lice Lucchese -> Lucchese lumbago -> lumbagos lumen -> lumens|lumina lummox -> lummoxes lustrum -> lustrums|lustra lyceum -> lyceums lymphoma -> lymphomas|lymphomata lynx -> lynxes Lyonese -> Lyonese M.I.A. -> M.I.A.s Macanese -> Macanese Macassarese -> Macassarese mackerel -> mackerel macro -> macros made -> made madman -> madmen Madurese -> Madurese magma -> magmas|magmata magneto -> magnetos magnum opus -> magnum opuses | magna opera Major General -> Major Generals Malabarese -> Malabarese Maltese -> Maltese malum in se -> mala in se man -> men mandamus -> mandamuses manifesto -> manifestos mantis -> mantises marquis -> marquises Mary -> Marys maximum -> maximums|maxima measles -> measles medico -> medicos medium -> mediums|media medium's -> mediums'|media's medulloblastoma -> medulloblastomas|medulloblastomata medusa -> medusas|medusae melastoma -> melastomas|melastomata memorandum -> memorandums|memoranda meniscus -> menisci merman -> mermen Messinese -> Messinese metamorphosis -> metamorphoses metropolis -> metropolises mews -> mews miasma -> miasmas|miasmata micronucleus -> micronuclei Milanese -> Milanese milieu -> milieus|milieux millennium -> millenniums|millennia minimum -> minimums|minima minx -> minxes miss -> miss # VERB FORM (1st/2nd pers.) miss -> misses # NOUN FORM misses -> miss # VERB FORM (3rd pers.) mistletoes -> mistletoe mittamus -> mittamuses Modenese -> Modenese momentum -> momentums|momenta money -> monies mongoose -> mongooses moose -> moose mother-in-law -> mothers-in-law mouse -> mice mumps -> mumps Muranese -> Muranese murex -> murices museum -> museums mustachio -> mustachios my -> our # POSSESSIVE FORM myself -> ourselves mythos -> mythoi Nakayaman -> Nakayamans Nankingese -> Nankingese nasturtium -> nasturtiums Navarrese -> Navarrese nebula -> nebulas|nebulae Nepalese -> Nepalese neuritis -> neuritises|neuritides neurosis -> neuroses news -> news nexus -> nexus Niasese -> Niasese Nicobarese -> Nicobarese nimbus -> nimbuses|nimbi Nipponese -> Nipponese no -> noes Norman -> Normans nostrum -> nostrums noumenon -> noumena nova -> novas|novae nucleolus -> nucleoluses|nucleoli nucleus -> nuclei numen -> numina oaf -> oafs oboes -> oboe occiput -> occiputs|occipita octavo -> octavos octopus -> octopuses|octopodes oedema -> oedemas|oedemata Oklahoman -> Oklahomans omnibus -> omnibuses on it -> on them # ACCUSATIVE onus -> onuses opera -> operas optimum -> optimums|optima opus -> opuses|opera organon -> organa osteoclastoma -> osteoclastomas|osteoclastomata ottoman -> ottomans ought to be -> ought to be # VERB (UNLIKE bride to be) overshoes -> overshoe overtoes -> overtoe ovum -> ova ox -> oxen ox's -> oxen's # POSSESSIVE FORM oxman -> oxmen oxymoron -> oxymorons|oxymora Panaman -> Panamans parabema -> parabemas|parabemata parabola -> parabolas|parabolae paranucleus -> paranuclei Parmese -> Parmese pathos -> pathoses pegasus -> pegasuses Pekingese -> Pekingese pelvis -> pelvises pendulum -> pendulums penis -> penises|penes penumbra -> penumbras|penumbrae perihelion -> perihelia perradius -> perradii person -> people|persons persona -> personae petroleum -> petroleums phalanx -> phalanxes|phalanges PhD -> PhDs phenomenon -> phenomena philtrum -> philtrums photo -> photos phylum -> phylums|phyla piano -> pianos|piani Piedmontese -> Piedmontese pika -> pikas pincer -> pincers pincers -> pincers Pistoiese -> Pistoiese plasmalemma -> plasmalemmata plateau -> plateaus|plateaux play -> plays plexus -> plexuses|plexus pliers -> pliers plies -> ply # VERB FORM polis -> polises Polonese -> Polonese pontifex -> pontifexes|pontifices portmanteau -> portmanteaus|portmanteaux Portuguese -> Portuguese possum -> possums potato -> potatoes pox -> pox pragma -> pragmas|pragmata premium -> premiums prima donna -> prima donnas|prime donne pro -> pros proceedings -> proceedings Progymnasium -> Progymnasia prolegomenon -> prolegomena proof -> proofs proof of concept -> proofs of concept prosecutrix -> prosecutrixes|prosecutrices prospectus -> prospectuses|prospectus protozoan -> protozoans protozoon -> protozoa pseudostoma -> pseudostomata puma -> pumas put -> put quantum -> quantums|quanta quartermaster general -> quartermasters general quarto -> quartos quiz -> quizzes quizzes -> quiz # VERB FORM quorum -> quorums rabies -> rabies radius -> radiuses|radii radix -> radices ragman -> ragmen rebus -> rebuses rehoes -> rehoe reindeer -> reindeer reshoes -> reshoe rhino -> rhinos rhinoceros -> rhinoceroses|rhinoceros roes -> roe Rom -> Roma Romagnese -> Romagnese Roman -> Romans Romanese -> Romanese Romany -> Romanies romeo -> romeos roof -> roofs rostrum -> rostrums|rostra ruckus -> ruckuses salmon -> salmon Sangirese -> Sangirese sank -> sank Sarawakese -> Sarawakese sarcoma -> sarcomas|sarcomata sassafras -> sassafrases saw -> saw # VERB FORM (1st/2nd pers.) saw -> saws # NOUN FORM saws -> saw # VERB FORM (3rd pers.) scarf -> scarves schema -> schemas|schemata scissors -> scissors Scotsman -> Scotsmen sea-bass -> sea-bass seaman -> seamen self -> selves Selman -> Selmans Senegalese -> Senegalese sense-datum -> sense-data seraph -> seraphs|seraphim series -> series shall eat -> shall eat shaman -> shamans Shavese -> Shavese Shawanese -> Shawanese she -> they sheaf -> sheaves shears -> shears sheep -> sheep shelf -> shelves shoes -> shoe should have -> should have Siamese -> Siamese siemens -> siemens Sienese -> Sienese Sikkimese -> Sikkimese silex -> silices simplex -> simplexes|simplices Singhalese -> Singhalese Sinhalese -> Sinhalese sinus -> sinuses|sinus size -> sizes sizes -> size #VERB FORM smallpox -> smallpox Smith -> Smiths snowshoes -> snowshoe Sogdianese -> Sogdianese soliloquy -> soliloquies solo -> solos|soli soma -> somas|somata son of a bitch -> sons of bitches Sonaman -> Sonamans soprano -> sopranos|soprani sought -> sought Spaetlese -> Spaetlesen spattlehoes -> spattlehoe species -> species spectrum -> spectrums|spectra speculum -> speculums|specula spent -> spent spermatozoon -> spermatozoa sphinx -> sphinxes|sphinges spokesperson -> spokespeople|spokespersons stadium -> stadiums|stadia stamen -> stamens|stamina starets -> startsy staretz -> startzy status -> statuses|status stereo -> stereos stigma -> stigmas|stigmata stimulus -> stimuli stoma -> stomas|stomata stomach -> stomachs storey -> storeys story -> stories stratum -> strata strife -> strifes studium generale -> studia generali stylo -> stylos stylus -> styluses|styli substratum -> substrata succubus -> succubuses|succubi Sudanese -> Sudanese suffix -> suffixes Sundanese -> Sundanese superhelix -> superhelices superior -> superiors supernova -> supernovas|supernovae superstratum -> superstrata Surgeon-General -> Surgeons-General surplus -> surpluses Swahilese -> Swahilese swine -> swines|swine syringe -> syringes syrinx -> syrinxes|syringes tableau -> tableaus|tableaux tableman -> tablemen Tacoman -> Tacomans talouse -> talouses tattoo -> tattoos taxman -> taxmen tempo -> tempos|tempi Tenggerese -> Tenggerese testatrix -> testatrixes|testatrices testes -> testes testis -> testes that -> those their -> their # POSSESSIVE FORM (GENDER-INCLUSIVE) themself -> themselves # ugly but gaining currency they -> they # for indeterminate gender thief -> thiefs|thieves this -> these thought -> thought # VERB FORM thought -> thoughts # NOUN FORM throes -> throe ticktacktoes -> ticktacktoe Times -> Timeses Timorese -> Timorese tiptoes -> tiptoe Tirolese -> Tirolese titmouse -> titmice to her -> to them to herself -> to themselves to him -> to them to himself -> to themselves to it -> to them to it -> to them # ACCUSATIVE to itself -> to themselves to me -> to us to myself -> to ourselves to them -> to them # for indeterminate gender to themself -> to themselves # ugly but gaining currency to you -> to you to yourself -> to yourselves Tocharese -> Tocharese toes -> toe tomato -> tomatoes Tonkinese -> Tonkinese tonsillitis -> tonsillitises|tonsillitides tooth -> teeth Torinese -> Torinese torus -> toruses|tori tradesman -> tradesmen trapezium -> trapeziums|trapezia trauma -> traumas|traumata travois -> travois trellis -> trellises tries -> try trilby -> trilbys triradius -> triradii trockenbeerenauslese -> trockenbeerenauslesen trousers -> trousers trousseau -> trousseaus|trousseaux trout -> trout try -> tries tuna -> tuna turf -> turfs|turves Tyrolese -> Tyrolese ultimatum -> ultimatums|ultimata umbilicus -> umbilicuses|umbilici umbra -> umbras|umbrae undershoes -> undershoe unshoes -> unshoe uterus -> uteruses|uteri vacuum -> vacuums|vacua vellum -> vellums velum -> velums|vela Vermontese -> Vermontese Veronese -> Veronese vertebra -> vertebrae vertex -> vertexes|vertices Viennese -> Viennese Vietnamese -> Vietnamese virtuoso -> virtuosos|virtuosi virus -> viruses vixen -> vixens vortex -> vortexes|vortices walrus -> walruses was -> were was faced with -> were faced with was hoping -> were hoping Wenchowese -> Wenchowese were -> were were found -> were found wharf -> wharves whiting -> whiting Whitmanese -> Whitmanese whiz -> whizzes whizz -> whizzes widget -> widgets wife -> wives wildebeest -> wildebeests|wildebeest will -> will # VERB FORM will -> wills # NOUN FORM will eat -> will eat # VERB FORM wills -> will # VERB FORM wish -> wishes with him -> with them with it -> with them # ACCUSATIVE woes -> woe wolf -> wolves woman -> women woman of substance -> women of substance woman's -> women's # POSSESSIVE FORM won't -> won't # VERB FORM woodlouse -> woodlice Yakiman -> Yakimans Yengeese -> Yengeese yeoman -> yeomen yeowoman -> yeowomen yes -> yeses Yokohaman -> Yokohamans you -> you your -> your # POSSESSIVE FORM yourself -> yourselves Yuman -> Yumans Yunnanese -> Yunnanese zero -> zeros zoon -> zoa zuz -> zuzzes|zuzim Lingua-EN-Inflect-1.895/t/no_commas.t000755 000765 000765 00000007567 12023645131 020021 0ustar00damiandamian000000 000000 use Test::More tests => 64; use Lingua::EN::Inflect qw( :ALL ); # No commas... is NO('cat', 12 ), '12 cats' => 'No commas: 12'; is NO('cat', 123 ), '123 cats' => 'No commas: 123'; is NO('cat', 1234 ), '1234 cats' => 'No commas: 1234'; is NO('cat', 12345 ), '12345 cats' => 'No commas: 12345'; is NO('cat', 123456 ), '123456 cats' => 'No commas: 123456'; is NO('cat', 1234567 ), '1234567 cats' => 'No commas: 1234567'; is NO('cat', 12345678 ), '12345678 cats' => 'No commas: 12345678'; is NO('cat', 123456789 ), '123456789 cats' => 'No commas: 123456789'; # Std commas... for my $comma ( qw< , . ' _ > ) { is NO('cat', 12 , { comma => $comma }), "12 cats" => "$comma as comma: 12"; is NO('cat', 123 , { comma => $comma }), "123 cats" => "$comma as comma: 123"; is NO('cat', 1234 , { comma => $comma }), "1${comma}234 cats" => "$comma as comma: 1234"; is NO('cat', 12345 , { comma => $comma }), "12${comma}345 cats" => "$comma as comma: 12345"; is NO('cat', 123456 , { comma => $comma }), "123${comma}456 cats" => "$comma as comma: 123456"; is NO('cat', 1234567 , { comma => $comma }), "1${comma}234${comma}567 cats" => "$comma as comma: 1234567"; is NO('cat', 12345678 , { comma => $comma }), "12${comma}345${comma}678 cats" => "$comma as comma: 12345678"; is NO('cat', 123456789, { comma => $comma }), "123${comma}456${comma}789 cats" => "$comma as comma: 123456789"; } # Comma flag... is NO('cat', 12 , { comma => 1 }), "12 cats" => "$comma as comma: 12"; is NO('cat', 123 , { comma => 1 }), "123 cats" => "$comma as comma: 123"; is NO('cat', 1234 , { comma => 1 }), "1,234 cats" => "$comma as comma: 1234"; is NO('cat', 12345 , { comma => 1 }), "12,345 cats" => "$comma as comma: 12345"; is NO('cat', 123456 , { comma => 1 }), "123,456 cats" => "$comma as comma: 123456"; is NO('cat', 1234567 , { comma => 1 }), "1,234,567 cats" => "$comma as comma: 1234567"; is NO('cat', 12345678 , { comma => 1 }), "12,345,678 cats" => "$comma as comma: 12345678"; is NO('cat', 123456789, { comma => 1 }), "123,456,789 cats" => "$comma as comma: 123456789"; # Comma every 2... is NO('cat', 12 , {comma_every=>2}), '12 cats' => 'Comma every 2: 12'; is NO('cat', 123 , {comma_every=>2}), '1,23 cats' => 'Comma every 2: 123'; is NO('cat', 1234 , {comma_every=>2}), '12,34 cats' => 'Comma every 2: 1234'; is NO('cat', 12345 , {comma_every=>2}), '1,23,45 cats' => 'Comma every 2: 12345'; is NO('cat', 123456 , {comma_every=>2}), '12,34,56 cats' => 'Comma every 2: 123456'; is NO('cat', 1234567 , {comma_every=>2}), '1,23,45,67 cats' => 'Comma every 2: 1234567'; is NO('cat', 12345678 , {comma_every=>2}), '12,34,56,78 cats' => 'Comma every 2: 12345678'; is NO('cat', 123456789, {comma_every=>2}), '1,23,45,67,89 cats' => 'Comma every 2: 123456789'; # Eurocomma every 4... is NO('cat', 12 , {comma_every=>4, comma=>'.'}), '12 cats' => '. as comma every 4: 12'; is NO('cat', 123 , {comma_every=>4, comma=>'.'}), '123 cats' => '. as comma every 4: 123'; is NO('cat', 1234 , {comma_every=>4, comma=>'.'}), '1234 cats' => '. as comma every 4: 1234'; is NO('cat', 12345 , {comma_every=>4, comma=>'.'}), '1.2345 cats' => '. as comma every 4: 12345'; is NO('cat', 123456 , {comma_every=>4, comma=>'.'}), '12.3456 cats' => '. as comma every 4: 123456'; is NO('cat', 1234567 , {comma_every=>4, comma=>'.'}), '123.4567 cats' => '. as comma every 4: 1234567'; is NO('cat', 12345678 , {comma_every=>4, comma=>'.'}), '1234.5678 cats' => '. as comma every 4: 12345678'; is NO('cat', 123456789, {comma_every=>4, comma=>'.'}), '1.2345.6789 cats' => '. as comma every 4: 123456789'; Lingua-EN-Inflect-1.895/t/numwords.t000644 000765 000765 00000037207 12023643157 017721 0ustar00damiandamian000000 000000 # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..951\n"; } END {print "not ok 1\n" unless $loaded;} use Lingua::EN::Inflect qw( :ALL ); $loaded = 1; print "ok 1\n"; my $count = 2; sub ok($;$$) { my $ok = $_[0]; print "not " unless $ok; print "ok $count"; print "\t# $_[1]" if $_[1]; print " -> $_[2]" if $_[2]; print "\n"; $count++; return $ok; } sub diag { print "# @_\n"; } ######################### End of black magic. sub test_eq($$) { PL_eq($_[0],$_[1]) || PL_N_eq($_[0],$_[1]) || PL_V_eq($_[0],$_[1]) || PL_ADJ_eq($_[0],$_[1]); } for my $thresh (0..20) { for my $n (0..20) { my $threshed = NUMWORDS($n, threshold=>$thresh); my $numwords = NUMWORDS($n); if ($n <= $thresh) { ok ( $numwords eq $threshed => "Wordified $n (<= $thresh)"); } else { $threshed =~ s/\D//gxms; ok ( $threshed == $n => "Preserved $n (above $thresh)"); } } } ok NUMWORDS( 999, threshold=>500) eq '999', ' 999 -> 999'; ok NUMWORDS( 1000, threshold=>500) eq '1,000', '1000 -> 1,000'; ok NUMWORDS( 10000, threshold=>500) eq '10,000', '10000 -> 10,000'; ok NUMWORDS( 100000, threshold=>500) eq '100,000', '100000 -> 100,000'; ok NUMWORDS(1000000, threshold=>500) eq '1,000,000', '1000000 -> 1,000,000'; ok NUMWORDS( 999.3, threshold=>500) eq '999.3', ' 999.3 -> 999.3'; ok NUMWORDS( 1000.3, threshold=>500) eq '1,000.3', '1000.3 -> 1,000.3'; ok NUMWORDS( 10000.3, threshold=>500) eq '10,000.3', '10000.3 -> 10,000.3'; ok NUMWORDS( 100000.3, threshold=>500) eq '100,000.3', '100000.3 -> 100,000.3'; ok NUMWORDS(1000000.3, threshold=>500) eq '1,000,000.3', '1000000.3 -> 1,000,000.3'; ok NUMWORDS( 999, threshold=>500, comma=>0) eq '999', ' 999 -> 999'; ok NUMWORDS( 1000, threshold=>500, comma=>0) eq '1000', '1000 -> 1000'; ok NUMWORDS( 10000, threshold=>500, comma=>0) eq '10000', '10000 -> 10000'; ok NUMWORDS( 100000, threshold=>500, comma=>0) eq '100000', '100000 -> 100000'; ok NUMWORDS(1000000, threshold=>500, comma=>0) eq '1000000', '1000000 -> 1000000'; ok NUMWORDS( 999.3, threshold=>500, comma=>0) eq '999.3', ' 999.3 -> 999.3'; ok NUMWORDS( 1000.3, threshold=>500, comma=>0) eq '1000.3', '1000.3 -> 1000.3'; ok NUMWORDS( 10000.3, threshold=>500, comma=>0) eq '10000.3', '10000.3 -> 10000.3'; ok NUMWORDS( 100000.3, threshold=>500, comma=>0) eq '100000.3', '100000.3 -> 100000.3'; ok NUMWORDS(1000000.3, threshold=>500, comma=>0) eq '1000000.3', '1000000.3 -> 1000000.3'; for my $i (0..$#nw) { ok ( NUMWORDS($nw[$i][0]) eq $nw[$i][1], "$nw[$i][0] -> $nw[$i][1]..." ); ok ( NUMWORDS($nw[$i][0], group=>1) eq $nw[$i][2] ); ok ( NUMWORDS($nw[$i][0], group=>2) eq $nw[$i][3] ); ok ( NUMWORDS($nw[$i][0], group=>3) eq $nw[$i][4] ); ok ( NUMWORDS(ORD($nw[$i][0])) eq $nw[$i][5] ) if $nw[$i][5]; ok ( ORD(NUMWORDS($nw[$i][0])) eq ($nw[$i][6]||$nw[$i][5]) ) if $nw[$i][6]||$nw[$i][5]; ok !eval { NUMWORDS(42, and=>); 1; }; ok $@ =~ 'odd number of'; diag NO('cat', $nw[$i][0], {words_below=>100}); ok ( NO('cat', $nw[$i][0], {words_below=>100}) =~ ( $nw[$i][0] == 0 ? 'no cat' : $nw[$i][0] == 1 ? 'one cat' : $nw[$i][0] < 100 ? "$nw[$i][1] cats" : "$nw[$i][0] cats")); } BEGIN { @nw = ( [ "0", "zero", "zero", "zero", "zero", "zeroth", ],[ "1", "one", "one", "one", "one", "first", ],[ "2", "two", "two", "two", "two", "second", ],[ "3", "three", "three", "three", "three", "third", ],[ "4", "four", "four", "four", "four", "fourth", ],[ "5", "five", "five", "five", "five", "fifth", ],[ "6", "six", "six", "six", "six", "sixth", ],[ "7", "seven", "seven", "seven", "seven", "seventh", ],[ "8", "eight", "eight", "eight", "eight", "eighth", ],[ "9", "nine", "nine", "nine", "nine", "ninth", ],[ "10", "ten", "one, zero", "ten", "ten", "tenth", ],[ "11", "eleven", "one, one", "eleven", "eleven", "eleventh", ],[ "12", "twelve", "one, two", "twelve", "twelve", "twelfth", ],[ "13", "thirteen", "one, three", "thirteen", "thirteen", "thirteenth", ],[ "14", "fourteen", "one, four", "fourteen", "fourteen", "fourteenth", ],[ "15", "fifteen", "one, five", "fifteen", "fifteen", "fifteenth", ],[ "16", "sixteen", "one, six", "sixteen", "sixteen", "sixteenth", ],[ "17", "seventeen", "one, seven", "seventeen", "seventeen", "seventeenth", ],[ "18", "eighteen", "one, eight", "eighteen", "eighteen", "eighteenth", ],[ "19", "nineteen", "one, nine", "nineteen", "nineteen", "nineteenth", ],[ "20", "twenty", "two, zero", "twenty", "twenty", "twentieth", ],[ "21", "twenty-one", "two, one", "twenty-one", "twenty-one", "twenty-first", ],[ "29", "twenty-nine", "two, nine", "twenty-nine", "twenty-nine", "twenty-ninth", ],[ "99", "ninety-nine", "nine, nine", "ninety-nine", "ninety-nine", "ninety-ninth", ],[ "100", "one hundred", "one, zero, zero", "ten, zero", "one zero zero", "one hundredth" ],[ "101", "one hundred and one", "one, zero, one", "ten, one", "one zero one", "one hundred and first" ],[ "110", "one hundred and ten", "one, one, zero", "eleven, zero", "one ten", "one hundred and tenth", ],[ "111", "one hundred and eleven", "one, one, one", "eleven, one", "one eleven", "one hundred and eleventh", ],[ "900", "nine hundred", "nine, zero, zero", "ninety, zero", "nine zero zero", "nine hundredth", ],[ "999", "nine hundred and ninety-nine", "nine, nine, nine", "ninety-nine, nine", "nine ninety-nine", "nine hundred and ninety-ninth", ],[ "1000", "one thousand", "one, zero, zero, zero", "ten, zero zero", "one zero zero, zero", "one thousandth", ],[ "1001", "one thousand and one", "one, zero, zero, one", "ten, zero one", "one zero zero, one", "one thousand and first", ],[ "1010", "one thousand and ten", "one, zero, one, zero", "ten, ten", "one zero one, zero", "one thousand and tenth", ],[ "1100", "one thousand, one hundred", "one, one, zero, zero", "eleven, zero zero", "one ten, zero", "one thousand, one hundredth", ],[ "2000", "two thousand", "two, zero, zero, zero", "twenty, zero zero", "two zero zero, zero", "two thousandth", ],[ "10000", "ten thousand", "one, zero, zero, zero, zero", "ten, zero zero, zero", "one zero zero, zero zero", "ten thousandth", ],[ "100000", "one hundred thousand", "one, zero, zero, zero, zero, zero", "ten, zero zero, zero zero", "one zero zero, zero zero zero", "one hundred thousandth", ],[ "100001", "one hundred thousand and one", "one, zero, zero, zero, zero, one", "ten, zero zero, zero one", "one zero zero, zero zero one", "one hundred thousand and first", ],[ "123456", "one hundred and twenty-three thousand, four hundred and fifty-six", "one, two, three, four, five, six", "twelve, thirty-four, fifty-six", "one twenty-three, four fifty-six", "one hundred and twenty-three thousand, four hundred and fifty-sixth", ],[ "0123456", "one hundred and twenty-three thousand, four hundred and fifty-six", "zero, one, two, three, four, five, six", "zero one, twenty-three, forty-five, six", "zero twelve, three forty-five, six", "one hundred and twenty-three thousand, four hundred and fifty-sixth", ],[ "1234567", "one million, two hundred and thirty-four thousand, five hundred and sixty-seven", "one, two, three, four, five, six, seven", "twelve, thirty-four, fifty-six, seven", "one twenty-three, four fifty-six, seven", "one million, two hundred and thirty-four thousand, five hundred and sixty-seventh", ],[ "12345678", "twelve million, three hundred and forty-five thousand, six hundred and seventy-eight", "one, two, three, four, five, six, seven, eight", "twelve, thirty-four, fifty-six, seventy-eight", "one twenty-three, four fifty-six, seventy-eight", "twelve million, three hundred and forty-five thousand, six hundred and seventy-eighth", ],[ "12_345_678", "twelve million, three hundred and forty-five thousand, six hundred and seventy-eight", "one, two, three, four, five, six, seven, eight", "twelve, thirty-four, fifty-six, seventy-eight", "one twenty-three, four fifty-six, seventy-eight", ],[ "1234,5678", "twelve million, three hundred and forty-five thousand, six hundred and seventy-eight", "one, two, three, four, five, six, seven, eight", "twelve, thirty-four, fifty-six, seventy-eight", "one twenty-three, four fifty-six, seventy-eight", ],[ "1234567890", "one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninety", "one, two, three, four, five, six, seven, eight, nine, zero", "twelve, thirty-four, fifty-six, seventy-eight, ninety", "one twenty-three, four fifty-six, seven eighty-nine, zero", "one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninetieth", ],[ "123456789012345", "one hundred and twenty-three trillion, four hundred and fifty-six billion, seven hundred and eighty-nine million, twelve thousand, three hundred and forty-five", "one, two, three, four, five, six, seven, eight, nine, zero, one, two, three, four, five", "twelve, thirty-four, fifty-six, seventy-eight, ninety, twelve, thirty-four, five", "one twenty-three, four fifty-six, seven eighty-nine, zero twelve, three forty-five", "one hundred and twenty-three trillion, four hundred and fifty-six billion, seven hundred and eighty-nine million, twelve thousand, three hundred and forty-fifth", ],[ "12345678901234567890", "twelve quintillion, three hundred and forty-five quadrillion, six hundred and seventy-eight trillion, nine hundred and one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninety", "one, two, three, four, five, six, seven, eight, nine, zero, one, two, three, four, five, six, seven, eight, nine, zero", "twelve, thirty-four, fifty-six, seventy-eight, ninety, twelve, thirty-four, fifty-six, seventy-eight, ninety", "one twenty-three, four fifty-six, seven eighty-nine, zero twelve, three forty-five, six seventy-eight, ninety", "twelve quintillion, three hundred and forty-five quadrillion, six hundred and seventy-eight trillion, nine hundred and one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninetieth", ],[ "0.987654", "zero point nine eight seven six five four", "zero, point, nine, eight, seven, six, five, four", "zero, point, ninety-eight, seventy-six, fifty-four", "zero, point, nine eighty-seven, six fifty-four", "zeroth point nine eight seven six five four", "zero point nine eight seven six five fourth", ],[ ".987654", "point nine eight seven six five four", "point, nine, eight, seven, six, five, four", "point, ninety-eight, seventy-six, fifty-four", "point, nine eighty-seven, six fifty-four", "point nine eight seven six five four", "point nine eight seven six five fourth", ],[ "9.87654", "nine point eight seven six five four", "nine, point, eight, seven, six, five, four", "nine, point, eighty-seven, sixty-five, four", "nine, point, eight seventy-six, fifty-four", "ninth point eight seven six five four", "nine point eight seven six five fourth", ],[ "98.7654", "ninety-eight point seven six five four", "nine, eight, point, seven, six, five, four", "ninety-eight, point, seventy-six, fifty-four", "ninety-eight, point, seven sixty-five, four", "ninety-eighth point seven six five four", "ninety-eight point seven six five fourth", ],[ "987.654", "nine hundred and eighty-seven point six five four", "nine, eight, seven, point, six, five, four", "ninety-eight, seven, point, sixty-five, four", "nine eighty-seven, point, six fifty-four", "nine hundred and eighty-seventh point six five four", "nine hundred and eighty-seven point six five fourth", ],[ "9876.54", "nine thousand, eight hundred and seventy-six point five four", "nine, eight, seven, six, point, five, four", "ninety-eight, seventy-six, point, fifty-four", "nine eighty-seven, six, point, fifty-four", "nine thousand, eight hundred and seventy-sixth point five four", "nine thousand, eight hundred and seventy-six point five fourth", ],[ "98765.4", "ninety-eight thousand, seven hundred and sixty-five point four", "nine, eight, seven, six, five, point, four", "ninety-eight, seventy-six, five, point, four", "nine eighty-seven, sixty-five, point, four", "ninety-eight thousand, seven hundred and sixty-fifth point four", "ninety-eight thousand, seven hundred and sixty-five point fourth", ],[ "101.202.303", "one hundred and one point two zero two three zero three", "one, zero, one, point, two, zero, two, point, three, zero, three", "ten, one, point, twenty, two, point, thirty, three", "one zero one, point, two zero two, point, three zero three", ] ); } Lingua-EN-Inflect-1.895/t/wordlist.t000644 000765 000765 00000006573 11750704102 017706 0ustar00damiandamian000000 000000 use Lingua::EN::Inflect qw( WORDLIST ); use Test::More 'no_plan'; my @words; # Four words... @words = qw(apple banana carrot tomato); is WORDLIST(@words), "apple, banana, carrot, and tomato" => 'plain 4 words'; is WORDLIST(@words, {final_sep=>''}), "apple, banana, carrot and tomato" => '4 words, no final sep'; is WORDLIST(@words, {final_sep=>'...'}), "apple, banana, carrot... and tomato" => '4 words, different final sep'; is WORDLIST(@words, {final_sep=>'...', conj=>''}), "apple, banana, carrot... tomato" => '4 words, different final sep, no conjunction'; is WORDLIST(@words, {conj=>'or'}), "apple, banana, carrot, or tomato" => '4 words, different conjunction'; is WORDLIST(@words, {conj=>'&'}), "apple, banana, carrot, & tomato" => '4 words, different conjunction'; # Three words... @words = qw(apple banana carrot); is WORDLIST(@words), "apple, banana, and carrot" => 'plain 3 words'; is WORDLIST(@words, {final_sep=>''}), "apple, banana and carrot" => '3 words, no final sep'; is WORDLIST(@words, {final_sep=>'...'}), "apple, banana... and carrot" => '3 words, different final sep'; is WORDLIST(@words, {final_sep=>'...', conj=>''}), "apple, banana... carrot" => '3 words, different final sep, no conjunction'; is WORDLIST(@words, {conj=>'or'}), "apple, banana, or carrot" => '3 words, different conjunction'; is WORDLIST(@words, {conj=>'&'}), "apple, banana, & carrot" => '3 words, different conjunction'; # Three words with semicolons... @words = ('apple,fuji' , 'banana' , 'carrot'); is WORDLIST(@words), "apple,fuji; banana; and carrot" => 'comma-inclusive 3 words'; is WORDLIST(@words, {final_sep=>''}), "apple,fuji; banana and carrot" => 'comma-inclusive 3 words, no final sep'; is WORDLIST(@words, {final_sep=>'...'}), "apple,fuji; banana... and carrot" => 'comma-inclusive 3 words, different final sep'; is WORDLIST(@words, {final_sep=>'...', conj=>''}), "apple,fuji; banana... carrot" => 'comma-inclusive 3 words, different final sep, no conjunction'; is WORDLIST(@words, {conj=>'or'}), "apple,fuji; banana; or carrot" => 'comma-inclusive 3 words, different conjunction'; is WORDLIST(@words, {conj=>'&'}), "apple,fuji; banana; & carrot" => 'comma-inclusive 3 words, different conjunction'; # Two words... @words = qw(apple carrot ); is WORDLIST(@words), "apple and carrot" => 'plain 2 words'; is WORDLIST(@words, {final_sep=>''}), "apple and carrot" => '2 words, no final sep'; is WORDLIST(@words, {final_sep=>'...'}), "apple and carrot" => '2 words, different final sep'; is WORDLIST(@words, {final_sep=>'...', conj=>''}), "applecarrot" => '2 words, different final sep, no conjunction'; is WORDLIST(@words, {conj=>'or'}), "apple or carrot" => '2 words, different conjunction'; is WORDLIST(@words, {conj=>'&'}), "apple & carrot" => '2 words, different conjunction'; # One word... @words = qw(carrot ); is WORDLIST(@words), "carrot" => 'plain 1 word'; is WORDLIST(@words, {final_sep=>''}), "carrot" => '1 word, no final sep'; is WORDLIST(@words, {final_sep=>'...'}), "carrot" => '1 word, different final sep'; is WORDLIST(@words, {final_sep=>'...', conj=>''}), "carrot" => '1 word, different final sep, no conjunction'; is WORDLIST(@words, {conj=>'or'}), "carrot" => '1 word, different conjunction'; Lingua-EN-Inflect-1.895/lib/Lingua/000755 000765 000765 00000000000 12023645160 017363 5ustar00damiandamian000000 000000 Lingua-EN-Inflect-1.895/lib/Lingua/EN/000755 000765 000765 00000000000 12023645160 017665 5ustar00damiandamian000000 000000 Lingua-EN-Inflect-1.895/lib/Lingua/EN/Inflect.pm000755 000765 000765 00000266775 12023645152 021642 0ustar00damiandamian000000 000000 package Lingua::EN::Inflect; use strict; use vars qw($VERSION @EXPORT_OK %EXPORT_TAGS @ISA); use Env; require Exporter; @ISA = qw(Exporter); our $VERSION = '1.895'; %EXPORT_TAGS = ( ALL => [ qw( classical inflect PL PL_N PL_V PL_ADJ NO NUM A AN PL_eq PL_N_eq PL_V_eq PL_ADJ_eq PART_PRES ORD NUMWORDS WORDLIST def_noun def_verb def_adj def_a def_an )], INFLECTIONS => [ qw( classical inflect PL PL_N PL_V PL_ADJ PL_eq NO NUM A AN PART_PRES )], PLURALS => [ qw( classical inflect PL PL_N PL_V PL_ADJ NO NUM PL_eq PL_N_eq PL_V_eq PL_ADJ_eq )], COMPARISONS => [ qw( classical PL_eq PL_N_eq PL_V_eq PL_ADJ_eq )], ARTICLES => [ qw( classical inflect NUM A AN )], NUMERICAL => [ qw( ORD NUMWORDS )], USER_DEFINED => [ qw( def_noun def_verb def_adj def_a def_an )], ); Exporter::export_ok_tags(qw( ALL )); # SUPPORT CLASSICAL PLURALIZATIONS my %def_classical = ( all => 0, zero => 0, herd => 0, names => 1, persons => 0, ancient => 0, ); my %all_classical = ( all => 1, zero => 1, herd => 1, names => 1, persons => 1, ancient => 1, ); my %classical = %def_classical; my $classical_mode = join '|', keys %all_classical; $classical_mode = qr/^(?:$classical_mode)$/; sub classical { if (!@_) { %classical = %all_classical; return; } if (@_==1 && $_[0] !~ $classical_mode) { %classical = $_[0] ? %all_classical : (); return; } while (@_) { my $arg = shift; if ($arg !~ $classical_mode) { die "Unknown classical mode ($arg)\n"; } if (@_ && $_[0] !~ $classical_mode) { $classical{$arg} = shift; } else { $classical{$arg} = 1; } if ($arg eq 'all') { %classical = $classical{all} ? %all_classical : (); } } } my $persistent_count; sub NUM # (;$count,$show) { if (defined $_[0]) { $persistent_count = $_[0]; return $_[0] if !defined($_[1]) || $_[1]; } else { $persistent_count = undef; } return ''; } # 0. PERFORM GENERAL INFLECTIONS IN A STRING sub enclose { "(?:$_[0])" } sub inflect { my $save_persistent_count = $persistent_count; my @sections = split /(NUM\([^)]*\))/, $_[0]; my $inflection = ""; foreach ( @sections ) { unless (s/NUM\(\s*?(?:([^),]*)(?:,([^)]*))?)?\)/ NUM($1,$2) /xe) { 1 while s/\bPL \( ([^),]*) (, ([^)]*) )? \) / PL($1,$3) /xeg || s/\bPL_N \( ([^),]*) (, ([^)]*) )? \) / PL_N($1,$3) /xeg || s/\bPL_V \( ([^),]*) (, ([^)]*) )? \) / PL_V($1,$3) /xeg || s/\bPL_ADJ \( ([^),]*) (, ([^)]*) )? \) / PL_ADJ($1,$3) /xeg || s/\bAN? \( ([^),]*) (, ([^)]*) )? \) / A($1,$3) /xeg || s/\bNO \( ([^),]*) (, ([^)]*) )? \) / NO($1,$3) /xeg || s/\bORD \( ([^)]*) \) / ORD($1) /xeg || s/\bNUMWORDS \( ([^)]*) \) / NUMWORDS($1) /xeg || s/\bPART_PRES \( ([^)]*) \) / PART_PRES($1) /xeg } $inflection .= $_; } $persistent_count = $save_persistent_count; return $inflection; } # 1. PLURALS my %PL_sb_irregular_s = ( "corpus" => "corpuses|corpora", "opus" => "opuses|opera", "magnum opus" => "magnum opuses|magna opera", "genus" => "genera", "mythos" => "mythoi", "penis" => "penises|penes", "testis" => "testes", "atlas" => "atlases|atlantes", "yes" => "yeses", 'editio princeps' => 'editiones principes', 'starets' => 'startsy', 'staretz' => 'startzy', ); my %PL_sb_irregular = ( "child" => "children", "brother" => "brothers|brethren", "loaf" => "loaves", "hoof" => "hoofs|hooves", "beef" => "beefs|beeves", "thief" => "thiefs|thieves", "money" => "monies", "mongoose" => "mongooses", "ox" => "oxen", "cow" => "cows|kine", "graffito" => "graffiti", "prima donna" => "prima donnas|prime donne", "octopus" => "octopuses|octopodes", "genie" => "genies|genii", "ganglion" => "ganglions|ganglia", "trilby" => "trilbys", "turf" => "turfs|turves", "numen" => "numina", "atman" => "atmas", "occiput" => "occiputs|occipita", 'sabretooth' => 'sabretooths', 'sabertooth' => 'sabertooths', 'lowlife' => 'lowlifes', 'flatfoot' => 'flatfoots', 'tenderfoot' => 'tenderfoots', 'Romany' => 'Romanies', 'romany' => 'romanies', 'Tornese' => 'Tornesi', 'Jerry' => 'Jerrys', 'jerry' => 'jerries', 'Mary' => 'Marys', 'mary' => 'maries', 'talouse' => 'talouses', 'blouse' => 'blouses', 'Rom' => 'Roma', 'rom' => 'roma', 'carmen' => 'carmina', 'cheval' => 'chevaux', 'chervonetz' => 'chervontzi', 'kuvasz' => 'kuvaszok', 'felo' => 'felones', 'put-off' => 'put-offs', 'set-off' => 'set-offs', 'set-out' => 'set-outs', 'set-to' => 'set-tos', 'brother-german' => 'brothers-german|brethren-german', 'studium generale' => 'studia generali', %PL_sb_irregular_s, ); my $PL_sb_irregular = enclose join '|', reverse sort keys %PL_sb_irregular; # Z's that don't double my @PL_sb_z_zes = ( "batz", "quartz", "topaz", "snooz(?=e)", "kibbutz", ); my $PL_sb_z_zes = enclose join '|', @PL_sb_z_zes; # UNCONDITIONAL "..is" -> "..ides" my @PL_sb_U_is_ides = ( "aphis", ); my $PL_sb_U_is_ides = enclose join "|", map { substr($_,0,-2) } @PL_sb_U_is_ides; # CLASSICAL "..is" -> "..ides" my @PL_sb_C_is_ides = ( # GENERAL WORDS... "ephemeris", "iris", "clitoris", "chrysalis", "epididymis", # INFLAMATIONS... ".*itis", ); my $PL_sb_C_is_ides = enclose join "|", map { substr($_,0,-2) } @PL_sb_C_is_ides; # UNCONDITIONAL "..a" -> "..ata" my @PL_sb_U_a_ata = ( "plasmalemma", "pseudostoma", ); my $PL_sb_U_a_ata = enclose join "|", map { substr($_,0,-1) } @PL_sb_U_a_ata; # CLASSICAL "..a" -> "..ata" my @PL_sb_C_a_ata = ( "anathema", "bema", "carcinoma", "charisma", "diploma", "dogma", "drama", "edema", "enema", "enigma", "lemma", "lymphoma", "magma", "melisma", "miasma", "oedema", "sarcoma", "schema", "soma", "stigma", "stoma", "trauma", "gumma", "pragma", "bema", ); my $PL_sb_C_a_ata = enclose join "|", map { substr($_,0,-1) } @PL_sb_C_a_ata; # UNCONDITIONAL "..a" -> "..ae" my $PL_sb_U_a_ae = enclose join "|", ( "alumna", "alga", "vertebra", "persona" ); # CLASSICAL "..a" -> "..ae" my $PL_sb_C_a_ae = enclose join "|", ( "amoeba", "antenna", "formula", "hyperbola", "medusa", "nebula", "parabola", "abscissa", "hydra", "nova", "lacuna", "aurora", ".*umbra", "flora", "fauna", ); # CLASSICAL "..en" -> "..ina" my $PL_sb_C_en_ina = enclose join "|", map { substr($_,0,-2) } ( "stamen", "foramen", "lumen" ); # UNCONDITIONAL "..um" -> "..a" my $PL_sb_U_um_a = enclose join "|", map { substr($_,0,-2) } ( "bacterium", "agendum", "desideratum", "erratum", "stratum", "datum", "ovum", "extremum", "candelabrum", "intermedium", "malum", "Progymnasium", ); # CLASSICAL "..um" -> "..a" my $PL_sb_C_um_a = enclose join "|", map { substr($_,0,-2) } ( "maximum", "minimum", "momentum", "optimum", "quantum", "cranium", "curriculum", "dictum", "phylum", "aquarium", "compendium", "emporium", "enconium", "gymnasium", "honorarium", "interregnum", "lustrum", "memorandum", "millennium", "rostrum", "spectrum", "speculum", "stadium", "trapezium", "ultimatum", "medium", "vacuum", "velum", "consortium", ); # UNCONDITIONAL "..us" -> "i" my $PL_sb_U_us_i = enclose join "|", map { substr($_,0,-2) } ( "alumnus", "alveolus", "bacillus", "bronchus", "locus", "nucleus", "stimulus", "meniscus", "sarcophagus", "interradius", "perradius", "triradius", ); # CLASSICAL "..us" -> "..i" my $PL_sb_C_us_i = enclose join "|", map { substr($_,0,-2) } ( "focus", "radius", "genius", "incubus", "succubus", "nimbus", "fungus", "nucleolus", "stylus", "torus", "umbilicus", "uterus", "hippopotamus", "cactus", ); # CLASSICAL "..us" -> "..us" (ASSIMILATED 4TH DECLENSION LATIN NOUNS) my $PL_sb_C_us_us = enclose join "|", ( "status", "apparatus", "prospectus", "sinus", "hiatus", "impetus", "plexus", ); # UNCONDITIONAL "..on" -> "a" my $PL_sb_U_on_a = enclose join "|", map { substr($_,0,-2) } ( "criterion", "perihelion", "aphelion", "phenomenon", "prolegomenon", "noumenon", "organon", "asyndeton", "hyperbaton", "legomenon", ); # CLASSICAL "..on" -> "..a" my $PL_sb_C_on_a = enclose join "|", map { substr($_,0,-2) } ( "oxymoron", ); # CLASSICAL "..o" -> "..i" (BUT NORMALLY -> "..os") my @PL_sb_C_o_i = ( "solo", "soprano", "basso", "alto", "contralto", "tempo", "piano", "virtuoso", ); my $PL_sb_C_o_i = enclose join "|", map { substr($_,0,-1) } @PL_sb_C_o_i; # ALWAYS "..o" -> "..os" my $PL_sb_U_o_os = enclose join "|", ( "^ado", "aficionado", "aggro", "albino", "allegro", "ammo", "Antananarivo", "archipelago", "armadillo", "auto", "avocado", "Bamako", "Barquisimeto", "bimbo", "bingo", "Biro", "bolero", "Bolzano", "bongo", "Boto", "burro", "Cairo", "canto", "cappuccino", "casino", "cello", "Chicago", "Chimango", "cilantro", "cochito", "coco", "Colombo", "Colorado", "commando", "concertino", "contango", "credo", "crescendo", "cyano", "demo", "ditto", "Draco", "dynamo", "embryo", "Esperanto", "espresso", "euro", "falsetto", "Faro", "fiasco", "Filipino", "flamenco", "furioso", "generalissimo", "Gestapo", "ghetto", "gigolo", "gizmo", "Greensboro", "gringo", "Guaiabero", "guano", "gumbo", "gyro", "hairdo", "hippo", "Idaho", "impetigo", "inferno", "info", "intermezzo", "intertrigo", "Iquico", "^ISO", "jumbo", "junto", "Kakapo", "kilo", "Kinkimavo", "Kokako", "Kosovo", "Lesotho", "libero", "libido", "libretto", "lido", "Lilo", "limbo", "limo", "lineno", "lingo", "lino", "livedo", "loco", "logo", "lumbago", "macho", "macro", "mafioso", "magneto", "magnifico", "Majuro", "Malabo", "manifesto", "Maputo", "Maracaibo", "medico", "memo", "metro", "Mexico", "micro", "Milano", "Monaco", "mono", "Montenegro", "Morocco", "Muqdisho", "myo", "^NATO", "^NCO", "neutrino", "^NGO", "Ningbo", "octavo", "oregano", "Orinoco", "Orlando", "Oslo", "^oto", "panto", "Paramaribo", "Pardusco", "pedalo", "photo", "pimento", "pinto", "pleco", "Pluto", "pogo", "polo", "poncho", "Porto-Novo", "Porto", "pro", "psycho", "pueblo", "quarto", "Quito", "rhino", "risotto", "rococo", "rondo", "Sacramento", "saddo", "sago", "salvo", "Santiago", "Sapporo", "Sarajevo", "scherzando", "scherzo", "silo", "sirocco", "sombrero", "staccato", "sterno", "stucco", "stylo", "sumo", "Taiko", "techno", "terrazzo", "testudo", "timpano", "tiro", "tobacco", "Togo", "Tokyo", "torero", "Torino", "Toronto", "torso", "tremolo", "typo", "tyro", "ufo", "UNESCO", "vaquero", "vermicello", "verso", "vibrato", "violoncello", "Virgo", "weirdo", "WHO", "WTO", "Yamoussoukro", "yo-yo", "zero", "Zibo", @PL_sb_C_o_i, ); # UNCONDITIONAL "..ch" -> "..chs" my $PL_sb_U_ch_chs = enclose join "|", map { substr($_,0,-2) } qw( czech eunuch stomach ); # UNCONDITIONAL "..[ei]x" -> "..ices" my $PL_sb_U_ex_ices = enclose join "|", map { substr($_,0,-2) } ( "codex", "murex", "silex", ); my $PL_sb_U_ix_ices = enclose join "|", map { substr($_,0,-2) } ( "radix", "helix", ); # CLASSICAL "..[ei]x" -> "..ices" my $PL_sb_C_ex_ices = enclose join "|", map { substr($_,0,-2) } ( "vortex", "vertex", "cortex", "latex", "pontifex", "apex", "index", "simplex", ); my $PL_sb_C_ix_ices = enclose join "|", map { substr($_,0,-2) } ( "appendix", ); # ARABIC: ".." -> "..i" my $PL_sb_C_i = enclose join "|", ( "afrit", "afreet", "efreet", ); # HEBREW: ".." -> "..im" my $PL_sb_C_im = enclose join "|", ( "goy", "seraph", "cherub", "zuz", "kibbutz", ); # UNCONDITIONAL "..man" -> "..mans" my $PL_sb_U_man_mans = enclose join "|", qw( \bataman caiman cayman ceriman \bdesman \bdolman \bfarman \bharman \bhetman human \bleman ottoman shaman talisman Alabaman Bahaman Burman German Hiroshiman Liman Nakayaman Norman Oklahoman Panaman Roman Selman Sonaman Tacoman Yakiman Yokohaman Yuman ); my @PL_sb_uninflected_s = ( # PAIRS OR GROUPS SUBSUMED TO A SINGULAR... "breeches", "britches", "pajamas", "pyjamas", "clippers", "gallows", "hijinks", "headquarters", "pliers", "scissors", "testes", "herpes", "pincers", "shears", "proceedings", "trousers", # UNASSIMILATED LATIN 4th DECLENSION "cantus", "coitus", "nexus", # RECENT IMPORTS... "contretemps", "corps", "debris", ".*ois", "siemens", # DISEASES ".*measles", "mumps", # MISCELLANEOUS OTHERS... "diabetes", "jackanapes", ".*series", "species", "rabies", "chassis", "innings", "news", "mews", "haggis", ); my $PL_sb_uninflected_herd = enclose join "|", # DON'T INFLECT IN CLASSICAL MODE, OTHERWISE NORMAL INFLECTION ( "wildebeest", "swine", "eland", "bison", "buffalo", "elk", "rhinoceros", 'zucchini', 'caribou', 'dace', 'grouse', 'guinea[- ]fowl', 'haddock', 'hake', 'halibut', 'herring', 'mackerel', 'pickerel', 'pike', 'roe', 'seed', 'shad', 'snipe', 'teal', 'turbot', 'water[- ]fowl', ); my $PL_sb_lese_lesen = enclose join "|", ( 'Auslese', 'beerenauslese', 'Spaetlese', 'trockenbeerenauslese', ); my $PL_sb_uninflected = enclose join "|", ( # SOME FISH AND HERD ANIMALS ".*fish", "tuna", "salmon", "mackerel", "trout", "bream", "sea[- ]bass", "carp", "cod", "flounder", "whiting", ".*deer", ".*sheep", "moose", # ALL NATIONALS ENDING IN -ese "Portuguese", "Amoyese", "Borghese", "Congoese", "Faroese", "Foochowese", "Genevese", "Genoese", "Gilbertese", "Hottentotese", "Kiplingese", "Kongoese", "Lucchese", "Maltese", "Nankingese", "Niasese", "Pekingese", "Piedmontese", "Pistoiese", "Sarawakese", "Shavese", "Vermontese", "Wenchowese", "Yengeese", ".*[nrlm]ese", # SOME WORDS ENDING IN ...s (OFTEN PAIRS TAKEN AS A WHOLE) @PL_sb_uninflected_s, # DISEASES ".*pox", # OTHER ODDITIES "graffiti", "djinn", 'samuri', '.*craft$', 'offspring', 'pence', 'quid', 'hertz', ); # SINGULAR WORDS ENDING IN ...s (ALL INFLECT WITH ...es) my $PL_sb_singular_s = enclose join '|', ( ".*ss", "acropolis", "aegis", "alias", "asbestos", "bathos", "bias", "bronchitis", "bursitis", "caddis", "cannabis", "canvas", "chaos", "cosmos", "dais", "digitalis", "epidermis", "ethos", "eyas", "gas", "glottis", "hubris", "ibis", "lens", "mantis", "marquis", "metropolis", "pathos", "pelvis", "polis", "rhinoceros", "sassafras", "trellis", ".*us", "[A-Z].*es", @PL_sb_C_is_ides, @PL_sb_U_is_ides, ); my $PL_v_special_s = enclose join '|', ( $PL_sb_singular_s, @PL_sb_uninflected_s, keys %PL_sb_irregular_s, '(.*[csx])is', '(.*)ceps', '[A-Z].*s', ); my %PL_sb_postfix_adj = ( 'general' => ['(?!major|lieutenant|brigadier|adjutant|.*star)\S+'], 'martial' => [qw(court)], ); foreach (keys %PL_sb_postfix_adj) { $PL_sb_postfix_adj{$_} = enclose enclose(join('|', @{$PL_sb_postfix_adj{$_}})) . "(?=(?:-|\\s+)$_)"; } my $PL_sb_postfix_adj = '(' . join('|', values %PL_sb_postfix_adj) . ')(.*)'; my $PL_prep = enclose join '|', qw ( about above across after against amid amidst among around as at athwart atop barring before behind below beneath beside besides between betwixt beyond but by circa despite down during except failing for from given in inside into like minus near next of off on onto out outside over pace past per plus pro qua round sans save since than through throughout thru thruout till times to toward towards under underneath unlike until unto up upon versus via vs with within without worth ); my $PL_sb_prep_dual_compound = '(.*?)((?:-|\s+)(?:'.$PL_prep.'|d[eua])(?:-|\s+))a(?:-|\s+)(.*)'; my $PL_sb_prep_compound = '(.*?)((-|\s+)('.$PL_prep.'|d[eua])((-|\s+)(.*))?)'; my %PL_pron_nom = ( # NOMINATIVE REFLEXIVE "i" => "we", "myself" => "ourselves", "you" => "you", "yourself" => "yourselves", "she" => "they", "herself" => "themselves", "he" => "they", "himself" => "themselves", "it" => "they", "itself" => "themselves", "they" => "they", "themself" => "themselves", # POSSESSIVE "mine" => "ours", "yours" => "yours", "hers" => "theirs", "his" => "theirs", "its" => "theirs", "theirs" => "theirs", ); my %PL_pron_acc = ( # ACCUSATIVE REFLEXIVE "me" => "us", "myself" => "ourselves", "you" => "you", "yourself" => "yourselves", "her" => "them", "herself" => "themselves", "him" => "them", "himself" => "themselves", "it" => "them", "itself" => "themselves", "them" => "them", "themself" => "themselves", ); my $PL_pron_acc = enclose join '|', keys %PL_pron_acc; my %PL_v_irregular_pres = ( # 1st PERS. SING. 2ND PERS. SING. 3RD PERS. SINGULAR # 3RD PERS. (INDET.) "am" => "are", "are" => "are", "is" => "are", "was" => "were", "were" => "were", "was" => "were", "have" => "have", "have" => "have", "has" => "have", "do" => "do", "do" => "do", "does" => "do", ); my $PL_v_irregular_pres = enclose join '|', keys %PL_v_irregular_pres; my %PL_v_ambiguous_pres = ( # 1st PERS. SING. 2ND PERS. SING. 3RD PERS. SINGULAR # 3RD PERS. (INDET.) "act" => "act", "act" => "act", "acts" => "act", "blame" => "blame", "blame" => "blame", "blames" => "blame", "can" => "can", "can" => "can", "can" => "can", "must" => "must", "must" => "must", "must" => "must", "fly" => "fly", "fly" => "fly", "flies" => "fly", "copy" => "copy", "copy" => "copy", "copies" => "copy", "drink" => "drink", "drink" => "drink", "drinks" => "drink", "fight" => "fight", "fight" => "fight", "fights" => "fight", "fire" => "fire", "fire" => "fire", "fires" => "fire", "like" => "like", "like" => "like", "likes" => "like", "look" => "look", "look" => "look", "looks" => "look", "make" => "make", "make" => "make", "makes" => "make", "reach" => "reach", "reach" => "reach", "reaches" => "reach", "run" => "run", "run" => "run", "runs" => "run", "sink" => "sink", "sink" => "sink", "sinks" => "sink", "sleep" => "sleep", "sleep" => "sleep", "sleeps" => "sleep", "view" => "view", "view" => "view", "views" => "view", ); my $PL_v_ambiguous_pres = enclose join '|', keys %PL_v_ambiguous_pres; my $PL_v_irregular_non_pres = enclose join '|', ( "did", "had", "ate", "made", "put", "spent", "fought", "sank", "gave", "sought", "shall", "could", "ought", "should", ); my $PL_v_ambiguous_non_pres = enclose join '|', ( "thought", "saw", "bent", "will", "might", "cut", ); # "..oes" -> "..oe" (the rest are "..oes" -> "o") my $PL_v_oes_oe = enclose join "|", qw( .*shoes .*hoes .*toes canoes floes oboes roes throes woes ); my $PL_count_zero = enclose join '|', ( 0, "no", "zero", "nil" ); my $PL_count_one = enclose join '|', ( 1, "a", "an", "one", "each", "every", "this", "that", ); my %PL_adj_special = ( "a" => "some", "an" => "some", "this" => "these", "that" => "those", ); my $PL_adj_special = enclose join '|', keys %PL_adj_special; my %PL_adj_poss = ( "my" => "our", "your" => "your", "its" => "their", "her" => "their", "his" => "their", "their" => "their", ); my $PL_adj_poss = enclose join '|', keys %PL_adj_poss; sub checkpat { local $SIG{__WARN__} = sub {0}; do {$@ =~ s/at.*?$//; die "\nBad user-defined singular pattern:\n\t$@\n"} if (!eval "'' =~ m/$_[0]/; 1;" or $@); return @_; } sub checkpatsubs { checkpat($_[0]); if (defined $_[1]) { local $SIG{__WARN__} = sub {0}; do {$@ =~ s/at.*?$//; die "\nBad user-defined plural string: '$_[1]'\n\t$@\n"} if (!eval "qq{$_[1]}; 1;" or $@); } return @_; } my @PL_sb_user_defined = (); my @PL_v_user_defined = (); my @PL_adj_user_defined = (); my @A_a_user_defined = (); sub def_noun { unshift @PL_sb_user_defined, checkpatsubs(@_); return 1; } sub def_verb { unshift @PL_v_user_defined, checkpatsubs(@_[4,5]); unshift @PL_v_user_defined, checkpatsubs(@_[2,3]); unshift @PL_v_user_defined, checkpatsubs(@_[0,1]); return 1; } sub def_adj { unshift @PL_adj_user_defined, checkpatsubs(@_); return 1; } sub def_a { unshift @A_a_user_defined, checkpat(@_,'a'); return 1; } sub def_an { unshift @A_a_user_defined, checkpat(@_,'an'); return 1; } sub ud_match { my $word = shift; for (my $i=0; $i < @_; $i+=2) { if ($word =~ /^(?:$_[$i])$/i) { last unless defined $_[$i+1]; return eval '"'.$_[$i+1].'"'; } } return undef; } do { local $SIG{__WARN__} = sub {0}; my $rcfile; $rcfile = $INC{'Lingua//EN/Inflect.pm'} || ''; $rcfile =~ s/Inflect.pm$/.inflectrc/; do $rcfile or die "\nBad .inflectrc file ($rcfile):\n\t$@\n" if $rcfile && -r $rcfile && -s $rcfile; $rcfile = "$ENV{HOME}/.inflectrc" || ''; do $rcfile or die "\nBad .inflectrc file ($rcfile):\n\t$@\n" if $rcfile && -r $rcfile && -s $rcfile; }; sub postprocess # FIX PEDANTRY AND CAPITALIZATION :-) { my ($orig, $inflected) = @_; $inflected =~ s/([^|]+)\|(.+)/ $classical{all}?$2:$1 /e; return $orig =~ /^I$/ ? $inflected : $orig =~ /^[A-Z]+$/ ? uc $inflected : $orig =~ /^[A-Z]/ ? ucfirst $inflected : $inflected; } sub PL # PL($word,$number) { my ($str, $count) = @_; my ($pre, $word, $post) = ($str =~ m/\A(\s*)(.+?)(\s*)\Z/); return $str unless $word; my $plural = postprocess $word, _PL_special_adjective($word,$count) || _PL_special_verb($word,$count) || _PL_noun($word,$count); return $pre.$plural.$post; } sub PL_N # PL_N($word,$number) { my ($str, $count) = @_; my ($pre, $word, $post) = ($str =~ m/\A(\s*)(.+?)(\s*)\Z/); return $str unless $word; my $plural = postprocess $word, _PL_noun($word,$count); return $pre.$plural.$post; } sub PL_V # PL_V($word,$number) { my ($str, $count) = @_; my ($pre, $word, $post) = ($str =~ m/\A(\s*)(.+?)(\s*)\Z/); return $str unless $word; my $plural = postprocess $word, _PL_special_verb($word,$count) || _PL_general_verb($word,$count); return $pre.$plural.$post; } sub PL_ADJ # PL_ADJ($word,$number) { my ($str, $count) = @_; my ($pre, $word, $post) = ($str =~ m/\A(\s*)(.+?)(\s*)\Z/); return $str unless $word; my $plural = postprocess $word, _PL_special_adjective($word,$count) || $word; return $pre.$plural.$post; } sub PL_eq { _PL_eq(@_, \&PL_N) || _PL_eq(@_, \&PL_V) || _PL_eq(@_, \&PL_ADJ); } sub PL_N_eq { _PL_eq(@_, \&PL_N); } sub PL_V_eq { _PL_eq(@_, \&PL_V); } sub PL_ADJ_eq { _PL_eq(@_, \&PL_ADJ); } sub _PL_eq { my ( $word1, $word2, $PL ) = @_; my %classval = %classical; %classical = %all_classical; my $result = ""; $result = "eq" if !$result && $word1 eq $word2; $result = "p:s" if !$result && $word1 eq &$PL($word2); $result = "s:p" if !$result && &$PL($word1) eq $word2; %classical = (); $result = "p:s" if !$result && $word1 eq &$PL($word2); $result = "s:p" if !$result && &$PL($word1) eq $word2; %classical = %classval; if ($PL == \&PL || $PL == \&PL_N) { $result = "p:p" if !$result && _PL_check_plurals_N($word1,$word2); $result = "p:p" if !$result && _PL_check_plurals_N($word2,$word1); } if ($PL == \&PL || $PL == \&PL_ADJ) { $result = "p:p" if !$result && _PL_check_plurals_ADJ($word1,$word2,$PL); } return $result; } sub _PL_reg_plurals { $_[0] =~ /($_[1])($_[2]\|\1$_[3]|$_[3]\|\1$_[2])/ } sub _PL_check_plurals_N { my $pair = "$_[0]|$_[1]"; foreach ( values %PL_sb_irregular_s ) { return 1 if $_ eq $pair; } foreach ( values %PL_sb_irregular ) { return 1 if $_ eq $pair; } return 1 if _PL_reg_plurals($pair, $PL_sb_U_a_ata, "as","ata") || _PL_reg_plurals($pair, $PL_sb_C_a_ata, "as","ata") || _PL_reg_plurals($pair, $PL_sb_U_is_ides, "is","ides") || _PL_reg_plurals($pair, $PL_sb_C_is_ides, "is","ides") || _PL_reg_plurals($pair, $PL_sb_C_a_ae, "s","e") || _PL_reg_plurals($pair, $PL_sb_C_en_ina, "ens","ina") || _PL_reg_plurals($pair, $PL_sb_C_um_a, "ums","a") || _PL_reg_plurals($pair, $PL_sb_C_us_i, "uses","i") || _PL_reg_plurals($pair, $PL_sb_C_on_a, "ons","a") || _PL_reg_plurals($pair, $PL_sb_C_o_i, "os","i") || _PL_reg_plurals($pair, $PL_sb_C_ex_ices, "exes","ices") || _PL_reg_plurals($pair, $PL_sb_C_ix_ices, "ixes","ices") || _PL_reg_plurals($pair, $PL_sb_C_i, "s","i") || _PL_reg_plurals($pair, $PL_sb_C_im, "s","im") || _PL_reg_plurals($pair, '.*eau', "s","x") || _PL_reg_plurals($pair, '.*ieu', "s","x") || _PL_reg_plurals($pair, '.*tri', "xes","ces") || _PL_reg_plurals($pair, '.{2,}[yia]n', "xes","ges"); return 0; } sub _PL_check_plurals_ADJ { my ( $word1a, $word2a ) = @_; my ( $word1b, $word2b ) = @_; $word1a = '' unless $word1a =~ s/'s?$//; $word2a = '' unless $word2a =~ s/'s?$//; $word1b = '' unless $word1b =~ s/s'$//; $word2b = '' unless $word2b =~ s/s'$//; if ($word1a) { return 1 if $word2a && ( _PL_check_plurals_N($word1a, $word2a) || _PL_check_plurals_N($word2a, $word1a) ); return 1 if $word2b && ( _PL_check_plurals_N($word1a, $word2b) || _PL_check_plurals_N($word2b, $word1a) ); } if ($word1b) { return 1 if $word2a && ( _PL_check_plurals_N($word1b, $word2a) || _PL_check_plurals_N($word2a, $word1b) ); return 1 if $word2b && ( _PL_check_plurals_N($word1b, $word2b) || _PL_check_plurals_N($word2b, $word1b) ); } return ""; } sub _PL_noun { my ( $word, $count ) = @_; my $value; # UTILITY VARIABLE # DEFAULT TO PLURAL $count = $persistent_count if !defined($count) && defined($persistent_count); $count = (defined $count and $count=~/^($PL_count_one)$/io or defined $count and $classical{zero} and $count=~/^($PL_count_zero)$/io) ? 1 : 2; return $word if $count==1; # HANDLE USER-DEFINED NOUNS return $value if defined($value = ud_match($word, @PL_sb_user_defined)); # HANDLE EMPTY WORD, SINGULAR COUNT AND UNINFLECTED PLURALS $word eq '' and return $word; $word =~ /^($PL_sb_uninflected)$/i && !exists $PL_sb_irregular{$word} && $word !~ /^($PL_sb_lese_lesen)$/i and return $word; $classical{herd} and $word =~ /^($PL_sb_uninflected_herd)$/i and return $word; # HANDLE ISOLATED IRREGULAR PLURALS $word =~ /^($PL_sb_irregular)$/i and return ( $PL_sb_irregular{$1} || $PL_sb_irregular{lc $1} ); $word =~ /(.*)\b($PL_sb_irregular)$/i and return $1 . ( $PL_sb_irregular{$2} || $PL_sb_irregular{lc $2} ); # HANDLE COMPOUNDS ("Governor General", "mother-in-law", "aide-de-camp", ETC.) $word =~ /^(?:$PL_sb_postfix_adj)$/i and $value = $2 and return _PL_noun($1,2) . $value; $word =~ /^(?:$PL_sb_prep_dual_compound)$/i and $value = [$2,$3] and return _PL_noun($1,2) . $value->[0] . _PL_noun($value->[1]); $word =~ /^(?:$PL_sb_prep_compound)$/i and $value = $2 and return _PL_noun($1,2) . $value; # HANDLE PRONOUNS $word =~ /^((?:$PL_prep)\s+)($PL_pron_acc)$/i and return $1.$PL_pron_acc{lc($2)}; $value = $PL_pron_nom{lc($word)} and return $value; $word =~ /^($PL_pron_acc)$/i and return $PL_pron_acc{lc($1)}; # HANDLE FAMILIES OF IRREGULAR PLURALS $word =~ /(.*$PL_sb_U_man_mans)$/i and return "$1s"; $word =~ /(\S*)quy$/i and return "$1quies"; $word =~ /(\S*)(person)$/i and return $classical{persons}?"$1persons":"$1people"; $word =~ /(.*)man$/i and return "$1men"; $word =~ /(.*[ml])ouse$/i and return "$1ice"; $word =~ /(.*)goose$/i and return "$1geese"; $word =~ /(.*)tooth$/i and return "$1teeth"; $word =~ /(.*)foot$/i and return "$1feet"; # HANDLE UNASSIMILATED IMPORTS $word =~ /(.*)ceps$/i and return $word; $word =~ /(.*)zoon$/i and return "$1zoa"; $word =~ /(.*[csx])is$/i and return "$1es"; $word =~ /(.*$PL_sb_U_a_ata)a$/i and return "$1ata"; $word =~ /(.*$PL_sb_U_is_ides)is$/i and return "$1ides"; $word =~ /(.*$PL_sb_U_ch_chs)ch$/i and return "$1chs"; $word =~ /(.*$PL_sb_U_ex_ices)ex$/i and return "$1ices"; $word =~ /(.*$PL_sb_U_ix_ices)ix$/i and return "$1ices"; $word =~ /(.*$PL_sb_U_um_a)um$/i and return "$1a"; $word =~ /(.*$PL_sb_U_us_i)us$/i and return "$1i"; $word =~ /(.*$PL_sb_U_on_a)on$/i and return "$1a"; $word =~ /(.*$PL_sb_U_a_ae)$/i and return "$1e"; $word =~ /(.*$PL_sb_lese_lesen)$/i and return "$1n"; # HANDLE INCOMPLETELY ASSIMILATED IMPORTS if ($classical{ancient}) { $word =~ /(.*)trix$/i and return "$1trices"; $word =~ /(.*)eau$/i and return "$1eaux"; $word =~ /(.*)ieu$/i and return "$1ieux"; $word =~ /(.{2,}[yia])nx$/i and return "$1nges"; $word =~ /(.*$PL_sb_C_en_ina)en$/i and return "$1ina"; $word =~ /(.*$PL_sb_C_ex_ices)ex$/i and return "$1ices"; $word =~ /(.*$PL_sb_C_ix_ices)ix$/i and return "$1ices"; $word =~ /(.*$PL_sb_C_um_a)um$/i and return "$1a"; $word =~ /(.*$PL_sb_C_us_i)us$/i and return "$1i"; $word =~ /(.*$PL_sb_C_us_us)$/i and return "$1"; $word =~ /(.*$PL_sb_C_a_ae)$/i and return "$1e"; $word =~ /(.*$PL_sb_C_a_ata)a$/i and return "$1ata"; $word =~ /(.*$PL_sb_C_is_ides)is$/i and return "$1ides"; $word =~ /(.*$PL_sb_C_o_i)o$/i and return "$1i"; $word =~ /(.*$PL_sb_C_on_a)on$/i and return "$1a"; $word =~ /$PL_sb_C_im$/i and return "${word}im"; $word =~ /$PL_sb_C_i$/i and return "${word}i"; } # HANDLE SINGULAR NOUNS ENDING IN ...s OR OTHER SILIBANTS $word =~ /^($PL_sb_singular_s)$/i and return "$1es"; $word =~ /^([A-Z].*s)$/ and $classical{names} and return "$1es"; $word =~ /^($PL_sb_z_zes)$/i and return "$1es"; $word =~ /^(.*[^z])(z)$/i and return "$1zzes"; $word =~ /^(.*)([cs]h|x|zz|ss)$/i and return "$1$2es"; # $word =~ /(.*)(us)$/i and return "$1$2es"; # HANDLE ...f -> ...ves $word =~ /(.*[eao])lf$/i and return "$1lves"; $word =~ /(.*[^d])eaf$/i and return "$1eaves"; $word =~ /(.*[nlw])ife$/i and return "$1ives"; $word =~ /(.*)arf$/i and return "$1arves"; # HANDLE ...y $word =~ /(.*[aeiou])y$/i and return "$1ys"; $word =~ /([A-Z].*y)$/ and $classical{names} and return "$1s"; $word =~ /(.*)y$/i and return "$1ies"; # HANDLE ...o $word =~ /$PL_sb_U_o_os$/i and return "${word}s"; $word =~ /[aeiou]o$/i and return "${word}s"; $word =~ /o$/i and return "${word}es"; # OTHERWISE JUST ADD ...s return "${word}s"; } sub _PL_special_verb { my ( $word, $count ) = @_; $count = $persistent_count if !defined($count) && defined($persistent_count); $count = (defined $count and $count=~/^($PL_count_one)$/io or defined $count and $classical{zero} and $count=~/^($PL_count_zero)$/io) ? 1 : 2; return undef if $count=~/^($PL_count_one)$/io; my $value; # UTILITY VARIABLE # HANDLE USER-DEFINED VERBS return $value if defined($value = ud_match($word, @PL_v_user_defined)); # HANDLE IRREGULAR PRESENT TENSE (SIMPLE AND COMPOUND) $word =~ /^($PL_v_irregular_pres)((\s.*)?)$/i and return $PL_v_irregular_pres{lc $1}.$2; # HANDLE IRREGULAR FUTURE, PRETERITE AND PERFECT TENSES $word =~ /^($PL_v_irregular_non_pres)((\s.*)?)$/i and return $word; # HANDLE PRESENT NEGATIONS (SIMPLE AND COMPOUND) $word =~ /^($PL_v_irregular_pres)(n't(\s.*)?)$/i and return $PL_v_irregular_pres{lc $1}.$2; $word =~ /^\S+n't\b/i and return $word; # HANDLE SPECIAL CASES $word =~ /^($PL_v_special_s)$/ and return undef; $word =~ /\s/ and return undef; $word =~ /^quizzes$/i and return "quiz"; # HANDLE STANDARD 3RD PERSON (CHOP THE ...(e)s OFF SINGLE WORDS) $word =~ /^(.*)([cs]h|[x]|zz|ss)es$/i and return "$1$2"; $word =~ /^(..+)ies$/i and return "$1y"; $word =~ /($PL_v_oes_oe)$/ and return substr($1,0,-1); $word =~ /^(.+)oes$/i and return "$1o"; $word =~ /^(.*[^s])s$/i and return $1; # OTHERWISE, A REGULAR VERB (HANDLE ELSEWHERE) return undef; } sub _PL_general_verb { my ( $word, $count ) = @_; $count = $persistent_count if !defined($count) && defined($persistent_count); $count = (defined $count and $count=~/^($PL_count_one)$/io or defined $count and $classical{zero} and $count=~/^($PL_count_zero)$/io) ? 1 : 2; return $word if $count=~/^($PL_count_one)$/io; # HANDLE AMBIGUOUS PRESENT TENSES (SIMPLE AND COMPOUND) $word =~ /^($PL_v_ambiguous_pres)((\s.*)?)$/i and return $PL_v_ambiguous_pres{lc $1}.$2; # HANDLE AMBIGUOUS PRETERITE AND PERFECT TENSES $word =~ /^($PL_v_ambiguous_non_pres)((\s.*)?)$/i and return $word; # OTHERWISE, 1st OR 2ND PERSON IS UNINFLECTED return $word; } sub _PL_special_adjective { my ( $word, $count ) = @_; $count = $persistent_count if !defined($count) && defined($persistent_count); $count = (defined $count and $count=~/^($PL_count_one)$/io or defined $count and $classical{zero} and $count=~/^($PL_count_zero)$/io) ? 1 : 2; return $word if $count=~/^($PL_count_one)$/io; # HANDLE USER-DEFINED ADJECTIVES my $value; return $value if defined($value = ud_match($word, @PL_adj_user_defined)); # HANDLE KNOWN CASES $word =~ /^($PL_adj_special)$/i and return $PL_adj_special{lc $1}; # HANDLE POSSESSIVES $word =~ /^($PL_adj_poss)$/i and return $PL_adj_poss{lc $1}; $word =~ /^(.*)'s?$/ and do { my $pl = PL_N($1); return "$pl'" . ($pl =~ m/s$/ ? "" : "s"); }; # OTHERWISE, NO IDEA return undef; } # 2. INDEFINITE ARTICLES # THIS PATTERN MATCHES STRINGS OF CAPITALS STARTING WITH A "VOWEL-SOUND" # CONSONANT FOLLOWED BY ANOTHER CONSONANT, AND WHICH ARE NOT LIKELY # TO BE REAL WORDS (OH, ALL RIGHT THEN, IT'S JUST MAGIC!) my $A_abbrev = q{ (?! FJO | [HLMNS]Y. | RY[EO] | SQU | ( F[LR]? | [HL] | MN? | N | RH? | S[CHKLMNPTVW]? | X(YL)?) [AEIOU]) [FHLMNRSX][A-Z] }; # THIS PATTERN CODES THE BEGINNINGS OF ALL ENGLISH WORDS BEGINING WITH A # 'y' FOLLOWED BY A CONSONANT. ANY OTHER Y-CONSONANT PREFIX THEREFORE # IMPLIES AN ABBREVIATION. my $A_y_cons = 'y(b[lor]|cl[ea]|fere|gg|p[ios]|rou|tt)'; # EXCEPTIONS TO EXCEPTIONS my $A_explicit_an = enclose join '|', ( "euler", "hour(?!i)", "heir", "honest", "hono", ); my $A_ordinal_an = enclose join '|', ( "[aefhilmnorsx]-?th", ); my $A_ordinal_a = enclose join '|', ( "[bcdgjkpqtuvwyz]-?th", ); sub A { my ($str, $count) = @_; my ($pre, $word, $post) = ( $str =~ m/\A(\s*)(?:an?\s+)?(.+?)(\s*)\Z/i ); return $str unless $word; my $result = _indef_article($word,$count); return $pre.$result.$post; } sub AN { goto &A } sub _indef_article { my ( $word, $count ) = @_; $count = $persistent_count if !defined($count) && defined($persistent_count); return "$count $word" if defined $count && $count!~/^($PL_count_one)$/io; # HANDLE USER-DEFINED VARIANTS my $value; return "$value $word" if defined($value = ud_match($word, @A_a_user_defined)); # HANDLE ORDINAL FORMS $word =~ /^($A_ordinal_a)/i and return "a $word"; $word =~ /^($A_ordinal_an)/i and return "an $word"; # HANDLE SPECIAL CASES $word =~ /^($A_explicit_an)/i and return "an $word"; $word =~ /^[aefhilmnorsx]$/i and return "an $word"; $word =~ /^[bcdgjkpqtuvwyz]$/i and return "a $word"; # HANDLE ABBREVIATIONS $word =~ /^($A_abbrev)/ox and return "an $word"; $word =~ /^[aefhilmnorsx][.-]/i and return "an $word"; $word =~ /^[a-z][.-]/i and return "a $word"; # HANDLE CONSONANTS $word =~ /^[^aeiouy]/i and return "a $word"; # HANDLE SPECIAL VOWEL-FORMS $word =~ /^e[uw]/i and return "a $word"; $word =~ /^onc?e\b/i and return "a $word"; $word =~ /^uni([^nmd]|mo)/i and return "a $word"; $word =~ /^ut[th]/i and return "an $word"; $word =~ /^u[bcfhjkqrst][aeiou]/i and return "a $word"; # HANDLE SPECIAL CAPITALS $word =~ /^U[NK][AIEO]?/ and return "a $word"; # HANDLE VOWELS $word =~ /^[aeiou]/i and return "an $word"; # HANDLE y... (BEFORE CERTAIN CONSONANTS IMPLIES (UNNATURALIZED) "i.." SOUND) $word =~ /^($A_y_cons)/io and return "an $word"; # OTHERWISE, GUESS "a" return "a $word"; } # 2. TRANSLATE ZERO-QUANTIFIED $word TO "no PL($word)" sub NO { my ($str, $count, $opt_ref) = @_; my ($pre, $word, $post) = ($str =~ m/\A(\s*)(.+?)(\s*)\Z/); $count = $persistent_count if !defined($count) && defined($persistent_count); $count = 0 unless $count; if ($count =~ /^$PL_count_zero$/) { return "${pre}no ". PL($word,0) . $post ; } $count = defined $opt_ref->{words_below} && $count < $opt_ref->{words_below} ? NUMWORDS($count) : $count; if (defined $opt_ref->{comma} || defined $opt_ref->{comma_every}) { $opt_ref->{comma_every} = 3 if !defined $opt_ref->{comma_every}; $opt_ref->{comma} = ',' if !defined $opt_ref->{comma} || $opt_ref->{comma} =~ /^\d+$/; $count = _commify($count, @{$opt_ref}{'comma','comma_every'}); } return "$pre$count " . PL($word,$count) . $post } sub _commify { my ($number, $comma, $every) = @_; return if !defined $comma; return if !defined $comma; $number =~ s{(?:(?<=^)|(?<=^-))(\d\d{$every,})} { my $n = $1; $n=~s/(?<=.)(?=(?:.{$every})+$)/$comma/g; $n; }e; return $number; } # PARTICIPLES sub PART_PRES { local $_ = PL_V(shift,2); s/ie$/y/ or s/ue$/u/ or s/([auy])e$/$1/ or s/ski$/ski/ or s/[^b]i$// or s/^(are|were)$/be/ or s/^(had)$/hav/ or s/(hoe)$/$1/ or s/([^e])e$/$1/ or m/er$/ or s/([^aeiou][aeiouy]([bdgmnprst]))$/$1$2/; return "${_}ing"; } # NUMERICAL INFLECTIONS my %nth = ( 0 => 'th', 1 => 'st', 2 => 'nd', 3 => 'rd', 4 => 'th', 5 => 'th', 6 => 'th', 7 => 'th', 8 => 'th', 9 => 'th', 11 => 'th', 12 => 'th', 13 => 'th', ); my %ordinal; @ordinal{qw(ty one two three five eight nine twelve )}= qw(tieth first second third fifth eighth ninth twelfth); my $ordinal_suff = join '|', keys %ordinal, ""; $ordinal{""} = 'th'; sub ORD($) { my $num = shift; if ($num =~ /\d/) { return $num . ($nth{$num%100} || $nth{$num%10}); } else { $num =~ s/($ordinal_suff)\Z/$ordinal{$1}/; return $num; } } my %default_args = ( 'group' => 0, 'comma' => ',', 'and' => 'and', 'zero' => 'zero', 'one' => 'one', 'decimal' => 'point', ); my @unit = ('',qw(one two three four five six seven eight nine)); my @teen = qw(ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen); my @ten = ('','',qw(twenty thirty forty fifty sixty seventy eighty ninety)); my @mill = map { (my $val=$_) =~ s/_/illion/; " $val" } ('',qw(thousand m_ b_ tr_ quadr_ quint_ sext_ sept_ oct_ non_ dec_)); sub mill { my $ind = $_[0]||0; die "Number out of range\n" if $ind > $#mill; return $ind<@mill ? $mill[$ind] : ' ???illion'; } sub unit { return $unit[$_[0]]. mill($_[1]); } sub ten { return $ten[$_[0]] . ($_[0]&&$_[1]?'-':'') . $unit[$_[1]] . mill($_[2]) if $_[0] ne '1'; return $teen[$_[1]]. $mill[$_[2]||0]; } sub hund { return unit($_[0]) . " hundred" . ($_[1] || $_[2] ? " $_[4] " : '') . ten($_[1],$_[2]) . mill($_[3]) . ', ' if $_[0]; return ten($_[1],$_[2]) . mill($_[3]) . ', ' if $_[1] || $_[2]; return ''; } sub enword { my ($num,$group,$zero,$one,$comma,$and) = @_; if ($group==1) { $num =~ s/(\d)/ ($1==1 ? " $one" : $1 ? unit($1) :" $zero")."$comma " /eg; } elsif ($group==2) { $num =~ s/(\d)(\d)/ ($1 ? ten($1,$2) : $2 ? " $zero " . unit($2) : " $zero $zero") . "$comma " /eg; $num =~ s/(\d)/ ($1 ? unit($1) :" $zero")."$comma " /e; } elsif ($group==3) { $num =~ s/(\d)(\d)(\d)/ ($1==1 ? " $one" : $1 ? unit($1) :" $zero")." ".($2 ? ten($2,$3) : $3 ? " $zero " . unit($3) : " $zero $zero") . "$comma " /eg; $num =~ s/(\d)(\d)/ ($1 ? ten($1,$2) : $2 ? " $zero " . unit($2) : " $zero $zero") . "$comma " /e; $num =~ s/(\d)/ ($1==1 ? " $one" : $1 ? unit($1) :" $zero")."$comma " /e; } elsif ($num+0==0) { $num = $zero; } elsif ($num+0==1) { $num = $one; } else { $num =~ s/\A\s*0+//; my $mill = 0; 1 while $num =~ s/(\d)(\d)(\d)(?=\D*\Z)/ hund($1,$2,$3,$mill++,$and) /e; $num =~ s/(\d)(\d)(?=\D*\Z)/ ten($1,$2,$mill)."$comma " /e; $num =~ s/(\d)(?=\D*\Z)/ unit($1,$mill) . "$comma "/e; } return $num; } sub NUMWORDS { my $num = shift; if (@_ % 2 and require Carp) { die "Missing value in option list (odd number of option args) at" . join ' line ', (caller)[1,2]; } my %arg = ( %default_args, @_ ); my $group = $arg{group}; # Handle "stylistic" conversions (up to a given threshold)... if (exists $arg{threshold} && $num > $arg{threshold}) { my ($whole, $frac) = split /[.]/, $num; while ($arg{comma}) { $whole =~ s{ (\d) ( \d{3}(?:,|\z) ) }{$1,$2}xms or last; } return $frac ? "$whole.$frac" : $whole; } die "Bad chunking option: $group\n" unless $group =~ /\A[0-3]\Z/; my $sign = ($num =~ /\A\s*\+/) ? "plus" : ($num =~ /\A\s*\-/) ? "minus" : ''; my ($zero, $one) = @arg{'zero','one'}; my $comma = $arg{comma}; my $and = $arg{'and'}; my $ord = $num =~ s/(st|nd|rd|th)\Z//; my @chunks = ($arg{decimal}) ? $group ? split(/\./, $num) : split(/\./, $num, 2) : ($num); my $first = 1; if ($chunks[0] eq '') { $first=0; shift @chunks; } foreach ( @chunks ) { s/\D//g; $_ = '0' unless $_; if (!$group && !$first) { $_ = enword($_,1,$zero,$one,$comma,$and) } else { $_ = enword($_,$group,$zero,$one,$comma,$and) } s/, \Z//; s/\s+,/,/g; s/, (\S+)\s+\Z/ $and $1/ if !$group and $first; s/\s+/ /g; s/(\A\s|\s\Z)//g; $first = '' if $first; } my @numchunks = (); if ($first =~ /0/) { unshift @chunks, ''; } else { @numchunks = split /\Q$comma /, $chunks[0]; } $numchunks[-1] =~ s/($ordinal_suff)\Z/$ordinal{$1}/ if $ord and @numchunks; foreach (@chunks[1..$#chunks]) { push @numchunks, $arg{decimal}; push @numchunks, split /\Q$comma /; } if (wantarray) { unshift @numchunks, $sign if $sign; return @numchunks } elsif ($group) { return ($sign?"$sign ":'') . join ", ", @numchunks; } else { $num = ($sign?"$sign ":'') . shift @numchunks; $first = ($num !~ /$arg{decimal}\Z/); foreach ( @numchunks ) { if (/\A$arg{decimal}\Z/) { $num .= " $_"; $first = 0; } elsif ($first) { $num .= "$comma $_"; } else { $num .= " $_"; } } return $num; } } # Join words with commas and a trailing 'and' (when appropriate)... sub WORDLIST { my %opt; my @words; for my $arg (@_) { if (ref $arg eq 'HASH' ) { %opt = (%opt, %{$arg}); } else { push @words, $arg; } } return "" if @words == 0; return "$words[0]" if @words == 1; my $conj = exists($opt{conj}) ? $opt{conj} : 'and'; if (@words == 2) { $conj =~ s/^ (?=\S) | (?<=\S) $/ /gxms; return "$words[0]$conj$words[1]"; } my $sep = exists $opt{sep} ? $opt{sep} : grep(/,/, @words) ? q{; } : q{, } ; my $final_sep = !exists $opt{final_sep} ? "$sep $conj" : length($opt{final_sep}) == 0 ? $conj : "$opt{final_sep} $conj" ; $final_sep =~ s/\s+/ /gmxs; $final_sep =~ s/^ (?=[^\W\d_]) | (?<=\S) $/ /gxms; return join($sep, @words[0..@words-2]) . "$final_sep$words[-1]"; } 1; __END__ =head1 NAME Lingua::EN::Inflect - Convert singular to plural. Select "a" or "an". =head1 VERSION This document describes version 1.895 of Lingua::EN::Inflect =head1 SYNOPSIS 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), "\n"; # CONDITIONALLY FORM THE PLURAL print "I saw $cat_count ", PL("cat",$cat_count), "\n"; # FORM PLURALS FOR SPECIFIC PARTS OF SPEECH print PL_N("I",$N1), PL_V("saw",$N1), PL_ADJ("my",$N2), PL_N("saw",$N2), "\n"; # DEAL WITH "0/1/N" -> "no/1/N" TRANSLATION: print "There ", PL_V("was",$errors), NO(" error",$errors), "\n"; # USE DEFAULT COUNTS: print NUM($N1,""), PL("I"), PL_V(" saw"), NUM($N2), PL_N(" saw"); print "There ", NUM($errors,''), PL_V("was"), NO(" error"), "\n"; # COMPARE TWO WORDS "NUMBER-INSENSITIVELY": print "same\n" if PL_eq($word1, $word2); print "same noun\n" if PL_N_eq($word1, $word2); print "same verb\n" if PL_V_eq($word1, $word2); print "same adj.\n" if PL_ADJ_eq($word1, $word2); # ADD CORRECT "a" OR "an" FOR A GIVEN WORD: print "Did you want ", A($thing), " or ", AN($idea), "\n"; # CONVERT NUMERALS INTO ORDINALS (i.e. 1->1st, 2->2nd, 3->3rd, etc.) print "It was", ORD($position), " from the left\n"; # 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, 'and'=>''); # "one thousand, two hundred thirty-four" $words = NUMWORDS(1234, 'and'=>', plus'); # "one thousand, two hundred, plus thirty-four" $words = NUMWORDS(555_1202, group=>1, zero=>'oh'); # "five, five, five, one, two, oh, two" $words = NUMWORDS(555_1202, group=>1, one=>'unity'); # "five, five, five, unity, two, oh, two" $words = NUMWORDS(123.456, group=>1, decimal=>'mark'); # "one two three mark four five six" # LITERAL STYLE ONLY NAMES NUMBERS LESS THAN A CERTAIN THRESHOLD... $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 'zero'; # "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 'herd'; # "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 'persons'; # "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 'ancient'; # "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)\n"); print inflect("I saw $cat_count PL("cat",$cat_count)\n"); 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")\nNUM()"); print inflect("There PL_V(was,$errors) NO(error,$errors)\n"); print inflect("There NUM($errors,) PL_V(was) NO(error)\n"; print inflect("Did you want A($thing) or AN($idea)\n"); print inflect("It was ORD($position) from the left\n"); # 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 'HAITCH'!" def_an "horrendous.*" # "AN HORRENDOUS AFFECTATION" =head1 DESCRIPTION The exportable subroutines of Lingua::EN::Inflect provide plural inflections, "a"/"an" selection for English words, and manipulation of numbers as words Plural forms of all nouns, most verbs, and some adjectives are provided. Where appropriate, "classical" variants (for example: "brother" -> "brethren", "dogma" -> "dogmata", etc.) are also provided. Pronunciation-based "a"/"an" selection is provided for all English words, and most initialisms. It is also possible to inflect numerals (1,2,3) to ordinals (1st, 2nd, 3rd) and to English words ("one", "two", "three). 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. 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 I explicitly catered for. Where two or more inflected forms exist for a single word (typically a "classical" form and a "modern" form), Lingua::EN::Inflect prefers the more common form (typically the "modern" one), unless "classical" processing has been specified (see L<"MODERN VS CLASSICAL INFLECTIONS">). =head1 FORMING PLURALS =head2 Inflecting Plurals All of the C 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 I form of the word. The results of passing a plural form are undefined (and unlikely to be correct). The C subroutines also take an optional second argument, which indicates the grammatical "number" of the word (or of another word with which the word being inflected must agree). If the "number" argument is supplied and is not C<1> (or C<"one"> or C<"a">, or some other adjective that implies the singular), the plural form of the word is returned. If the "number" argument I indicate singularity, the (uninflected) word itself is returned. If the number argument is omitted, the plural form is returned unconditionally. The various subroutines are: =over 8 =item C The exportable subroutine C takes a I English noun or pronoun and returns its plural. Pronouns in the nominative ("I" -> "we") and accusative ("me" -> "us") cases are handled, as are possessive pronouns ("mine" -> "ours"). =item C The exportable subroutine C takes the I form of a conjugated verb (that is, one which is already in the correct "person" and "mood") and returns the corresponding plural conjugation. =item C The exportable subroutine C takes the I form of certain types of adjectives and returns the corresponding plural form. Adjectives that are correctly handled include: "numerical" adjectives ("a" -> "some"), demonstrative adjectives ("this" -> "these", "that" -> "those"), and possessives ("my" -> "our", "cat's" -> "cats'", "child's" -> "childrens'", etc.) =item C The exportable subroutine C takes a I 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 "thought" inflects to "thoughts", the verb "thought" to "thought"), the (singular) noun sense is preferred to the (singular) verb sense. Hence C will return "knives" ("knife" having been treated as a singular noun), whereas C will return "knife" ("knifes" having been treated as a 3rd person singular verb). The inherent ambiguity of such cases suggests that, where the part of speech is known, C, C, and C should be used in preference to C. =back Note that all these subroutines ignore any whitespace surrounding the word being inflected, but preserve that whitespace when the result is returned. For example, C> returns S<" cats ">. =head2 Numbered plurals The C subroutines return only the inflected word, not the count that was used to inflect it. Thus, in order to produce "I saw 3 ducks", it is necessary to use: print "I saw $N ", PL_N($animal,$N), "\n"; Since the usual purpose of producing a plural is to make it agree with a preceding count, Lingua::EN::Inflect provides an exportable subroutine (C) 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: print "I saw ", NO($animal,$N), "\n"; In addition, if the count is zero (or some other term which implies zero, such as C<"zero">, C<"nil">, etc.) the count is replaced by the word "no". Hence, if C<$N> had the value zero, the previous example would print the somewhat more elegant: I saw no animals rather than: I saw 0 animals Note that the name of the subroutine is a pun: the subroutine returns either a number (a I) or a C<"no">, in front of the inflected word. =head3 Wordy and comma'd plurals The C subroutine takes an optional third argument: a hash of named options that configure its behaviour. The C<'words_below'> option informs C what other numbers (i.e. apart from zero) it should convert to words. For example:S for my $count (0..12) { print NO('cat', $count, {words_below => 10}), "\n"; } would print: 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 The C<'comma'> and C<'comma_every'> options determine whether or not the numbers produced by C have commas in them. That is: 2001 space odysseys versus: 2,001 space odysseys Normally, numbers are produced without commas, but if C<'comma'> or C<'comma_every'> is specified, then commas are added as requested. The C<'comma'> option specifies which character to use as a comma. It defaults to C<','>, but may be set to anything convenient: print NO('Euro', $amount, {comma=>'.'}); # prints: 1.000.000 Euros The C<'comma_every'> option specifies how many characters between commas. It defaults to 3, but may be set to any positive number: print NO('Euro', $amount, {comma_every=>4}); # prints: 100,0000 Euros Note that you can set both options at once, if you wish: print NO('Euro', $amount, {comma_every=>2, comma=>'_'}); # prints: 1_00_00_00 Euros =head2 Reducing the number of counts required In some contexts, the need to supply an explicit count to the various C subroutines makes for tiresome repetition. For example: print PL_ADJ("This",$errors), PL_N(" error",$errors), PL_V(" was",$errors), " fatal.\n"; Lingua::EN::Inflect therefore provides an exportable subroutine (C) which may be used to set a persistent "default number" value. If such a value is set, it is subsequently used whenever an optional second "number" argument is omitted. The default value thus set can subsequently be removed by calling C with no arguments. Hence we could rewrite the previous example: NUM($errors); print PL_ADJ("This"), PL_N(" error"), PL_V(" was"), "fatal.\n"; NUM(); Normally, C returns its first argument, so that it may also be "inlined" in contexts like: print NUM($errors), PL_N(" error"), PL_V(" was"), " detected.\n" print PL_ADJ("This"), PL_N(" error"), PL_V(" was"), "fatal.\n" if $severity > 1; However, in certain contexts (see L<"INTERPOLATING INFLECTIONS IN STRINGS">) it is preferable that C return an empty string. Hence C provides an optional second argument. If that argument is supplied (that is, if it is defined) and evaluates to false, C returns an empty string instead of its first argument. For example: print NUM($errors,0), NO("error"), PL_V(" was"), " detected.\n"; print PL_ADJ("This"), PL_N(" error"), PL_V(" was"), "fatal.\n" if $severity > 1; =head2 Number-insensitive equality Lingua::EN::Inflect also provides a solution to the problem of comparing words of differing plurality through the exportable subroutines C, C, C, and C. Each of these subroutines takes two strings, and compares them using the corresponding plural-inflection subroutine (C, C, C, and C respectively). The comparison returns true if: =over 8 =item * the strings are C-equal, or =item * one string is C-equal to a plural form of the other, or =item * the strings are two different plural forms of the one word. =back Hence all of the following return true: 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" As indicated by the comments in the previous example, the actual value returned by the various C subroutines encodes which of the three equality rules succeeded: "eq" is returned if the strings were identical, "s:p" if the strings were singular and plural respectively, "p:s" for plural and singular, and "p:p" for two distinct plurals. Inequality is indicated by returning an empty string. It should be noted that two distinct singular words which happen to take the same plural form are I 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: 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" Note too that, although the comparison is "number-insensitive" it is I case-insensitive (that is, C returns false. To obtain both number and case insensitivity, prefix both arguments with C (that is, C returns true). =head1 OTHER VERB FORMS =head2 Present participles C also provides the C subroutine, which can take a 3rd person singular verb and correctly inflect it to its present participle: PART_PRES("runs") # "running" PART_PRES("loves") # "loving" PART_PRES("eats") # "eating" PART_PRES("bats") # "batting" PART_PRES("spies") # "spying" =head1 PROVIDING INDEFINITE ARTICLES =head2 Selecting indefinite articles Lingua::EN::Inflect provides two exportable subroutines (C and C) which will correctly prepend the appropriate indefinite article to a word, depending on its pronunciation. For example: 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" The two subroutines are I in function and may be used interchangeably. The only reason that two versions are provided is to enhance the readability of code such as: print "That is ", AN($errortype), " error\n; print "That is ", A($fataltype), " fatal error\n; Note that in both cases the actual article provided depends I on the pronunciation of the first argument, I on the name of the subroutine. C and C will ignore any indefinite article that already exists at the start of the string. Thus: @half_arked = ( "a elephant", "a giraffe", "an ewe", "a orangutan", ); print A($_), "\n" for @half_arked; # prints: # an elephant # a giraffe # a ewe # an orangutan C and C both take an optional second argument. As with the C subroutines, this second argument is a "number" specifier. If its value is C<1> (or some other value implying singularity), C and C insert "a" or "an" as appropriate. If the number specifier implies plurality, (C and C insert the actual second argument instead. For example: A("cat",1) # -> "a cat" A("cat",2) # -> "2 cat" A("cat","one") # -> "one cat" A("cat","no") # -> "no cat" Note that, as implied by the previous examples, C and C both assume that their job is merely to provide the correct qualifier for a word (that is: "a", "an", or the specified count). In other words, they assume that the word they are given has already been correctly inflected for plurality. Hence, if C<$N> has the value 2, then: print A("cat",$N); prints "2 cat", instead of "2 cats". The correct approach is to use: print A(PL("cat",$N),$N); or, better still: print NO("cat",$N); Note too that, like the various C subroutines, whenever C and C are called with only one argument they are subject to the effects of any preceding call to C. Hence, another possible solution is: NUM($N); print A(PL("cat")); =head2 Indefinite articles and initialisms "Initialisms" (sometimes inaccurately called "acronyms") are terms which have been formed from the initial letters of words in a phrase (for example, "NATO", "NBL", "S.O.S.", "SCUBA", etc.) Such terms present a particular challenge when selecting between "a" and "an", since they are sometimes pronounced as if they were a single word ("nay-tow", "sku-ba") and sometimes as a series of letter names ("en-eff-ell", "ess-oh-ess"). C and C cope with this dichotomy using a series of inbuilt rules, which may be summarized as: =over 8 =item 1. If the word starts with a single letter, followed by a period or dash (for example, "R.I.P.", "C.O.D.", "e-mail", "X-ray", "T-square"), then choose the appropriate article for the I of the first letter ("an R.I.P.", "a C.O.D.", "an e-mail", "an X-ray", "a T-square"). =item 2. 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, "LCD", "XML", "YWCA"), then once again choose "a" or "an" depending on the I of the first letter ("an LCD", "an XML", "a YWCA"). =item 3. Otherwise, assume the string is a capitalized word or a pronounceable initialism (for example, "LED", "OPEC", "FAQ", "UNESCO"), and therefore takes "a" or "an" according to the (apparent) pronunciation of the entire word ("a LED", "an OPEC", "a FAQ", "a UNESCO"). =back 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, "a FAQ" but "an F.A.Q."). =head2 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, "hour", "honour", "heir") the 'H' is not voiced at all, and so such words inflect with "an". The remaining cases ("voiced H's") may be divided into two categories: "hard H's" (such as "hangman", "holograph", "hat", etc.) and "soft H's" (such as "hysterical", "horrendous", "holy", etc.) Hard H's always take "a" as their indefinite article, and soft H's normally do so as well. But I English speakers prefer "an" for soft H's (although the practice is now generally considered an affectation, rather than a legitimate grammatical alternative). At present, the C and C subroutines ignore soft H's and use "a" for any voiced 'H'. The author would, however, welcome feedback on this decision (envisaging a possible future "soft H" mode). =head1 INFLECTING ORDINALS Occasionally it is useful to present an integer value as an ordinal rather than as a numeral. For example: Enter password (1st attempt): ******** Enter password (2nd attempt): ********* Enter password (3rd attempt): ********* No 4th attempt. Access denied. To this end, Lingua::EN::Inflect provides the C subroutine. takes a single argument and forms its ordinal equivalent. If the argument isn't a numerical integer, it just adds "-th". =head1 CONVERTING NUMBERS TO WORDS The exportable subroutine C takes a number (cardinal or ordinal) and returns an English representation of that number. In a scalar context a string is returned. Hence: use Lingua::EN::Inflect qw( NUMWORDS ); $words = NUMWORDS(1234567); puts the string: "one million, two hundred and thirty-four thousand, five hundred and sixty-seven" into $words. In a list context each comma-separated chunk is returned as a separate element. Hence: @words = NUMWORDS(1234567); puts the list: ("one million", "two hundred and thirty-four thousand", "five hundred and sixty-seven") into @words. 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: NUMWORDS(5551202); NUMWORDS(5_551_202); NUMWORDS("5,551,202"); NUMWORDS("555-1202"); That last case is a little awkward since it's almost certainly a phone number, and "five million, five hundred and fifty-one thousand, two hundred and two" probably isn't what's wanted. To overcome this, C 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 C<1>, then each digit is translated separately. If the argument is C<2>, pairs of digits (starting from the I) are grouped together. If the argument is C<3>, triples of numbers (again, from the I) are grouped. Hence: NUMWORDS("555-1202", group=>1) returns C<"five, five, five, one, two, zero, two">, whilst: NUMWORDS("555-1202", group=>2) returns C<"fifty-five, fifty-one, twenty, two">, and: NUMWORDS("555-1202", group=>3) returns C<"five fifty-five, one twenty, two">. Phone numbers are often written in words as C<"five..five..five..one..two..zero..two">, which is also easy to achieve: join '..', NUMWORDS("555-1202", group=>1) C also handles decimal fractions. Hence: NUMWORDS("1.2345") returns C<"one point two three four five"> in a scalar context and C<("one","point","two","three","four","five")>) in an array context. Exponent form (C<"1.234e56">) is not yet handled. Multiple decimal points are only translated in one of the "grouping" modes. Hence: NUMWORDS(101.202.303) returns C<"one hundred and one point two zero two three zero three">, whereas: NUMWORDS(101.202.303, group=>1) returns C<"one zero one point two zero two point three zero three">. The digit C<'0'> is unusual in that in may be translated to English as "zero", "oh", or "nought". To cater for this diversity, C may be passed a named argument, 'zero', which may be set to the desired translation of C<'0'>. For example: print join "..", NUMWORDS("555-1202", group=>3, zero=>'oh') prints C<"five..five..five..one..two..oh..two">. By default, zero is rendered as "zero". Likewise, the digit C<'1'> may be rendered as "one" or "a/an" (or very occasionally other variants), depending on the context. So there is a C<'one'> argument as well: print NUMWORDS($_, one=>'a solitary', zero=>'no more'), PL(" bottle of beer on the wall\n", $_) 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 Care is needed if the word "a/an" is to be used as a C<'one'> value. Unless the next word is known in advance, it's almost always necessary to use the C function as well: print A( NUMWORDS(1, one=>'a') . " $_\n") for qw(cat aardvark ewe hour); # prints: # a cat # an aardvark # a ewe # an hour Another major regional variation in number translation is the use of "and" in certain contexts. The named argument 'and' allows the programmer to specify how "and" should be handled. Hence: print scalar NUMWORDS("765", 'and'=>'') prints "seven hundred sixty-five", instead of "seven hundred and sixty-five". By default, the "and" is included. The translation of the decimal point is also subject to variation (with "point", "dot", and "decimal" being the favorites). The named argument 'decimal' allows the programmer to how the decimal point should be rendered. Hence: print scalar NUMWORDS("666.124.64.101", group=>3, decimal=>'dot') prints "six sixty-six, dot, one twenty-four, dot, sixty-four, dot, one zero one" By default, the decimal point is rendered as "point". C also handles the ordinal forms of numbers. So: print scalar NUMWORDS('1st'); print scalar NUMWORDS('3rd'); print scalar NUMWORDS('202nd'); print scalar NUMWORDS('1000000th'); print: first third two hundred and twenty-second one millionth Two common idioms in this regard are: print scalar NUMWORDS(ORD($number)); and: print scalar ORD(NUMWORDS($number)); These are identical in effect, except when $number contains a decimal: $number = 99.09; print scalar NUMWORDS(ORD($number)); # ninety-ninth point zero nine print scalar ORD(NUMWORDS($number)); # ninety-nine point zero ninth Use whichever you feel is most appropriate. =head1 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 "and" or "or") 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. That's complicated enough to warrant its own subroutine: C. 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: print "You chose ", WORDLIST(@selected_items), "\n"; # You chose barley soup, roast beef, and Yorkshire pudding print "You chose ", WORDLIST(@selected_items, {final_sep=>""}), "\n"; # You chose barley soup, roast beef and Yorkshire pudding print "Please chose ", WORDLIST(@side_orders, {conj=>"or"}), "\n"; # Please chose salad, vegetables, or ice-cream The available options are: Option named Specifies Default value conj Final conjunction "and" sep Inter-item separator "," last_sep Final separator value of 'sep' option =head1 INTERPOLATING INFLECTIONS IN STRINGS By far the commonest use of the inflection subroutines is to produce message strings for various purposes. For example: print NUM($errors), PL_N(" error"), PL_V(" was"), " detected.\n"; print PL_ADJ("This"), PL_N(" error"), PL_V(" was"), "fatal.\n" if $severity > 1; 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 (C), which recognizes calls to the various inflection subroutines within a string and interpolates them appropriately. Using C the previous example could be rewritten: print inflect "NUM($errors) PL_N(error) PL_V(was) detected.\n"; print inflect "PL_ADJ(This) PL_N(error) PL_V(was) fatal.\n" if $severity > 1; Note that C also correctly handles calls to the C subroutine (whether interpolated or antecedent). The C subroutine has a related extra feature, in that it I cancels any "default number" value before it returns its interpolated string. This means that calls to C which are embedded in an C-interpolated string do not "escape" and interfere with subsequent inflections. =head1 MODERN VS CLASSICAL INFLECTIONS Certain words, mainly of Latin or Ancient Greek origin, can form plurals either using the standard English "-s" suffix, or with their original Latin or Greek inflections. For example: 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" Lingua::EN::Inflect caters to such words by providing an "alternate state" of inflection known as "classical mode". By default, words are inflected using their contemporary English plurals, but if classical mode is invoked, the more traditional plural forms are returned instead. The exportable subroutine C controls this feature. If C 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. Thus: 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" Note however that C has no effect on the inflection of words which are now fully assimilated. Hence: PL("forum") # ALWAYS -> "forums" PL("criterion") # ALWAYS -> "criteria" LEI 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 C<< classical(names=>0) >>. =head1 USER-DEFINED INFLECTIONS =head2 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: =over 8 =item C The C 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 C). 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: def_noun 'cow' => 'kine'; def_noun '(.+i)o' => '$1i'; def_noun 'spam(mer)?' => '\\$\\%\\@#\\$\\@#!!'; 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. The second argument string may also specify a second variant of the plural form, to be used when "classical" plurals have been requested. The beginning of the second variant is marked by a '|' character: def_noun 'cow' => 'cows|kine'; def_noun '(.+i)o' => '$1os|$1i'; def_noun 'spam(mer)?' => '\\$\\%\\@#\\$\\@#!!|varmints'; If no classical variant is given, the specified plural form is used in both normal and "classical" modes. If the second argument is C instead of a string, then the current user definition for the first argument is removed, and the standard plural inflection(s) restored. Note that in all cases, later plural definitions for a particular singular form replace earlier definitions of the same form. For example: # FIRST, HIDE THE MODERN FORM.... def_noun 'aviatrix' => 'aviatrices'; # LATER, HIDE THE CLASSICAL FORM... def_noun 'aviatrix' => 'aviatrixes'; # FINALLY, RESTORE THE DEFAULT BEHAVIOUR... def_noun 'aviatrix' => undef; Special care is also required when defining general patterns and associated specific exceptions: put the more specific cases I the general pattern. For example: def_noun '(.+)us' => '$1i'; # EVERY "-us" TO "-i" def_noun 'bus' => 'buses'; # EXCEPT FOR "bus" This "try-most-recently-defined-first" approach to matching user-defined words is also used by C, C and C. =item C The C subroutine takes three pairs of string arguments (that is, six arguments in total), specifying the singular and plural forms of the three "persons" of verb. As with C, the singular forms are specifications of run-time-interpolated patterns, whilst the plural forms are specifications of (up to two) run-time-interpolated strings: def_verb 'am' => 'are', 'are' => 'are|art", 'is' => 'are'; def_verb 'have' => 'have', 'have' => 'have", 'ha(s|th)' => 'have'; Note that as with C, modern/classical variants of plurals may be separately specified, subsequent definitions replace previous ones, and C'ed plural forms revert to the standard behaviour. =item C The C subroutine takes a pair of string arguments, which specify the singular and plural forms of the adjective being defined. As with C and C, the singular forms are specifications of run-time-interpolated patterns, whilst the plural forms are specifications of (up to two) run-time-interpolated strings: def_adj 'this' => 'these', def_adj 'red' => 'red|gules', As previously, modern/classical variants of plurals may be separately specified, subsequent definitions replace previous ones, and C'ed plural forms revert to the standard behaviour. =item C and C The C and C subroutines each take a single argument, which specifies a pattern. If a word passed to C or C matches this pattern, it will be prefixed (unconditionally) with the corresponding indefinite article. For example: def_a 'error'; def_a 'in.+'; def_an 'mistake'; def_an 'error'; As with the other C subroutines, such redefinitions are sequential in effect so that, after the above example, "error" will be inflected with "an". =back =head2 The F<$HOME/.inflectrc> file When it is imported, Lingua::EN::Inflect executes (as Perl code) the contents of any file named F<.inflectrc> which it finds in the in the directory where F is installed, or in the current home directory (C<$ENV{HOME}>), or in both. Note that the code is executed within the Lingua::EN::Inflect namespace. Hence the user or the local Perl guru can make appropriate calls to C, C, etc. in one of these F<.inflectrc> files, to permanently and universally modify the behaviour of the module. For example > 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 Note that calls to the C subroutines from within a program will take precedence over the contents of the home directory F<.inflectrc> file, which in turn takes precedence over the system-wide F<.inflectrc> file. =head1 DIAGNOSTICS On loading, if the Perl code in a F<.inflectrc> 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 C subroutines do). Using the five C subroutines directly in a program may also result in fatal diagnostics, if a (singular) pattern or an interpolated (plural) string is somehow invalid. Specific diagnostics related to user-defined inflections are: =over 8 =item C<"Bad user-defined singular pattern:\n\t %s"> The singular form of a user-defined noun or verb (as defined by a call to C, C, C, C or C) is not a valid Perl regular expression. The actual Perl error message is also given. =item C<"Bad user-defined plural string: '%s'"> The plural form(s) of a user-defined noun or verb (as defined by a call to C, C or C) is not a valid Perl interpolated string (usually because it interpolates some undefined variable). =item C<"Bad .inflectrc file (%s):\n %s"> Some other problem occurred in loading the named local or global F<.inflectrc> file. The Perl error message (including the line number) is also given. =back There are I diagnosable run-time error conditions for the actual inflection subroutines, except C 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 "guess" the commonest English inflection: adding "-s" for nouns, removing "-s" for verbs, and no inflection for adjectives. C can C with the following messages: =over 8 =item C<"Bad grouping option: %s"> The optional argument to C wasn't 1, 2 or 3. =item C<"Number out of range"> C 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 :-) The problem is that C doesn't know any words for number components bigger than "decillion". =back =head1 OTHER ISSUES =head2 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. The author is not currently aware of any such verbs in English, but is not quite arrogant enough to assume I that none exist. =head2 Nominative precedence The singular pronoun "it" presents a special problem because its plural form can vary, depending on its "case". For example: 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 As a consequence of this ambiguity, C or C have been implemented so that they always return the I plural (that is, "they"). However, when asked for the plural of an unambiguously I "it" (namely, C, C, C, etc.), both subroutines will correctly return the accusative plural ("to them", "from them", "with them", etc.) =head2 The plurality of zero The rules governing the choice between: There were no errors. and There was no error. are complex and often depend more on I rather than I. Hence it is infeasible to specify such rules algorithmically. 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 "classical" inflection is in effect, in which case the singular form is always returned. Thus, the sequence: NUM(0); print inflect "There PL(was) NO(choice)"; produces "There were no choices", whereas: classical 'zero'; # or: classical(zero=>1); NUM(0); print inflect "There PL(was) NO(choice)"; it will print "There was no choice". =head2 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: Three basses were stolen from the band's equipment trailer. Three bass were stolen from the band's 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. Lingua::EN::Inflect handles such words in two ways: =over 8 =item * If both meanings of the word are the I part of speech (for example, "bass" is a noun in both sentences above), then one meaning is chosen as the "usual" meaning, and only that meaning's plural is ever returned by any of the inflection subroutines. =item * If each meaning of the word is a different part of speech (for example, "thought" is both a noun and a verb), then the noun's plural is returned by C and C and the verb's plural is returned only by C. =back Such contexts are, fortunately, uncommon (particularly "same-part-of-speech" examples). An informal study of nearly 600 "difficult plurals" indicates that C can be relied upon to "get it right" about 98% of the time (although, of course, ichthyophilic guitarists or cyber-behaviouralists may experience higher rates of confusion). If the choice of a particular "usual inflection" is considered inappropriate, it can always be reversed with a preliminary call to the corresponding C subroutine. =head1 NOTE I'm not taking any further correspondence on: =over =item "octopi". Despite the populist pandering of certain New World dictionaries, the plural is "octopuses" or (for the pedantic classicist) "octopodes". The suffix "-pus" is Greek, not Latin, so the plural is "-podes", not "pi". =item "virus". Had no plural in Latin (possibly because it was a mass noun). The only plural is the Anglicized "viruses". =back =head1 AUTHORS Damian Conway (damian@conway.org) Matthew Persico (ORD inflection) =head1 BUGS AND IRRITATIONS The endless inconsistencies of English. (I report words for which the correct plural or indefinite article is not formed, so that the reliability of Lingua::EN::Inflect can be improved.) =head1 COPYRIGHT 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. Lingua-EN-Inflect-1.895/demo/demo_eq.pl000755 000765 000765 00000001070 07531120215 020266 0ustar00damiandamian000000 000000 #! /usr/bin/perl -ws use Lingua::EN::Inflect qw { :COMPARISONS }; use vars qw { $classical $modern }; classical if $classical && !$modern; print "compare> "; while (<>) { chomp; exit if /^\.$/; if (/^\-classical$/) { classical ; print "[going classical]"} elsif (/^-modern$/) { classical 0; print "[going modern]" } else { if (/(\S+)\s+(\S+)/) { print "PL: [", PL_eq($1, $2), "]\n"; print "PL_N: [", PL_N_eq($1, $2), "]\n"; print "PL_V: [", PL_V_eq($1, $2), "]\n"; print "PL_ADJ: [", PL_ADJ_eq($1, $2), "]\n"; } } print "\ncompare> "; } Lingua-EN-Inflect-1.895/demo/demo_inflect.pl000755 000765 000765 00000000577 07531120216 021321 0ustar00damiandamian000000 000000 #! /usr/bin/perl -ws use Lingua::EN::Inflect qw { &inflect &classical }; use vars qw { $classical $modern }; classical if $classical && !$modern; print "inflect> "; while (<>) { chomp; exit if /^\.$/; if (/^\-classical$/) { classical ; print "[going classical]"} elsif (/^-modern$/) { classical 0; print "[going modern]" } else { print inflect $_ } print "\ninflect> "; } Lingua-EN-Inflect-1.895/demo/demo_NO.pl000755 000765 000765 00000001143 07531120211 020172 0ustar00damiandamian000000 000000 #! /usr/bin/perl -ws use Lingua::EN::Inflect qw { :USER_DEFINED classical NO }; use vars qw { $classical $modern }; classical if $classical && !$modern; def_noun 'kin' => 'kine'; def_noun '(.*)x' => '$1xen'; def_verb 'foo' => 'fee', 'foo' => 'fee', 'foos' => 'fee'; def_adj 'red' => 'red|gules'; print "count word> "; while (<>) { chomp; exit if /^\.$/; if (/^\-classical$/) { classical ; print "[going classical]"} elsif (/^-modern$/) { classical 0; print "[going modern]" } else { /\s*([^\s]+)\s+(.*)/ or next; print " ", NO($2,$1), "\n"; } print "\ncount word> "; } Lingua-EN-Inflect-1.895/demo/demo_NUM.pl000755 000765 000765 00000001020 07531120213 020311 0ustar00damiandamian000000 000000 #! /usr/bin/perl -ws use Lingua::EN::Inflect qw { classical NUM inflect }; use vars qw { $classical $modern }; classical if $classical && !$modern; print "count inflection> "; while (<>) { chomp; exit if /^\.$/; if (/^\-classical$/) { classical ; print "[going classical]"} elsif (/^-modern$/) { classical 0; print "[going modern]" } else { /\s*(\S+)\s+(.*)/ and print " ", NUM($1), " ", inflect($2), "\n" or /\s*(\S*)/ and print " ", inflect($1), "\n"; } print "\ncount word> "; } Lingua-EN-Inflect-1.895/demo/demo_PL.pl000755 000765 000765 00000001050 07531120214 020171 0ustar00damiandamian000000 000000 #! /usr/bin/perl -ws use Lingua::EN::Inflect qw { classical PL def_noun def_verb def_adj }; use vars qw { $classical $modern }; classical if $classical && !$modern; def_noun 'kin' => 'kine'; def_verb 'foo' => 'fee', 'foo' => 'fee', 'foos' => 'fee'; def_adj 'red' => 'red|gules'; print "singular> one "; while (<>) { chomp; exit if /^\.$/; if (/^\-classical$/) { classical ; print "[going classical]"} elsif (/^-modern$/) { classical 0; print "[going modern]" } else { print " plural> two ", PL $_ } print "\nsingular> one "; }