如何在列表的每对元素之间计算语义相似性与wup_sibrility?

发布于 2025-01-21 21:55:21 字数 1032 浏览 2 评论 0原文

我有一个字符串列表,我想通过使用字符串的wup_simarility来计算每对之间的语义相似性之后创建一个矩阵视频,并用语义相似性的度量填充矩阵。

list=['empty', 'new', 'recent', 'warm', 'full', 'mixed', 'late', 
      'little', 'tentative', 'half', 'entree', 'tagliatelle', 
      'bolognese', 'asparagus', 'good', 'secondo', 'special', 'garlic', 
      'romanesco', 'bread', 'capable', 'comped', 
 'tasty', 'huge', 'hungry', 'crowd', 'former', 'able', 'Easy']
print(list)
import numpy as np
from nltk.corpus import wordnet
x = np.zeros((len(list), len(list)))
 
# print the matrix
print('The matrix is : \n', x)

for i in range(len(list)-1):  
    syn_sets = [wordnet.synsets(i) for i in list]
    #syn1 = wordnet.synsets(list[i])
    for j in range(len(list)-1):
        syn_sets1 = [wordnet.synsets(j) for j in list]
       # syn2 = wordnet.synsets(list[j])
        x[i,j]= syn_sets.wup_similarity(syn_sets1)
        
print(x[i,j])

错误 :

AttributeError: 'list' object has no attribute 'wup_similarity'

I have a list of strings and I want to create a matrix vide after that I want calculate the semantics similarity between each pair by using wup_similarity of string and fill the matrix with the measures of semantics similarity.

list=['empty', 'new', 'recent', 'warm', 'full', 'mixed', 'late', 
      'little', 'tentative', 'half', 'entree', 'tagliatelle', 
      'bolognese', 'asparagus', 'good', 'secondo', 'special', 'garlic', 
      'romanesco', 'bread', 'capable', 'comped', 
 'tasty', 'huge', 'hungry', 'crowd', 'former', 'able', 'Easy']
print(list)
import numpy as np
from nltk.corpus import wordnet
x = np.zeros((len(list), len(list)))
 
# print the matrix
print('The matrix is : \n', x)

for i in range(len(list)-1):  
    syn_sets = [wordnet.synsets(i) for i in list]
    #syn1 = wordnet.synsets(list[i])
    for j in range(len(list)-1):
        syn_sets1 = [wordnet.synsets(j) for j in list]
       # syn2 = wordnet.synsets(list[j])
        x[i,j]= syn_sets.wup_similarity(syn_sets1)
        
print(x[i,j])

error :

AttributeError: 'list' object has no attribute 'wup_similarity'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文