import nltk
from nltk import *
from nltk.corpus import wordnet as wn
output=[]
wordlist=[]
entries = nltk.corpus.cmudict.entries()
for entry in entries[:200]: #create a list of words, without the pronounciation since.pos_tag only works with a list
wordlist.append(entry[0])
for word in nltk.pos_tag(wordlist): #create a list of nouns
if(word[1]=='NN'):
output.append(word[0])
for word in output:
x = wn.synsets(word) #remove all words which does not have synsets (this is the problem)
if len(x)<1:
output.remove(word)
for word in output[:200]:
print (word," ",len(wn.synsets(word)))
我正在尝试删除所有没有同义词的单词,但由于某种原因它不起作用。运行程序后,我发现即使说一个词具有 len(wn.synsets(word)) = 0,它也不会从我的列表中删除。有人可以告诉我出了什么问题吗?