检索与一个 WordNet 相关的所有单词

Retrieve all words related to one WordNet

我想用 WordNet

获取与 'food' 相关的所有单词
import nltk
from nltk.corpus import wordnet as wn
food = wn.synsets('food')

for synset in food:
   for lemma in synset.lemmas():
       print lemma.name()

通过这段代码我得到了这个:

food
nutrient
food
solid_food
food
food_for_thought
intellectual_nourishment

我想要实现的是这样的

食物
-> solid_food
-> liquid_food
-> powder_food

还有一些递归的东西,比如
solid_food
-> 蔬菜
-> 肉 ...

简而言之,我试图从一个词访问 Wordnet 的层次结构:'food'。
我该怎么做,知道吗?

您可以按照从一般术语到特定术语的关系 Hyponymy 探索层次结构:

Hyponymy shows the relationship between the more general terms (hypernyms) and the more specific instances of it (hyponyms).

ref

>>>  food[1].hyponyms()
[Synset('fish.n.02'), Synset('slop.n.04'), Synset('coconut.n.01'), 
Synset('baked_goods.n.01'), Synset('yogurt.n.01'), Synset('breakfast_food.n.01'), Synset('seafood.n.01'), Synset('cheese.n.01'), Synset('pasta.n.02'), Synset('meat.n.01'), Synset('leftovers.n.01'), Synset('butter.n.01'), Synset('produce.n.01'), Synset('convenience_food.n.01'), Synset('fresh_food.n.01'), Synset('junk_food.n.01'), Synset('dika_bread.n.01'), Synset('loaf.n.02'), Synset('chocolate.n.02'), Synset('health_food.n.01')]

也继续使用同义词。