hbutils.string.plural
Pluralization and singularization helpers for English words.
This module provides thin wrappers around the underlying inflection utilities for converting words between singular and plural forms. It also exposes a helper for formatting a word with its count using grammatically correct forms.
The module contains the following public components:
plural_form()- Convert a word to its plural form.singular_form()- Convert a word to its singular form.plural_word()- Format a word with its count using correct plurality.
Example:
>>> from hbutils.string.plural import plural_form, singular_form, plural_word
>>> plural_form('woman')
'women'
>>> singular_form('women')
'woman'
>>> plural_word(3, 'word')
'3 words'
Note
These helpers delegate to hbutils.string.inflection.pluralize() and
hbutils.string.inflection.singularize(), which implement both regular
and irregular English inflection rules.
__all__
- hbutils.string.plural.__all__ = ['plural_form', 'plural_word', 'singular_form']
Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
plural_form
- hbutils.string.plural.plural_form(word: str) str[source]
Get the pluralized form of the given word.
This function is a thin wrapper around
hbutils.string.inflection.pluralize()and therefore supports the same irregular and uncountable noun handling as the underlying implementation.- Parameters:
word (str) – The word to be pluralized.
- Returns:
Pluralized word.
- Return type:
str
Example:
>>> from hbutils.string import plural_form >>> plural_form('it') 'they' >>> plural_form('word') 'words' >>> plural_form('woman') 'women'
singular_form
- hbutils.string.plural.singular_form(word: str) str[source]
Get the singular form of the given word.
This function is a thin wrapper around
hbutils.string.inflection.singularize()and therefore supports the same irregular and uncountable noun handling as the underlying implementation.- Parameters:
word (str) – The word to be singularized.
- Returns:
Singular form of the word.
- Return type:
str
Example:
>>> from hbutils.string import singular_form >>> singular_form('they') 'it' >>> singular_form('it') 'it' >>> singular_form('women') 'woman' >>> singular_form('words') 'word' >>> singular_form('themselves') 'itself'
plural_word
- hbutils.string.plural.plural_word(count: int, word: str) str[source]
Format a word with its count using correct plurality.
If
countis 1, the singular form is used; otherwise, the plural form is used. The singular form is derived fromsingular_form()and the plural form fromplural_form(), which handle irregular inflections.- Parameters:
count (int) – Count of the word.
word (str) – Word to be pluralized.
- Returns:
Formatted string with the count and correct word form.
- Return type:
str
Example:
>>> from hbutils.string import plural_word >>> plural_word(0, 'word') '0 words' >>> plural_word(1, 'word') '1 word' >>> plural_word(2, 'word') '2 words' >>> plural_word(20, 'word') '20 words' >>> plural_word(233, 'word') '233 words'