Esempio n. 1
0
    def setup(self):
        self.commands = CommandManager()
        self.goslate = Goslate()

        self.commands.register_command("translate", self.translate_command,
                                       self, "translate.translate",
                                       ["tr", "t"], True)
Esempio n. 2
0
 def __init__(self, application=None):
     self.application = application
     self.genroroot = getGenroRoot()
     try:
         from goslate import Goslate
         self.translator = Goslate()
         self.languages = self.translator.get_languages()
     except:
         self.translator = False
         self.languages = dict(en='English', it='Italian')
     roots = [
         os.path.join(self.genroroot, n)
         for n in ('gnrpy/gnr', 'gnrjs', 'resources/common',
                   'resources/mobile')
     ]
     self.slots = [
         dict(roots=roots,
              destFolder=self.genroroot,
              code='core',
              protected=True,
              language='en')
     ]
     for p in self.application.packages.values():
         self.slots.append(
             dict(roots=[p.packageFolder],
                  destFolder=p.packageFolder,
                  code=p.id,
                  protected=(p.project == 'gnrcore'),
                  language=p.language))
     #if os.path.exists(self.application.customFolder):
     #    self.slots.append(dict(roots=[self.application.customFolder],destFolder=self.application.customFolder,
     #                                code='customization',protected=False))
     self.buildLocalizationDict()
Esempio n. 3
0
    def get_translation(self, email):
        """returns translation"""
        go = Goslate()

        #=====[ Step 1: get translation	]=====
        lang = email.subject.strip().lower().capitalize()
        langs = go.get_languages()
        if lang in langs.values():
            lang_code = [k for k, v in langs.items() if langs[k] == lang][0]
            try:
                translation = go.translate(email.body, lang_code)
            except:
                translation = "Translation error."
        else:
            translation = u'%s no esta soportado intente con es/en/fr' % lang

        #=====[ Step 2: format	]=====
        return """
Traduccion para:
================

%s
---

%s
""" % (email.subject.strip().encode(
            'ascii', 'ignore'), translation.encode('ascii', 'ignore'))
Esempio n. 4
0
 def translation(self):
     """
     Translate text using Google translator.
     """
     if 'translation' in self.js:
         translation = self.js['translation']
     else:
         gs = Goslate()
         translation = gs.translate(self.text_with_title, 'en')
         self.add_key(key='translation', value=translation)
     return translation
    def get_features(self, context_obj):
        if 'source' not in context_obj:
            raise NoDataError('source', context_obj,
                              'GoogleTranslateFeatureExtractor')

        if 'pseudo-reference' in context_obj:
            translation = context_obj['pseudo-reference']
        else:
            gs = Goslate()
            translation = word_tokenize(
                gs.translate(' '.join(context_obj['source']), self.lang))
        if context_obj['token'] in translation:
            return [1]
        return [0]
Esempio n. 6
0
 def __init__(self, group):
     self.group = group
     self.__consts = Constants()
     self.__settings = Settings()
     self.__trans = Goslate()
     self.obj = json.loads(self.__consts.WANCAK_RAND.read())
Esempio n. 7
0
import re
from urllib import parse
from math import log

from goslate import Goslate
from publicsuffix import PublicSuffixList
from unidecode import unidecode

import keywords

###################
# initializations #
###################


g = Goslate()

stopwords = pickle.load(open("data/stopwords_dict", 'rb'))

psl = PublicSuffixList(open("data/public_suffix_list.dat", encoding="utf8"))

document_frequencies = {}
with open("data/count_1w.txt") as f:
    for line in f:
        key, value = line.strip().split()
        document_frequencies[key] = int(value)


#########
# UTILS #
#########
Esempio n. 8
0
 def __init__(self):
     self.t = Goslate()
Esempio n. 9
0
        print(game.get_hangman())
        print(game.get_position())
        game_over = not game.get_status() == 'guessing'

    if game.get_status() == 'won':
        print('Congratulations! You guessed the word correctly.')
    else:
        print(f'The word to be guessed is: {game.get_word()}')
        print('I am sure you will do better next time. :)\n')

    # This section is different from the other example.
    # It helps the player learn something new about word they did not guess.

    # PyDictionary uses Goslate to translate text. Hence, Goslate is used to
    # get the avialable languages.
    gs = Goslate()
    languages = list(gs.get_languages())

    dictionary = PyDictionary(game.get_word())
    func_dict = {
        'Synonyms': dictionary.getSynonyms,
        'Antonyms': dictionary.getAntonyms,
        'Translation': dictionary.translateTo
    }

    lang = random.choice(languages)
    func_name = random.choice(list(func_dict.keys()))
    function = func_dict[func_name]

    if func_name == 'Translation':
        fun_fact = function(language=lang)[0]
Esempio n. 10
0
 def __init__(self, lang='en'):
     self.lang = lang
     self.gs = Goslate()