Andrew Ford (PAUSE Custodial Account) > Template-Plugin-Lingua-EN-Inflect-0.02 > Template::Plugin::Lingua::EN::Inflect

Download:
Template-Plugin-Lingua-EN-Inflect-0.02.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  2
Open  0
View/Report Bugs
Module Version: 0.02   Source   Latest Release: Template-Plugin-Lingua-EN-Inflect-0.03

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)

given a word and an optional count, returns the count followed by the correctly inflected word

NUM($string, $opt_arg)

sets a persistent default number value, which is subsequently used whenever an optional second number argument is omitted. The default value thus set can subsequently be removed by calling NUM() with no arguments. NUM() normally returns its first argument, however if NUM() is called with a second argument that is defined and evaluates to false then NUM() returns an empty string.

NUMWORDS($string, $opt_arg)

takes a number (cardinal or ordinal) and returns an English represen- tation of that number. In a scalar context a string is returned. In a list context each comma-separated chunk is returned as a separate element.

ORD($number)

takes a single argument and forms its ordinal equivalent. If the argument isn't a numerical integer, it just adds "-th".

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@ford-mason.co.uk> wrote the plugin code (basing it heavily on the Template::Plugin::Autoformat code).

Damian Conway <damian@conway.org> 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

syntax highlighting: