【问题标题】:How to get wordnet domains hierarchy in python?如何在 python 中获取 wordnet 域层次结构?
【发布时间】:2013-06-09 21:21:04
【问题描述】:

我有一个关键字,例如“SPORTS”。我需要拥有它的所有第一个孩子,即下一个层次结构。所以我应该得到[板球、足球、网球、曲棍球]之类的东西。

【问题讨论】:

  • 欢迎来到 StackOverflow。请考虑在您的问题中添加您的实际代码以及您遇到的具体问题,以便社区更容易为您提供帮助。

标签: python-2.7 nltk wordnet


【解决方案1】:

它应该像这样工作(假设您使用的是 nltk):

from nltk.corpus import wordnet as wn
sport = wn.synset('sport.n.01')
sport.hyponyms() 

【讨论】:

    【解决方案2】:

    如果您正在寻找递归下位词,试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-02
      • 1970-01-01
      • 2012-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多