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.
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.
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.
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.
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.
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:
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.
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