>>> from nltk.wsd import lesk
>>> sent = 'I went to the bank to deposit my money'
>>> ambiguous = 'bank'
>>> lesk(sent, ambiguous)
Synset('bank.v.04')
>>> lesk(sent, ambiguous).definition()
u'act as the banker in a game or in gambling'
>>> from pywsd.similarity import max_similiarity
>>> max_similarity('my cat likes to eat mice', 'cat', 'wup', pos='n').definition
'feline mammal usually having thick soft fur and no ability to roar: domestic cats; wildcats'
>>> max_similarity('my cat likes to eat mice', 'cat', 'lin', pos='n').definition
'feline mammal usually having thick soft fur and no ability to roar: domestic cats; wildcats'
最近,部分
pywsd
代码已移植到wsd.py
模块中NLTK
'的出血边缘版本中,请尝试:为了获得更好的WSD性能,请使用
pywsd
库而不是NLTK
模块。一般来说,来自pywsd
的simple_lesk()
比来自NLTK
的lesk
好。我会尽量在空闲时更新NLTK
模块。在回应Chris Spencer的评论时,请注意Lesk算法的局限性。我只是给出了算法的精确实现。不是银弹,http://en.wikipedia.org/wiki/Lesk_algorithm
也请注意,尽管:
不要给出正确的答案,可以使用
pywsd
实现max_similarity()
:@Chris,如果你想要一个python setup.py,只要做一个礼貌的请求,我就写出来。。。
是的,事实上,NLTK团队编写了a book,其中有多个关于分类的章节,并且它们显式地涵盖了how to use WordNet。你也可以从Safari购买这本书的实体版。
仅供参考:NLTK由自然语言编程学者编写,用于他们的编程入门课程。
参考http://jaganadhg.freeflux.net/blog/archive/2010/10/16/wordnet-sense-similarity-with-nltk-some-basics.html
相关问题 更多 >
编程相关推荐