不能用巴贝鱼翻译

2024-06-16 13:25:03 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我试着用nltk和babelfish来学习机器翻译,但是每当我尝试使用babelfish方法时,总是会出现这些错误:

>>> import yahoo
>>> import nltk
>>> from nltk.misc import babelfish
>>> babelfish.translate('cookbook', 'english', 'spanish')
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python2.7/dist-packages/nltk/misc/babelfish.py", line 106, in  translate
    if not match: raise BabelfishChangedError("Can't recognize translated string.")
    nltk.misc.babelfish.BabelfishChangedError: Can't recognize translated string.
>>> for text in babelfish.babelize('cookbook', 'english', 'spanish'):
...   print text
... 
cookbook
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/nltk/misc/babelfish.py", line 126, in babelize
phrase = translate(phrase, next, flip[next])
File "/usr/lib/python2.7/dist-packages/nltk/misc/babelfish.py", line 106, in translate
if not match: raise BabelfishChangedError("Can't recognize translated string.")
nltk.misc.babelfish.BabelfishChangedError: Can't recognize translated string.

我做错什么了?在


Tags: inimportstringusrlinecantranslatefile
1条回答
网友
1楼 · 发布于 2024-06-16 13:25:03

代码没有问题,只是babelfishAPI不再可用,这使得nltkapi to babelfish void=(

它也从NLTK的最新版本中删除,请参见https://github.com/nltk/nltk/issues/265

相关问题 更多 >