gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 17:12:41 29 4
gpt4 key购买 nike

我正在执行 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com