Given a word, which may or may not be a singular-form noun, how would you generate its plural form?
Based on this NLTK tutorial and this informal list on pluralization rules, I wrote this simple function:
def plural(word):
"""
Converts a word to its plural form.
"""
if word in c.PLURALE_TANTUMS:
# defective nouns, fish, deer, etc
return word
elif word in c.IRREGULAR_NOUNS:
# foot->feet, person->people, etc
return c.IRREGULAR_NOUNS[word]
elif word.endswith('fe'):
# wolf -> wolves
return word[:-2] + 'ves'
elif word.endswith('f'):
# knife -> knives
return word[:-1] + 'ves'
elif word.endswith('o'):
# potato -> potatoes
return word + 'es'
elif word.endswith('us'):
# cactus -> cacti
return word[:-2] + 'i'
elif word.endswith('on'):
# criterion -> criteria
return word[:-2] + 'a'
elif word.endswith('y'):
# community -> communities
return word[:-1] + 'ies'
elif word[-1] in 'sx' or word[-2:] in ['sh', 'ch']:
return word + 'es'
elif word.endswith('an'):
return word[:-2] + 'en'
else:
return word + 's'
But I think this is incomplete. Is there a better way to do this?
A plural noun indicates that there is more than one of that noun (while a singular noun indicates that there is just one of the noun). Most plural forms are created by simply adding an -s or –es to the end of the singular word. For example, there's one dog (singular), but three dogs (plural).
The pattern-en package offers pluralization
>>> import pattern.en
>>> pattern.en.pluralize("dog")
'dogs'
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With