Identify the word as a noun, verb or adjective

jonty rhodes picture jonty rhodes · Sep 5, 2015 · Viewed 12.9k times · Source

Given a single word such as "table", I want to identify what it is most commonly used as, whether its most common usage is noun, verb or adjective. I want to do this in python. Is there anything else besides wordnet too? I don't prefer wordnet. Or, if I use wordnet, how would I do it exactly with it?

Answer

Vidul picture Vidul · Sep 5, 2015
import nltk


text = 'This is a table. We should table this offer. The table is in the center.'
text = nltk.word_tokenize(text)
result = nltk.pos_tag(text)
result = [i for i in result if i[0].lower() == 'table']

print(result) # [('table', 'JJ'), ('table', 'VB'), ('table', 'NN')]