什么是好的 Python 同义词库和分类库?

发布于 2024-08-18 01:07:32 字数 1539 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柏拉图鍀咏恒 2024-08-25 01:07:32

pywordnet,现在是 NLTK

pywordnet, now part of NLTK

¢好甜 2024-08-25 01:07:32

NLTK

安装

您可能需要超级用户权限:

$ pip install nltk

>>> import nltk
>>> from nltk.corpus import wordnet as wn

>>> wn.synsets('dog')
[Synset('dog.n.01'), Synset('frump.n.01'), Synset('dog.n.03'), Synset('cad.n.01'), Synset('frank.n.02'), Synset('pawl.n.01'), Synset('andiron.n.01'), Synset('chase.v.01')]

>>> wn.synset('dog.n.01').definition()
u'a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds'

>>> wn.synset('dog.n.03').definition()
u'informal term for a man'

>>> baseball = wn.synset('baseball.n.01')
>>> sport = wn.synset('sport.n.01')
>>> picture = wn.synset('picture.n.01')

>>> sport.path_similarity(baseball)
0.16666666666666666

>>> sport.path_similarity(picture)
0.06666666666666667

NLTK

Installation

You might need superuser rights for that:

$ pip install nltk

Usage

>>> import nltk
>>> from nltk.corpus import wordnet as wn

>>> wn.synsets('dog')
[Synset('dog.n.01'), Synset('frump.n.01'), Synset('dog.n.03'), Synset('cad.n.01'), Synset('frank.n.02'), Synset('pawl.n.01'), Synset('andiron.n.01'), Synset('chase.v.01')]

>>> wn.synset('dog.n.01').definition()
u'a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds'

>>> wn.synset('dog.n.03').definition()
u'informal term for a man'

>>> baseball = wn.synset('baseball.n.01')
>>> sport = wn.synset('sport.n.01')
>>> picture = wn.synset('picture.n.01')

>>> sport.path_similarity(baseball)
0.16666666666666666

>>> sport.path_similarity(picture)
0.06666666666666667
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文