为什么在实现`wordnet.synsets()`时出现属性错误?

时间:2020-05-01 08:57:57

标签: python wordnet

我试图在list中找到单词的某些同义词。这是我的代码:

test=['work','goat',...]
lst=[]

for i in range(len(test)):

    for s in wordnet.synsets(test[i]):
        for j in s.lemmas():
            lst.append(j.name()) 

但是我收到以下错误消息:AttributeError: 'generator' object has no attribute 'lower' for s in wordnet.synsets(test[i])。请帮助我。

1 个答案:

答案 0 :(得分:0)

我认为您的...列表中的省略号(test)可能有问题
这段代码对我有用(Win10上的python 3.8.2):

from nltk.corpus import wordnet

test = ['work','goat']
lst = []

for word in test:
    for s in wordnet.synsets(word):
        for j in s.lemmas():
            lst.append(j.name())