python - 错误 : Class advice impossible in Python3 topia. termextract

标签 python python-3.x nlp google-colaboratory keyword-search

我正在执行 nlp 任务。我为topia.termextract 编写了以下代码。执行时显示错误。如果您建议解决错误,这将很有帮助。

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)

我在 google colab 中使用 Python 3。
---------------------------------------------------------------------------      
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.     

最佳答案

为了解决这个问题,我添加了以下行:from zope.interface import implementer二者皆是:~/.local/lib/python3.8/site-packages/topia/termextract/extract.py和:~/.local/lib/python3.8/site-packages/topia/termextract/tag.py.
然后在extract.py中,我改了

class TermExtractor(object):
    zope.interface.implements(interfaces.ITermExtractor)
到:
@implementer(interfaces.ITermExtractor)
class TermExtractor(object):
    ...
同样,在 tag.py 中,
class Tagger(object):
    zope.interface.implements(interfaces.ITagger)
到:
@implementer(interfaces.ITagger)
class Tagger(object):
    ...
希望这可以帮助!

关于python - 错误 : Class advice impossible in Python3 topia. termextract,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59332776/

相关文章:

python - 如何将具有动态维度的张量的每个 2D 元素乘以静态 2D 掩码?

python - 在 pandas python 中将列值转换为行值时出现问题?

python - 计算元组列表中项目的频率

python - 比较同义词 NLTK

nlp - 概率潜在语义分析/索引 - 简介

python - 在 SciPy 中生成您自己的颜色图

python - 我无法抓取网站的 div 参数(scrapy)

mysql - 尝试使用 sqlobject 和 python 3 添加数据和查询 mysql 数据库

r - 使用 R 进行荷兰语情感分析

python - 通过将 sklearn.predict 传递给 df.apply 对 Pandas 数据帧进行行式预测