首页 > 解决方案 > 无法在 python 中找到 wordnet 同义词集

问题描述

我有功能

def find_n_similar():
    word = input("please enter a word: ")
    word_syntest = wordnet.synsets(word)[0]
    print(word_syntest)
    similarity_rate = {}
    with open("1-1000.txt", 'r') as file:
        file_words = file.read().split("\n")
    print(file_words)
    for file_word in file_words:
        file_word_syntest = wordnet.synsets(file_word)
        similarity_rate.update({f"{file_word}": word_syntest.path_similarity(file_word_syntest)})

如果我输入“the”、“of”等,它会抛出异常:IndexError: list index out of range 我怎样才能找到这些词的同义词?

标签: pythonnltkwordnet

解决方案


WordNet 并不真正做文章。:(从他们的主页

名词、动词、形容词和副词被分组为一组认知同义词(synsets)

这很糟糕,但无论如何“the”或“a”都没有同义词,对吧?


推荐阅读