Python 制作同义词簇

Python make clusters of synonyms

我有一长串单词:

verbs = ['be','have', 'find', 'use', 'show', 'increase', 'detect', 'do', 'determine', 'demonstrate', 'observe','suggest', ...]

我想根据这些词的同义词(语义接近)对这些词进行聚类。我想将列表中的每个元素与所有其他元素进行比较,对于相似度得分 > 0.7 的元素,将它们组合在一起。我正在使用 wordnet,但我一直收到此错误:

for i, verb in enumerate(verbs):
    for j in range(i + 1, len(verbs)):
        verbs[i].wup_similarity(verbs[j])


    ERROR MESSAGE : 
    ---->        verbs[i].wup_similarity(verbs[j])
    ---->        AttributeError: 'str' object has no attribute 'wup_similarity'

也许这甚至不是正确的方法,但有人可以帮忙吗?

关于更新的问题,这个解决方案适用于我的机器。

verbs = ['be','have', 'find', 'use', 'show', 'increase', 'detect', 'do', 'determine', 'demonstrate', 'observe','suggest']

for i, verb in enumerate(verbs):
    for j in range(i + 1, len(verbs)):
        v1 = wordnet.synset(verbs[i]+ '.v.01')
        v2 = wordnet.synset(verbs[j]+ '.v.01')
        wup_score = v1.wup_similarity(v2)
        if wup_score > 0.7:
            print(f"{verbs[i]} and {verbs[j]} are similar")
            #or do whatever you want to do with similar words.

关于原问题:

我不是这方面的专家,所以这可能根本没有帮助。目前你做 str.wup_similarity(str)。但是根据 this 文档(在该网站上搜索 'wup_similarity')我认为它应该是 synset1.wup_similarity(synset2).

所以我的建议是:

for i, verb in enumerate(verbs):
    for j in range(i + 1, len(verbs)):
        for syni in wordnet.synsets(verb[i]):
            for synj in wordnet.synsets(verb[j]):
                for li in syni.lemmas():
                    for lj in synj.lemmas():
                        v1 = wordnet.synset(verbs[i]+ '.v.01')
                        v2 = wordnet.synset(verbs[j]+ '.v.01')
                        v1.wup_similarity(v2)