如何在word net中找到名词到其根节点的距离? [英] How can I find the distance from a noun to its root node in word net?

查看:63
本文介绍了如何在word net中找到名词到其根节点的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道句子中某个词的具体程度.因此,为了做到这一点,我所采取的假设是单词在 wordnet 的上位词层次结构中越低,它就会越具体.但是我无法编写一个代码来给出名词词与其根上位词之间的节点数,即entity.n.01",我正在尝试使用 nltk 的 wordnet 来做到这一点.请在这方面帮助我.

I want to find how specific a word in my sentence is. So for doing that the assumption that I have taken is the lower a word is in wordnet's hypernym hierarchy it is going to be more specific. But I am not able to write a code that is going to give the number of nodes between a noun word and its root hypernym which is 'entity.n.01' and I am trying to do that using wordnet of nltk. Please help me in this regard.

任何帮助将不胜感激.

推荐答案

试试这个...

from nltk.corpus import wordnet as wn
ss = wn.synset('car.n.01')
print min([len(path) for path in ss.hypernym_paths()])

hypernym_paths() 为您提供返回根的可能路径列表,对于名词来说,它是 entity.n.01.

hypernym_paths() gives you a list of the possible paths back to the root, which for a noun is entity.n.01.

这篇关于如何在word net中找到名词到其根节点的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆