python - res_similarity() 函数的参数

标签 python nltk wordnet

我正在使用 resnik 相似度算法来查找两个同义词集之间的相似度,并且我在 python 中按以下方式使用它:

def get_maximum(synset1,synset2):
    maxSim = None
    for s1 in synset1:
          for s2 in synset2:
               sim = s1.res_similarity(s2)
               if maxSim == None or maxSim < sim:
                     maxSim = sim
    return maxSim

这里我收到以下错误:

Typeerror: res_similarity() takes at least 3 arguments (2 given)

有人能告诉我第三个参数是哪一个吗?

最佳答案

文档中的类型错误:

Raised when an operation or function is applied to an object of inappropriate type. The associated value is a string giving details about the type mismatch.

在您的情况下,您有一个名为 res_similarity() 的函数,需要接受 2 个参数。

您看到 3 和 2 的原因是因为它也有 self

例如 res_similarity(self, arg1, arg2) 您仅传递 1 个参数 - s2

您需要再向此方法传递一个参数

关于python - res_similarity() 函数的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21399258/

相关文章:

python - wordnet中的lemma和synset有什么联系或区别?

python - 如何批量插入或创建多个数据

python - 获取 Mechanize 中 br.forms() 的键和值

python - 当我从 virtualenv 运行 nosetests 时,为什么会出现错误 "Invalid command nosetests"?

python - 如何调用需要 "quotes"字符串的函数?

python - Wordnet:获取单词的派生相关形式

python - NLTK文档分类

python - nltk python 3 如果用户输入中有名词,如何返回 true?

algorithm - 词消歧算法(Lesk算法)

java - 如何使用 Wordnet 或任何其他 NLP 工具查找形容词的词根?