Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

Python
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])  


What I have tried:

error:
AttributeError: 'list' object has no attribute 'wup_similarity'
Posted
Updated 18-Apr-22 20:27pm
Comments
0x01AA 18-Apr-22 13:46pm    
Why syn_sets should magically have an attribute wup_similarity? Therefore syn_sets.wup_similarity would be problematic.
boudinar soltana 19-Apr-22 9:53am    
How I print the matrix, because I write print(x) out of the boucle but when I excute, the result is empty matrix fill with zeros.

1 solution

Quote:
x[i,j]= syn_sets.wup_similarity(syn_sets1)
This should be, instead
Python
x[i,j]= syn_sets[i].wup_similarity(syn_sets1[j])
 
Share this answer
 
Comments
boudinar soltana 19-Apr-22 9:53am    
How I print the matrix, because I write print(x) out of the boucle but when I excute, the result is empty matrix fill with zeros.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900