如何访问 nltk/wordnet Synset 对象?

Urb*_*bKr 3 python nltk

from nltk.corpus import wordnet as wn 

print (wn.synsets('pretty')[0])
Run Code Online (Sandbox Code Playgroud)

此代码返回:

Synset('pretty.s.01')

但是,我似乎无法对这个类做任何事情。有没有办法从 Synset 中提取 'pretty.s.01' 字符串,以便我可以在 if 语句中比较它?

Fre*_*Foo 5

>>> s = wn.synsets('pretty')[0]
>>> s.lemma_names() #call the method to extract list
['pretty']
Run Code Online (Sandbox Code Playgroud)

请注意,这给出了一个引理列表;我不确定你什么时候会得到多个,但这似乎是可能的。

如果您想了解 a 上的其他操作Synset,请在解释器中调用helpdir