我正在使用Python NLTK Wordnet API。我试图找到代表一组单词的最佳synset。
如果我需要找到“学校和办公用品”这样的最佳synset,我不确定该怎么做。到目前为止,我已经尝试查找每个单词的synset,然后像这样计算最佳的最低通用上位词:
def find_best_synset(category_name):
text = word_tokenize(category_name)
tags = pos_tag(text)
node_synsets = []
for word, tag in tags:
pos = get_wordnet_pos(tag)
if not pos:
continue
node_synsets.append(wordnet.synsets(word, pos=pos))
max_score = 0
max_synset = None
max_combination = None
for combination in itertools.product(*node_synsets):
for test in itertools.combinations(combination, 2):
score = wordnet.path_similarity(test[0], test[1])
if score > max_score:
max_score = score
max_combination = test
max_synset = test[0].lowest_common_hypernyms(test[1])
return max_synset
然而,这种方法并不是很有效,并且成本非常高。有没有办法找出最好地表示多个单词的同义词集?
感谢您的帮助!