我想通过WordNet获得与“食物”相关的所有词语
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
- >蔬菜
- >肉......
简而言之,我试图用一个词来访问Wordnet的层次结构:'food' 我怎么能这样做,任何想法?
答案 0 :(得分:1)
您可以按照从一般术语到特定术语的关系Hyponymy
来探索层次结构:
Hyponymy显示了更一般的术语之间的关系 (上位词)及其更具体的实例(下位词)。
>>> 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')]
继续使用同义词。