不能用babelfish翻译

时间:2014-08-05 06:55:44

标签: python nlp nltk yahoo-api machine-translation

所以我正在尝试用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.

我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

代码没有任何问题,只是babelfish API不再可用,这使得NLTK API无法使用虚拟=(

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