Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Generating the plural noun of a singular noun

Tags:

python

nlp

How could I use NLTK module to write both the noun's singular and plural form, or tell it not to differentiate between singular and plural when searching a txt file for a word? Can I use NLTK to make the program case insensitive?

like image 269
user5301912 Avatar asked Sep 04 '15 18:09

user5301912


People also ask

How do you change singular to plural in Python?

To convert plural to single just import singular module and use singular() function. It handles proper conversions for words with different endings, irregular forms, etc.

How do you make singular nouns plural?

1 To make regular nouns plural, add –s to the end. 2 If the singular noun ends in –s, –ss, –sh, –ch, –x, or –z, add -es to the end to make it plural.

Is Python singular or plural?

The plural form of python is pythons. Find more words!

How do you change a singular verb to plural?

How do you recognise a singular or plural verb? A singular verb is one that has an s added to it in the present tense, such as writes, plays, runs, and uses forms such as is, was, has, does. A plural verb does not have an s added to it, such as write, play, run, and uses forms such as are, were, have and do.


2 Answers

You can do this by using pattern.en, not too sure about NLTK

>>> from pattern.en import pluralize, singularize
>>>  
>>> print pluralize('child') #children
>>> print singularize('wolves') #wolf

see more

like image 186
taesu Avatar answered Sep 22 '22 12:09

taesu


It might be a bit late to answer but just in case someone is still looking for something similar:

There's inflect (also available in github) which support python 2.x and 3.x. You can find the singular or plural form of a given word:

import inflect
p = inflect.engine()

words = "cat dog child goose pants"
print([p.plural(word) for word in words.split(' ')])
# ['cats', 'dogs', 'children', 'geese', 'pant']

Is worth noticing that p.plural of a plural will give you the singular form. In addition, you can provide a POS (Part Of Speech) tag or to provide a number and the lib determines if it needs to be plural or singular:

p.plural('cat', 4)   # cats
p.plural('cat', 1)   # cat
# but also...
p.plural('cat', 0)   # cats
like image 26
jose.marcos.rf Avatar answered Sep 21 '22 12:09

jose.marcos.rf