Exemplo n.º 1
0
def translate(text, source, target, trace=1, sleep=1, retries=1):
	try:
		return babelfish.translate(text, source, target)
	except babelfish.BabelizerIOError as exc:
		if retries:
			if trace:
				print 'IO error in translation, trying again after %ss' % sleep
			
			time.sleep(sleep)
			return translate(text, source, target, sleep, retries=retries-1)
		else:
			raise exc
	except babelfish.BabelfishChangedError as exc:
		if trace:
			print 'error getting translation for:', text, '::', exc
		
		return ''
Exemplo n.º 2
0
def translate(text, source, target, trace=1, sleep=1, retries=1):
    try:
        return babelfish.translate(text, source, target)
    except babelfish.BabelizerIOError as exc:
        if retries:
            if trace:
                print 'IO error in translation, trying again after %ss' % sleep

            time.sleep(sleep)
            return translate(text, source, target, sleep, retries=retries - 1)
        else:
            raise exc
    except babelfish.BabelfishChangedError as exc:
        if trace:
            print 'error getting translation for:', text, '::', exc

        return ''
Exemplo n.º 3
0
def translate_document(source_lang,target_lang,document):
	from nltk.misc import babelfish
	return babelfish.translate(document,source_lang,target_lang)