是否可以在WordNet数据集上获得类?

问题描述 投票:0回答:1

我正在玩WordNet,并试图解决一个NLP任务。

我想知道是否存在任何方法来获得属于一些大型集合的单词列表,例如 "动物"(即狗、猫、牛等)、"国家"、"电子产品 "等。

我相信,应该可以通过利用超词来以某种方式获得这个列表。

额外的问题:除了 "名词"、"形容词 "和 "动词 "之外,你知道有什么其他的方法可以将非常大类的词进行分类吗?例如,像,"介词","连词 "等类。

nlp dataset nltk wordnet
1个回答
2
投票

是的,你只要检查这个类别是否是给定词的超义词。

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

如果广义词(这里的 "类别")是最低常见的超义词,那就说明它是查询词的直接超义词,所以查询词在类别中。

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


0
投票

在polm23的帮助下,我找到了这个解决方案,它利用了单词之间的相似性,并防止了类名模糊时的错误结果.其想法是,WordNet可以用来比较一个列表 words,其字符串为 animal,并计算出相似度得分。来自ltk.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

© www.soinside.com 2019 - 2024. All rights reserved.