如何在python nltk和wordnet中获取单词/同义词集的所有下位词? [英] How to get all the hyponyms of a word/synset in python nltk and wordnet?

查看:113
本文介绍了如何在python nltk和wordnet中获取单词/同义词集的所有下位词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个wordnet中所有名词的列表,现在我只想留下车辆中的单词并删除其余的单词.我该怎么做?下面是我要创建的伪代码,但我不知道如何使它工作

I have a list of all the nouns in wordnet now i want to leave only words which are vehicles and remove the rest. How do i do it? Below is the pseudo-code i want to make but i do not know how to make it work

for word in wordlist:
  if not "vehicle" in wn.synsets(word):
    wordlist.remove(word)

推荐答案

from nltk.corpus import wordnet as wn
vehicle = wn.synset('vehicle.n.01')
typesOfVehicles = list(set([w for s in vehicle.closure(lambda s:s.hyponyms()) for w in s.lemma_names()]))

这将为您提供来自每个同义词集的所有唯一词,它们是名词车辆"(第一感觉).

This will give you all the unique words from every synset that is a hyponym of the noun "vehicle" (1st sense).

这篇关于如何在python nltk和wordnet中获取单词/同义词集的所有下位词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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