我正在使用Python NLTK Wordnet API.我正在尝试找到代表一组单词的最佳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
Run Code Online (Sandbox Code Playgroud)
然而,这不是很好,而且成本很高.有没有办法找出哪个synset最能代表多个单词?
谢谢你的帮助!