gsi-upm / sematch

semantic similarity framework for knowledge graph
http://gsi-upm.github.io/sematch/
Other
432 stars 111 forks source link

'str' has no no attribute 'decode' #17

Closed clesleycode closed 6 years ago

clesleycode commented 7 years ago

I'm currently in Python3, which I believe isn't compatible with sematch right now (it's a bit unclear to me). I'm trying to run this code from the tutorial in Python3:

from sematch.semantic.similarity import WordNetSimilarity
wns = WordNetSimilarity()
wns.crossl_word_similarity('perro', 'cat', 'spa', 'eng', 'res')

I first got an error about a print statement, which I quickly fixed on line 36 in /Users/lesleycordero/anaconda3/lib/python3.6/site-packages/sematch/semantic/sparql.py

But now i'm stuck on this error:

AttributeError                            Traceback (most recent call last)
<ipython-input-35-1a68728fda46> in <module>()
----> 1 wns.crossl_word_similarity('perro', 'cat', 'spa', 'eng', 'res')
      2 

~/anaconda3/lib/python3.6/site-packages/sematch/utility.py in __call__(self, *args)
     77          return self.cache[args]
     78       else:
---> 79          value = self.func(*args)
     80          self.cache[args] = value
     81          return value

~/anaconda3/lib/python3.6/site-packages/sematch/semantic/similarity.py in crossl_word_similarity(self, w1, w2, lang1, lang2, name)
    357         :return: semantic similarity score
    358         """
--> 359         s1 = self.multilingual2synset(w1, lang1)
    360         s2 = self.multilingual2synset(w2, lang2)
    361         sim_metric = lambda x, y: self.similarity(x, y, name)

~/anaconda3/lib/python3.6/site-packages/sematch/semantic/similarity.py in multilingual2synset(self, word, lang)
    283         :return: wordnet synsets.
    284         """
--> 285         return wn.synsets(word.decode('utf-8'), lang=lang, pos=wn.NOUN)
    286 
    287 

AttributeError: 'str' object has no attribute 'decode'

I tried the following, but got the same error:

  1. taking out the .decode('utf-8') on line 285.
  2. casting word on 285 with unicode()
  3. changing word on 285 to word.encode().decode()
  4. changing w1 and w2 on lines 359 and 360 to w1.encode() and w2.encode()

(I tried this as per the instructions here.

Unfortunately still no luck.

clesleycode commented 6 years ago

this issue is solved, so i'll close it!

theslai commented 5 years ago

I know this is a bit old, but I'm running into the same problem, too. @lesley2958, what did you do to fix the issue?

khaledtouati commented 4 years ago

hi i have the same prob !! how did u fixed it!

MadhuPasula commented 3 years ago

drop .decode('utf-8') from word.decode('utf-8') in similarity.py.