i have list of words like amazing, interesting, love, great, nice. And i want to check if word is adjective or verb , like "love" is verb and nice is adjective... How to do it using python, or nltk, any help ?
Verbs always tell the time (also called the tense) of the sentence. The easiest way to find a verb in a sentence is to change the time of the sentence and find the word that changes.
if (val = = 'NN' or val = = 'NNS' or val = = 'NNPS' or val = = 'NNP' ): print (text, " is a noun." ) else : print (text, " is not a noun." )
The only way to guess what a word is without having any context is to use WordNet, but it won't be 100% reliable since for example "love" can have different roles in a sentence.
from nltk.corpus import wordnet as wn
words = ['amazing', 'interesting', 'love', 'great', 'nice']
for w in words:
tmp = wn.synsets(w)[0].pos()
print w, ":", tmp
Will output:
amazing : v
interesting : v
love : n
great : n
nice : n
An update to @Alex solution:
Code:
from nltk.corpus import wordnet as wn
words = ['amazing', 'interesting', 'love', 'great', 'nice']
pos_all = dict()
for w in words:
pos_l = set()
for tmp in wn.synsets(w):
if tmp.name().split('.')[0] == w:
pos_l.add(tmp.pos())
pos_all[w] = pos_l
print pos_all
Output:
{'interesting': set([u'a']),
'amazing': set([u's']),
'love': set([u'v', u'n']),
'great': set([u's', u'n']),
'nice': set([u'a', u's', u'n'])}
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