Closed fezzik1620 closed 1 year ago
Found this old bug that was purportedly fixed (#5). But this does seem to be the same issue. As, if I run the same code above, but change the word from "Entity" to "entity", it works.
>>> import inflect
>>> word="entity"
>>> print(f'The plural of "{word}" is "{inflect.engine().plural(word)}".')
The plural of "entity" is "entities".
>>> print(f'The plural of "{word}" is "{inflect.engine().plural_noun(word)}".')
The plural of "entity" is "entities".
So, it is specifically a problem when the first letter is capitalized.
Dug through and found more closed issues.
So, since the owner doesn't think this is a problem (seems like this could be handled with a flag), but I have a case where I do commonly have a capitalized inputs but, in my case, they would never be proper nouns, I created this wrapper function.
import inflect
inflect_engine = inflect.engine()
def get_plural_of(singular):
"""
Given the singular form of a word, returns the plural form. This function is a wrapper of the inflect plugin. Any
word that begins with a capital letter and ends with a 'y', it assumes is a proper noun, and thus just throws an
's' on the end. "Entity" becomes "Entitys". The developer doesn't see this as a problem. So this function tries to
deal with those cases by converting it to lowercase, running it through the plural method and then converting the
case back.
@param singular: singular form of a noun or noun phrase to pluralize
@return: Plural form of the input in the same capitalization as the input.
"""
lowercase = singular.lower()
plural = inflect_engine.plural(lowercase)
if singular == singular.upper():
plural = plural.upper()
elif singular == singular.capitalize():
plural = plural.capitalize()
return plural
It's not fool proof, by a long shot, but it fits my needs; thought it might help someone else too.
This is a duplicate of #5.