NLTK-Python中的词义消歧

2024-06-01 10:35:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我是NLTK Python的新手,我正在寻找一些可以进行词义消歧的示例应用程序。我在搜索结果中有很多算法,但不是一个示例应用程序。我只想通过引用wordnet库来传递一个句子并了解每个单词的含义。 谢谢

我在PERL中找到了一个类似的模块。http://marimba.d.umn.edu/allwords/allwords.html NLTK Python中是否存在这样的模块?


Tags: 模块算法应用程序http示例单词wordnetperl
3条回答

最近,部分pywsd代码已移植到wsd.py模块中NLTK'的出血边缘版本中,请尝试:

>>> 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'

为了获得更好的WSD性能,请使用pywsd库而不是NLTK模块。一般来说,来自pywsdsimple_lesk()比来自NLTKlesk好。我会尽量在空闲时更新NLTK模块。


在回应Chris Spencer的评论时,请注意Lesk算法的局限性。我只是给出了算法的精确实现。不是银弹,http://en.wikipedia.org/wiki/Lesk_algorithm

也请注意,尽管:

lesk("My cat likes to eat mice.", "cat", "n")

不要给出正确的答案,可以使用pywsd实现max_similarity()

>>> 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'

@Chris,如果你想要一个python setup.py,只要做一个礼貌的请求,我就写出来。。。

是的,事实上,NLTK团队编写了a book,其中有多个关于分类的章节,并且它们显式地涵盖了how to use WordNet。你也可以从Safari购买这本书的实体版。

仅供参考:NLTK由自然语言编程学者编写,用于他们的编程入门课程。

相关问题 更多 >