'Synset' object has no attribute 'path_similarity'

32 Views Asked by At

I'm attempting to do one of the assignments in Text Mining class offered by Coursera. Basically, I'm trying to write a function that returns the normalized similarity score of a list of synsets (s1) onto another list of synsets (s2). Additionally, for each synset in s1, I need to find the synset in s2 with the largest similarity value. Then, sum all of the largest similarity values together and normalize the value by dividing it by the number of largest similarity values found. Here is the code I have so far:

import numpy as np
import nltk
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')
nltk.download('wordnet')
from nltk.corpus import wordnet as wn
import pandas as pd
nltk.data.path.append("assets/")
import wn
from wn.similarity import path

def similarity_score(s1, s2):
    val_list = []
    for i in s1:
        scores=[]
        for j in s2:
            k = i.path_similarity(j)
            if k is not None:
                scores.append(k)
        if scores:
            val_list.append(max(scores))
    return sum(val_list)/len(val_list)

I used the path_similarity attribute or trying to use it. But I'm getting the following error:

Exception has occurred: AttributeError
'Synset' object has no attribute 'path_similarity'
  File "C:\Users\Anbara\Desktop\Introduction to Data Science with Python\assignment4_test_mining.py", line 33, in similarity_score
    k = i.path_similarity(j)
        ^^^^^^^^^^^^^^^^^
  File "C:\Users\Anbara\Desktop\Introduction to Data Science with Python\assignment4_test_mining.py", line 46, in <module>
    print(similarity_score(synsets1, synsets2))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Synset' object has no attribute 'path_similarity'

I'm very new to nltk any help or suggestions/explainations would be appreciated.

0

There are 0 best solutions below