Find file
Fetching contributors…
Cannot retrieve contributors at this time
26 lines (22 sloc) 761 Bytes
Translating Text with Babelfish
>>> from nltk.misc import babelfish
>>> babelfish.translate('cookbook', 'english', 'spanish')
'libro de cocina'
>>> babelfish.translate('libro de cocina', 'spanish', 'english')
'kitchen book'
>>> babelfish.translate('cookbook', 'english', 'german')
>>> babelfish.translate('kochbuch', 'german', 'english')
'cook book'
>>> for text in babelfish.babelize('cookbook', 'english', 'spanish'):
... print text
libro de cocina
kitchen book
libro de la cocina
book of the kitchen
>>> babelfish.available_languages
['Portuguese', 'Chinese', 'German', 'Japanese', 'French', 'Spanish', 'Russian', 'Greek', 'English', 'Korean', 'Italian']