
A.Fordatford-mason.co.uk
Sep 2, 2005, 12:16 PM
Post #1 of 1
(96 views)
Permalink
|
|
Announce: Template::Plugin::Lingua::EN::Inflect
|
|
I have written a simple plugin interface to Damien Conway's Lingua::EN::Inflect module (basing the code on the autoformat plugin). This allows you to do things like [.%- USE infl = Lingua.EN.Inflect; message = "There PL_V(was) NO(error).\nPL_ADJ(This) PL_N(error) PL_V(was) fatal."; message | inflect(number => 1); message | inflect(number => 42); "... and "; infl.ORD(9); "ly..."; -%] and get nicely inflected messages like: There was 1 error. This error was fatal. There were 42 errors. These errors were fatal. ... and 9thly... I will be uploading the module to CPAN later today but it is also available from http://andrew-ford.com/perl/tt2-inflect-plugin.html The man page is included below. Comments welcome. Andrew -- Andrew Ford, Director Pauntley Prints / Ford & Mason Ltd A.Ford [at] ford-mason South Wing Compton House pauntley-prints.co.uk Compton Green, Redmarley Tel: +44 1531 829900 ford-mason.co.uk Gloucester GL19 3JB Fax: +44 1531 829901 refcards.com cronolog.org Great Britain Mobile: +44 7785 258278 NAME Template::Plugin::Lingua::EN::Inflect - Interface to Lingua::EN::Inflect module SYNOPSIS [% USE infl = Lingua.EN.Inflect; -%] [% FILTER inflect(number => 42); -%] There PL_V(was) NO(error). PL_ADJ(This) PL_N(error) PL_V(was) fatal. [% END; -%] [% "... and "; infl.ORD(9); "ly..." %] # Output: # There were 42 errors. # These errors were fatal. # ... and 9thly... DESCRIPTION The Lingua::EN::Inflect is an interface to Damian Conway's Linua::EN::Inflect Perl module, which provides plural inflections, "a"/"an" selection for English words, and manipulation of numbers as words. The plugin provides an 'inflect' filter, which can be used to interpolate inflections in a string. The NUM() function set a persistent default value to be used whenever an optional number argument is omitted. The number to be used for a particular invocation of 'inflect' can also be specified with a 'number' option. For the full gory details of the inflection functionality refer to the Lingua::EN::Inflect manual. OBJECT METHODS "infl.A($string, $opt_number)" prepends the appropriate indefinite article to a word, depending on its pronunciation. If the second argument is provided and its value is numeric and not 1 then the value of the second argument is used instead. e.g. "infl.A("idea")" returns "an idea" "AN($string, $opt_number)" synonym for "A()" "NO($string, $opt_arg)" "NUM($string, $opt_arg)" "NUMWORDS($string, $opt_arg)" "ORD($number)" "PART_PRES($string, $opt_arg)" returns the present participle for a third person singluar verb PART_PRES("runs"); # returns "running" "PL($string, $opt_arg)" returns the plural of a *singular* English noun, pronoun, verb or adjective. "PL_N($string, $opt_arg)" returns the plural of a *singular* English noun or pronoun. "PL_V($string, $opt_arg)" returns the plural conjugation of the *singular* form of a conjugated verb. "PL_ADJ($string, $opt_arg)" returns the plural form of a *singular* form of certain types of adjectives. "PL_eq($string, $opt_arg)" "PL_N_eq($string, $opt_arg)" "PL_V_eq($string, $opt_arg)" "PL_ADJ_eq($string, $opt_arg)" "classical($string, $opt_arg)" "def_noun($string, $opt_arg)" "def_verb($string, $opt_arg)" "def_adj($string, $opt_arg)" "def_a($string, $opt_arg)" "def_an($string, $opt_arg)" TODO Finish off documenting the object methods. Provide tests for all methods in the test suite. It would also be nice to have methods that spelled out numbers that were less than a certain threshold and that formatted large numbers with commas, for example: inflect("There PL_V(was) NO(error).", number => 0); # outputs: "There were no errors." inflect("There PL_V(was) NO(error).", number => 1); # outputs: "There was one errors." inflect("There PL_V(was) NO(error).", number => 3); # outputs: "There were three errors." inflect("There PL_V(was) NO(error).", number => 1042); # outputs: "There were 1,042 errors." This would require changes to the Lingua::EN::Inflect module. AUTHOR Andrew Ford <A.Ford [at] ford-mason> wrote the plugin code (basing it heavily on the Template::Plugin::Autoformat code). Damian Conway <damian [at] conway> wrote the Lingua::EN::Inflect module, which does all the clever stuff. COPYRIGHT Copyright (C) 2005 Andrew Ford. All Rights Reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO Lingua::EN::Inflect, Template, "Template::Plugin"
|