是否有可能在 WordNet 数据集上得到 类?

Is it possible to get classes on the WordNet dataset?

我正在玩 WordNet 并尝试解决 NLP 任务。

我想知道是否有任何方法可以获取属于一些大集合的单词列表,例如 "animals"(即狗、猫、牛等)、"countries"、"electronics"等

我相信应该可以通过利用上位词以某种方式获得此列表。

加分问题:除了 "noun"、"adjective" 和 "verb" 之外,您还知道对非常大的 类 中的单词进行分类的其他方法吗?例如,类,"prepositions","conjunctions"等

是的,您只需检查类别是否是给定词的上位词。

from nltk.corpus import wordnet as wn

def has_hypernym(word, category):
    # Assume the category always uses the most popular sense
    cat_syn = wn.synsets(category)[0]

    # For the input, check all senses
    for syn in wn.synsets(word):
        for match in syn.lowest_common_hypernyms(cat_syn):
            if match == cat_syn:
                return True
    return False

has_hypernym('dog', 'animal') # => True
has_hypernym('bucket', 'animal') # => False

如果上义词(这里的"category")是最常用的上位词,则表示它是查询词的直接上位词,所以查询词在该类别中。

关于你的奖金问题,我不知道你的意思。也许你应该看看 NER 或提出一个新问题。

在 polm23 的帮助下,我找到了这个解决方案,它利用单词之间的相似性,并在 class 名称不明确时防止错误结果。 这个想法是,WordNet 可用于比较列表 words 与字符串 animal,并计算相似度分数。来自 nltk.org 网页:

Wu-Palmer Similarity: Return a score denoting how similar two word senses are, based on the depth of the two senses in the taxonomy and that of their Least Common Subsumer (most specific ancestor node).

def keep_similar(words, similarity_thr):
    similar_words=[]
    w2 = wn.synset('animal.n.01')

    [similar_words.append(word) for word in words if wn.synset(word + '.n.01').wup_similarity(w2) > similarity_thr ]
    return similar_words

例如word_list = ['dog', 'car', 'train', 'dinosaur', 'London', 'cheese', 'radon'],对应的分数为:

0.875
0.4444444444444444
0.5
0.7
0.3333333333333333
0.3076923076923077
0.3076923076923077

通过设置适当的 similarity_thr

值,这可以很容易地用于生成动物列表