edwin
edwin

Reputation: 1252

convert plural nouns to singular 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.

Upvotes: 8

Views: 8218

Answers (2)

Fleron-X
Fleron-X

Reputation: 242

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.

Upvotes: 2

MartyIX
MartyIX

Reputation: 28686

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:

Upvotes: 11

Related Questions