spunQ_Grammar Class Reference

Simple class for transforming words from singular to plural and vice versa. More...

List of all members.

Static Public Member Functions

static pluralize ($word)
 Converts a word to plural.
static singularize ($word)
 Converts a word to singular.

Static Private Member Functions

static initPluralRules ()
 Initializes all the rules that are described in the class docs.
static initSingularRules ()
 Initializes all the rules that are described in the class docs.
static transform ($word, $rules)
 Does the actual inflection.

Static Private Attributes

static $pluralizationRules = NULL
 Rules for converting singular to plural.
static $pluralizedWords = array()
 Cache for already-processed words.
static $singularizationRules = NULL
 Rules for converting plural to singular.
static $singularizedWords = array()
 Cache for already-processed words.


Detailed Description

Simple class for transforming words from singular to plural and vice versa.

Pluralization/singularization relies on three different lookups:

All of these lookups are done using regular expressions. The rules are stored in two arrays, one for singular to plural and one for the other way round. Both these arrays contain four entries: The function transform does the actual transformation, the results are cached in the variables $pluralizedWords and $singularizedWords.
Todo:
Parts of this file were copied from the CakePHP framework - give proper credit.

Definition at line 27 of file Grammar.class.php.


Member Function Documentation

static spunQ_Grammar::initPluralRules (  )  [static, private]

Initializes all the rules that are described in the class docs.

Returns:
void

Definition at line 83 of file Grammar.class.php.

static spunQ_Grammar::initSingularRules (  )  [static, private]

Initializes all the rules that are described in the class docs.

Returns:
void

Definition at line 177 of file Grammar.class.php.

static spunQ_Grammar::pluralize ( word  )  [static]

Converts a word to plural.

Parameters:
$word the word to convert to plural
Returns:
string

Definition at line 58 of file Grammar.class.php.

static spunQ_Grammar::singularize ( word  )  [static]

Converts a word to singular.

Parameters:
$word the word to convert to singular
Returns:
string

Definition at line 71 of file Grammar.class.php.

static spunQ_Grammar::transform ( word,
rules 
) [static, private]

Does the actual inflection.

Since both arrays have the same structure, this function does not need to care whether it is transforming form singular to plural or vice versa.

Parameters:
$word The word to inflect.
$rules The rules to use. Either of $singularizationRules and $pluralizationRules.
Returns:
string the inflected word

Definition at line 284 of file Grammar.class.php.


Member Data Documentation

spunQ_Grammar::$pluralizationRules = NULL [static, private]

Rules for converting singular to plural.

Type:
array

Definition at line 33 of file Grammar.class.php.

spunQ_Grammar::$pluralizedWords = array() [static, private]

Cache for already-processed words.

Type:
map<string,srtring>

Definition at line 39 of file Grammar.class.php.

spunQ_Grammar::$singularizationRules = NULL [static, private]

Rules for converting plural to singular.

Type:
array

Definition at line 45 of file Grammar.class.php.

spunQ_Grammar::$singularizedWords = array() [static, private]

Cache for already-processed words.

Type:
map<string,srtring>

Definition at line 51 of file Grammar.class.php.


The documentation for this class was generated from the following file:

Generated on Fri Jul 1 11:12:40 2011 for spunQ3 by  doxygen 1.5.9