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



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

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

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

额外的问题:除了"名词"、"形容词"one_answers"动词",你知道还有什么其他方法可以把单词分类在很大的类别中吗?例如,"介词"、"连词"等类。

是的,您只需检查类别是否是给定单词的超名称。

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或者提出一个新的问题。

在polm23的帮助下,我找到了这个解决方案,它利用单词之间的相似性,并在类名不明确时防止错误结果。其思想是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的适当值,这可以很容易地用于生成动物列表

最新更新