Package nltk :: Package misc :: Module babelfish
[hide private]
[frames] | no frames]

Module babelfish

source code

API for simple access to babelfish.altavista.com.

Summary:

>>> import babelizer
>>> print ' '.join(babelizer.available_languages)
>>> print babelizer.translate( 'How much is that doggie in the window?',
                               'English', 'French' )
>>> def babel_callback(phrase):
       print phrase
       sys.stdout.flush()
>>> babelizer.babelize( 'I love a reigning knight.',
                        'English', 'German',
                        callback = babel_callback )

Version: $Id: babelfish.py 1361 2003-10-24 14:41:44Z edloper $

Author: Jonathan Feinberg <jdf@pobox.com>

Classes [hide private]
BabelizerError
Calling translate() or babelize() can raise a BabelizerError
BabelfishChangedError
Thrown when babelfish.yahoo.com changes some detail of their HTML layout, and babelizer no longer submits data in the correct form, or can no longer parse the results.
BabelizerIOError
Thrown for various networking and IO errors.
Functions [hide private]
 
translate(phrase, source, target)
Use babelfish to translate phrase from source language to target language.
source code
 
babelize(phrase, source, target, limit=12)
Uses babelfish to translate back and forth between source and target until either no more changes occur in translation or limit iterations have been reached, whichever comes first.
source code
 
babelize_shell()
An interactive shell that uses babelfish to translate back and forth between source and target until either no more changes occur in translation or limit iterations have been reached, whichever comes first.
source code
    Helper Functions
 
clean(text) source code
Variables [hide private]
  __where = [re.compile(r'<div id="result"><div style="padding:0...
  __languages = {'chinese': 'zh', 'english': 'en', 'french': 'fr...
All of the available language names.
  available_languages = ['Portuguese', 'Chinese', 'German', 'Eng...
A list of languages available for use with babelfish.
  HELP = 'NLTK Babelizer Commands:\nAll single-word inputs are c...
  x = 'italian'
Function Details [hide private]

translate(phrase, source, target)

source code 

Use babelfish to translate phrase from source language to target language. It's only guaranteed to work if 'english' is one of the two languages.

Raises:
  • BabelizeError - If an error is encountered.

babelize(phrase, source, target, limit=12)

source code 

Uses babelfish to translate back and forth between source and target until either no more changes occur in translation or limit iterations have been reached, whichever comes first. It's only guaranteed to work if 'english' is one of the two languages.

Raises:
  • BabelizeError - If an error is encountered.

babelize_shell()

source code 

An interactive shell that uses babelfish to translate back and forth between source and target until either no more changes occur in translation or limit iterations have been reached, whichever comes first. It's only guaranteed to work if 'english' is one of the two languages.

Raises:
  • BabelizeError - If an error is encountered.

Variables Details [hide private]

__where

Value:
[re.compile(r'<div id="result"><div style="padding:0.6em;">([^<]*)'),
 re.compile(r'name="q">([^<]*)'),
 re.compile(r'td bgcolor=white>([^<]*)'),
 re.compile(r'</strong><br>([^<]*)'),
 re.compile(r'padding:10px[^>]+>([^<]*)')]

__languages

All of the available language names.

Value:
{'chinese': 'zh',
 'english': 'en',
 'french': 'fr',
 'german': 'de',
 'greek': 'el',
 'italian': 'it',
 'japanese': 'ja',
 'korean': 'ko',
...

available_languages

A list of languages available for use with babelfish.
Value:
['Portuguese',
 'Chinese',
 'German',
 'English',
 'Japanese',
 'French',
 'Greek',
 'Spanish',
...

HELP

Value:
'''NLTK Babelizer Commands:
All single-word inputs are commands:
help: this help message
languages: print the list of languages
language: the name of a language to use'''