hbutils.string.plural

Overview:

Useful utilities for pluralize your words.

plural_form

hbutils.string.plural.plural_form(word: str, engine: Optional[inflect.engine] = None) → str[source]
Overview:

Get the pluralized form of the given word.

Arguments:
  • word (str): The given word to be pluralized.

  • engine (Optional[inflect.engine]): Engine to be used, default is None which means just use the default one.

Returns:
  • pluralized (str): Pluralized word.

Examples::
>>> 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, engine: Optional[inflect.engine] = None) → str[source]
Overview:

Get the singular form of the given word.

Arguments:
  • word (str): The given word to be singularized.

  • engine (Optional[inflect.engine]): Engine to be used, default is None which means just use the default one.

Returns:
  • single (str): Singular form of word.

Examples::
>>> from hbutils.string import singular_form
>>> singular_form('they')
'it'
>>> singular_form('them')
'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, num_text: bool = False, num_threshold: Optional[int] = None, engine: Optional[inflect.engine] = None) → str[source]
Overview:

Get plural form of the whole word, with the number before the word.

Arguments:
  • count (int): Count of the word, should be a non-negative integer.

  • word (str): Word to be pluralized.

  • num_text (bool): Show the number as text format or not, default is False which means just use the arabic number for all the cases.

  • num_threshold (Optional[int]): Threshold value when the number is shown as text, default is None which means just use english text format for all the cases.

  • engine (Optional[inflect.engine]): Engine to be used, default is None which means just use the default one.

Returns:
  • plural_word (str): Pluralized word, with the number.

Examples::
>>> 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'
>>> plural_word(20, 'word', num_text=True)
'twenty words'
>>> plural_word(233, 'word', num_text=True)
'two hundred and thirty-three words'
>>> plural_word(20, 'word', num_text=True, num_threshold=99)
'twenty words'
>>> plural_word(233, 'word', num_text=True, num_threshold=99)
'233 words'