热线电话:13121318867

登录
2019-03-18 阅读量: 688
如何使用nltk 计算单词相似度

import nltk

from nltk.corpus import wordnet

# Let's compare the noun of "ship" and "boat:"

w1 = wordnet.synset('run.v.01') # v here denotes the tag verb

w2 = wordnet.synset('sprint.v.01')

print(w1.wup_similarity(w2))

输出:

0.857142857143

w1 = wordnet.synset('ship.n.01')

w2 = wordnet.synset('boat.n.01') # n denotes noun

print(w1.wup_similarity(w2))

输出:

0.9090909090909091

0.0000
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子