Lingua::EN::Inflect 1.89 review

Download
by rbytes.net on

Lingua::EN::Inflect is a Perl module that can convert singular to plural

License: Perl Artistic License
File size: 40K
Developer: Damian Conway
0 stars award from rbytes.net

Lingua::EN::Inflect is a Perl module that can convert singular to plural. Select "a" or "an".

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
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 "samen" if PL_eq($word1, $word2);
print "same nounn" if PL_eq_N($word1, $word2);
print "same verbn" if PL_eq_V($word1, $word2);
print "same adj.n" if PL_eq_ADJ($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 leftn";

# 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"


# 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 leftn");


# 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"

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 not 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 "MODERN VS CLASSICAL INFLECTIONS").

Requirements:
Perl

Lingua::EN::Inflect 1.89 keywords