Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Class advice impossible in Python3 topia.termextract

I am performing an nlp task. I have written the following code for topia.termextract. While executing it isshowing errors. It will be helpful, if you suggest to resolve the errors.

from topia.termextract import extract
from topia.termextract import tag

# Setup Term Extractor
extractor = extract.TermExtractor()

# Some sample text
text ='''
Police shut Palestinian theatre in Jerusalem.

Israeli police have shut down a Palestinian theatre in East Jerusalem.

The action, on Thursday, prevented the closing event of an international
literature festival from taking place."""

# Extract Keywords
keywords_topica = extractor(text)
print(keywords_topica)

I am using Python 3 in google colab.

---------------------------------------------------------------------------      
TypeError                                 Traceback (most recent call last)      
<ipython-input-23-9a094f024dfe> in <module>()      
 ----> 1 from topia.termextract import extract    
       2 from topia.termextract import tag     

 3 frames      
 /usr/local/lib/python3.6/dist-packages/zope/interface/declarations.py in implements(*interfaces)    
     481     # the coverage for this block there. :(     
     482     if PYTHON3:     
 --> 483         raise TypeError(_ADVICE_ERROR % 'implementer')    
     484     _implements("implements", interfaces, classImplements)    
     485      

     TypeError: Class advice impossible in Python3.  Use the @implementer class decorator instead.     
like image 844
shan Avatar asked Oct 15 '22 08:10

shan


1 Answers

To solve this, I added the following line:

from zope.interface import implementer

to both:

~/.local/lib/python3.8/site-packages/topia/termextract/extract.py

and:

~/.local/lib/python3.8/site-packages/topia/termextract/tag.py

.

Then in extract.py, I changed

class TermExtractor(object):
    zope.interface.implements(interfaces.ITermExtractor)

to:

@implementer(interfaces.ITermExtractor)
class TermExtractor(object):
    ...

And similarly, in tag.py,

class Tagger(object):
    zope.interface.implements(interfaces.ITagger)

to:

@implementer(interfaces.ITagger)
class Tagger(object):
    ...

Hope this helps!

like image 66
planetscape Avatar answered Oct 20 '22 09:10

planetscape