Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert plural nouns to singular NLP

Tags:

java

python

nlp

I have a list of plural nouns. For example, apples, oranges and etc. I would like to convert all of them to singular nouns. Is there any tools for this purpose? Prefer it to be Java or Python.

like image 996
edwin Avatar asked Nov 28 '15 14:11

edwin


People also ask

How do you pluralize singular nouns?

Grammar Most singular nouns are made plural by simply putting an -s at the end. There are many different rules regarding pluralization depending on what letter a noun ends in. Irregular nouns do not follow plural noun rules, so they must be memorized or looked up in the dictionary.

How do I use the verb ‘is’ with plural nouns?

The verb ‘is’ can only be used with singular nouns. For plural nouns, we use ‘are’. This problem is very common in the real world and we can correct this mistake by creating verb correction mappings that are used depending on whether there’s plural or singular noun in the chunk. The code above looks for the tag NNS to look for Plural Noun.

What is the correct way to spell plural?

The correct spelling of plurals usually depends on what letter the singular noun ends in. 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.

How do I correct the plural noun in a chunk of text?

This problem is very common in the real world and we can correct this mistake by creating verb correction mappings that are used depending on whether there’s plural or singular noun in the chunk. The code above looks for the tag NNS to look for Plural Noun.


2 Answers

There is for example https://pypi.python.org/pypi/inflect library.

Example:

import inflect
p = inflect.engine()

words = ["apples", "sheep", "oranges", "cats", "people", "dice", "pence"]

for word in words:
    print("The singular of ", word, " is ", p.singular_noun(word))

Output:

('The singular of ', 'apples', ' is ', 'apple')
('The singular of ', 'sheep', ' is ', 'sheep')
('The singular of ', 'oranges', ' is ', 'orange')
('The singular of ', 'cats', ' is ', 'cat')
('The singular of ', 'people', ' is ', 'person')
('The singular of ', 'dice', ' is ', 'die')
('The singular of ', 'pence', ' is ', 'pence')

Sources:

  • https://en.wikipedia.org/wiki/English_plurals#Miscellaneous_irregular_plurals
like image 81
Martin Vseticka Avatar answered Sep 29 '22 22:09

Martin Vseticka


You can use a Java Library, SimpleNLG (https://github.com/simplenlg/simplenlg) or use its Python Wrapper, PyNLG (https://github.com/mapado/pynlg) (pip install pynlg).

It has an extensive collection of Lexicons and can identify many object's number form. You can set its feature and print out its singular form. It works pretty good for simple tasks.

Lexicon lexicon = Lexicon.getDefaultLexicon();

NLGFactory nlgFactory = new NLGFactory(lexicon);

NPPhraseSpec subject = nlgFactory.createNounPhrase("apples"); subject.setFeature(Feature.NUMBER, NumberAgreement.SINGULAR);

will give "Apple". By default simpleNLG coverts all noun phrases it can identify to singular.

like image 37
Fleron-X Avatar answered Sep 29 '22 20:09

Fleron-X