Susina Utils

SimpleInflector
in package
implements InflectorInterface

Simple English pluralizer/singularizer class.

Tags
author

Cristiano Cinotti

Table of Contents

Interfaces

InflectorInterface

Properties

$ambiguous  : array<string|int, string>
Array of words that could be ambiguously interpreted. Eg: `isPlural` method can't recognize 'menus' as plural, because it considers 'menus' as the singular of 'menuses'.
$irregular  : array<string, string>
Irregular forms.
$plural  : array<string, string>
Plural forms
$singular  : array<string, string>
Singular forms.
$uncountable  : array<string|int, string>
Uncountable

Methods

__construct()  : mixed
isPlural()  : bool
Check if $root word is plural.
isSingular()  : bool
Check if $root word is singular.
pluralize()  : string
Generate a plural name based on the passed in root.
singularize()  : string
Generate a singular name based on the passed in root.
checkIrregularForm()  : null|string
Pluralize/Singularize irregular forms.
checkIrregularSuffix()  : null|string
isAmbiguousPlural()  : bool
isIrregular()  : bool

Properties

$ambiguous

Array of words that could be ambiguously interpreted. Eg: `isPlural` method can't recognize 'menus' as plural, because it considers 'menus' as the singular of 'menuses'.

protected array<string|int, string> $ambiguous = ['menu' => 'menus']

$irregular

Irregular forms.

protected array<string, string> $irregular = ['matrix' => 'matrices', 'leaf' => 'leaves', 'loaf' => 'loaves', 'move' => 'moves', 'foot' => 'feet', 'goose' => 'geese', 'genus' => 'genera', 'sex' => 'sexes', 'ox' => 'oxen', 'child' => 'children', 'man' => 'men', 'tooth' => 'teeth', 'person' => 'people', 'wife' => 'wives', 'mythos' => 'mythoi', 'testis' => 'testes', 'numen' => 'numina', 'quiz' => 'quizzes', 'alias' => 'aliases']

$plural

Plural forms

protected array<string, string> $plural = ['(ind|vert)ex' => '\1ices', '(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us' => '\1i', '(buffal|tomat)o' => '\1oes', 'x' => 'xes', 'ch' => 'ches', 'sh' => 'shes', 'ss' => 'sses', 'ay' => 'ays', 'ey' => 'eys', 'iy' => 'iys', 'oy' => 'oys', 'uy' => 'uys', 'y' => 'ies', 'ao' => 'aos', 'eo' => 'eos', 'io' => 'ios', 'oo' => 'oos', 'uo' => 'uos', 'o' => 'os', 'us' => 'uses', 'cis' => 'ces', 'sis' => 'ses', 'xis' => 'xes', 'zoon' => 'zoa', 'itis' => 'itis', 'ois' => 'ois', 'pox' => 'pox', 'ox' => 'oxes', 'foot' => 'feet', 'goose' => 'geese', 'tooth' => 'teeth', 'quiz' => 'quizzes', 'alias' => 'aliases', 'alf' => 'alves', 'elf' => 'elves', 'olf' => 'olves', 'arf' => 'arves', 'nife' => 'nives', 'life' => 'lives']

$singular

Singular forms.

protected array<string, string> $singular

This variable is populated by flipping $plural property.

$uncountable

Uncountable

protected array<string|int, string> $uncountable = ['sheep', 'fish', 'deer', 'series', 'species', 'money', 'rice', 'information', 'equipment', 'news', 'people']

Methods

isPlural()

Check if $root word is plural.

public isPlural(string $root) : bool
Parameters
$root : string
Return values
bool

isSingular()

Check if $root word is singular.

public isSingular(mixed $root) : bool
Parameters
$root : mixed
Return values
bool

pluralize()

Generate a plural name based on the passed in root.

public pluralize(string $root) : string
Parameters
$root : string

The root that needs to be pluralized (e.g. Author)

Return values
string —

The plural form of $root (e.g. Authors).

singularize()

Generate a singular name based on the passed in root.

public singularize(string $root) : string
Parameters
$root : string

The root that needs to be pluralized (e.g. Author)

Return values
string —

The singular form of $root (e.g. Authors).

checkIrregularForm()

Pluralize/Singularize irregular forms.

private checkIrregularForm(string $root, array<string, string> $irregular) : null|string
Parameters
$root : string

The string to pluralize/singularize

$irregular : array<string, string>

Array of irregular forms

Return values
null|string

checkIrregularSuffix()

private checkIrregularSuffix(string $root, array<string, string> $irregular) : null|string
Parameters
$root : string
$irregular : array<string, string>

Array of irregular suffixes

Return values
null|string

isAmbiguousPlural()

private isAmbiguousPlural(mixed $root) : bool
Parameters
$root : mixed
Return values
bool

isIrregular()

private isIrregular(array<string|int, string> $irregular, string $root) : bool
Parameters
$irregular : array<string|int, string>

Array of irregular forms

$root : string
Return values
bool
On this page

Search results