在NLTK 3.0中使用Wordnet从Synset提取Word [英] Extract Word from Synset using Wordnet in NLTK 3.0
问题描述
Some time ago, someone on SO asked how to retrieve a list of words for a given synset using NLTK's wordnet wrapper. Here is one of the suggested responses:
for synset in wn.synsets('dog'):
print synset.lemmas[0].name
在NLTK 3.0中运行此代码将产生TypeError: 'instancemethod' object is not subscriptable
.
Running this code with NLTK 3.0 yields TypeError: 'instancemethod' object is not subscriptable
.
我尝试了每个先前提出的解决方案(上面链接页面上描述的每个解决方案),但是每个都抛出错误.因此,我想问:NLTK 3.0是否可以为同义词集列表打印单词?对于其他人可以就此问题提供的任何建议,我将深表感谢.
I tried each of the previously-proposed solutions (each of the solutions described on the page linked above), but each throws an error. I therefore wanted to ask: Is it possible to print the words for a list of synsets with NLTK 3.0? I would be thankful for any advice others can offer on this question.
推荐答案
WordNet在NLTK 3.0中工作正常.您只是以错误的方式访问了引理(和名称).尝试以下方法:
WordNet works fine in NLTK 3.0. You are just accessing the lemmas (and names) in the wrong way. Try this instead:
>>> import nltk
>>> nltk.__version__
'3.0.0'
>>> from nltk.corpus import wordnet as wn
>>> for synset in wn.synsets('dog'):
for lemma in synset.lemmas():
print lemma.name()
dog
domestic_dog
Canis_familiaris
frump
dog
dog
cad
bounder
blackguard
...
synset.lemmas
是一种方法,没有__getitem__()
方法(因此不能下标).
synset.lemmas
is a method and does not have a __getitem__()
method (and so is not subscriptable).
这篇关于在NLTK 3.0中使用Wordnet从Synset提取Word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!