Beispiel #1
0
 def __init__(self, script):
     script = script.encode("utf-8", "ignore")
     script = script.decode("utf-8")
     trans = Translator(script)
     reload(sys)
     sys.setdefaultencoding('utf8')
     self.script = trans.translate(script)
Beispiel #2
0
 def merge(self, props1, props2):
     props = []
     if props1 != None:
         for k in props1[1]['Books'][props1[0]]['properties'].keys():
             prop, value = k, props1[1]['Books'][props1[0]]['properties'][k]
             props.append([prop, value])
     if props2 != None:
         for k in props2[1]['Books'][props2[0]]['properties'].keys():
             prop, value = k, props2[1]['Books'][props2[0]]['properties'][k]
             flag = False
             for j in range(0, len(props)):
                 if props and k == props[j][0]:
                     props[j][1] += ", " + value
                     flag = True
             if not flag:
                 props.append([prop, value])
     tr = t.Translator(b.tr_mapfile)
     simul = []
     for proop in range(0, len(props)):
         lfirst = props[proop][0]
         lsecond = props[proop][1]
         lsecond = lsecond.replace('\n', '')
         lsecond = re.sub(r'\s+', ' ', lsecond)
         lsecond_fixed = ""
         for i in lsecond.split(' '):
             lsecond_fixed += tr.translate(i) + " "
         props[proop][1] = lsecond_fixed
     return props
Beispiel #3
0
    def pull_props(self, data):
        props = []
        pieces = []
        name = None
        tr = t.Translator(b.tr_mapfile)

        f1 = open(b.main_dir + '/' + b.RTUD_DIR + b.THERE + b.AZON_DIR + b.THERE + b.AZON_DIR + ".json", "r",  encoding='utf-8')
        data1 = json.load(f1)
        f1.close()
        for book in range(0, len(data1['Books']) - 1):
            name = data1['Books'][book]["Name"].split('–')[0].split(':')[0]
            part = data1['Books'][book]["Part"]
            if tr.diff_cmp(name, data[0], 200) and tr.diff_cmp(part, data[1], 0):
                props.append((book, data1))
                break
        if len(props) == 0:
            props.append(None)
        pieces = []
        f2 = open(b.main_dir + '/' + b.RTUD_DIR + b.THERE + b.BOOKDEPOSITORY_DIR + b.THERE + b.BOOKDEPOSITORY_DIR + ".json", "r")
        data2 = json.load(f2)
        f2.close()
        for book in range(0, len(data2['Books']) - 1):
            name = data2['Books'][book]["Name"].split('–')[0].split(':')[0]
            if name.replace(' ', '') == data[2].replace(' ', ''):
                props.append((book, data2))
                break
        if len(props) == 1:
            props.append(None)
        return props[0], props[1]
 def __init__(self, quiz):
     global myTranslator
     global wordSetIndex
     global wordSets
     global tenseSets
     global subjectSet
     wordSetIndex = quiz
     wordSets = {
         1: [
             'hablar', 'vivir', 'estar', 'ser', 'dar', 'hacer', 'decir',
             'dormir', 'escribir', 'saber', 'salir', 'ver', 'trabajar',
             'oír', 'comer'
         ],
         2: [
             'querer', 'ver', 'socializar', 'poner', 'morir', 'hacer',
             'decir', 'escribir', 'conocer', 'cambiar', 'abrir',
             'descubrir', 'romper', 'educar', 'desempeñar'
         ]
     }
     tenseSets = {
         1: ['present', 'preterite', 'imperfect', 'subjunctive'],
         2: ['ppi, pps']
     }
     subjectSet = ['yo', 'tu', 'el/ella', 'nosotros', 'ellos/ellas']
     myTranslator = Translator.Translator()
Beispiel #5
0
def test():
    translator = Translator('template.mapping')
    filename = 'template.dat'
    f = open(filename, 'r')
    assert f, "error when open %s" % filename
    content = f.read()
    print('before: \n%s\n' % content)
    translation = translator.translate(content)
    print('after: \n%s\n' % translation)
Beispiel #6
0
 def easy_turn_data(self, lang, pieces):
     tr = t.Translator(b.tr_mapfile)
     lsecond_fixed = ""
     for i in pieces.split(' '):
         inm = tr.translate(i)
         inm = inm.replace('\n', '')
         inm = re.sub(r'\s+', ' ', inm)
         lsecond_fixed += inm + " "
     return lsecond_fixed, pieces
Beispiel #7
0
    def __init__(self):
        self.T = Translator()
        self.sem_using = threading.Semaphore(1)  # 1명만 쓸것
        self.sem_emp = threading.Semaphore(0)  # 처음 큐는 비어있음
        self.sem_ob = threading.Semaphore(1)
        self.Q = []

        self.observerDic = {}
        self.thList = []
        self.setUpObserverDic()
        self.setUpThread()
        self.PushTh = threading.Thread(target=self.run)
Beispiel #8
0
 def convert_proops(self, pieces):
     tr = t.Translator(b.tr_mapfile)
     simul = []
     for proop in pieces:
         if proop == None:
             continue
         lfirst = proop[0]
         lsecond = proop[1]
         lfirst = lfirst.replace('\n', '')
         lfirst = re.sub(r'\s+', ' ', lfirst)
         lsecond = lsecond.replace('\n', '')
         lsecond = re.sub(r'\s+', ' ', lsecond)
         simul.append((tr.translate(lfirst), lsecond))
     return simul
Beispiel #9
0
 def turn_data(self, lang, pieces):
     if lang == "RU":
         tr = t.Translator(b.tr_mapfile)
         simul = []
         for proop in pieces:
             lfirst = proop[0]
             lsecond = proop[1]
             lfirst = lfirst.replace('\n', '')
             lfirst = re.sub(r'\s+', ' ', lfirst)
             lsecond = lsecond.replace('\n', '')
             lsecond = re.sub(r'\s+', ' ', lsecond)
             lsecond_fixed = ""
             for i in lsecond.split(' '):
                 lsecond_fixed += tr.translate(i) + " "
             simul.append((lfirst, lsecond_fixed))
     return simul
def main():
    manager = MainManager()
    manager.init_directories()

    print_intro()
    input_path = source_choose_menu(manager)
    dependencies_paths = manager.list_dependencies()
    if len(dependencies_paths) == 0:
        print("\n\n Failed! Empty Dependencies folder")
        return 1
    output_handler = OutputHandler()

    translator = Translator(input_path, dependencies_paths, output_handler)
    translator.prepareTranslation()
    translator.parseResources()
    translator.startTranslation()

    output_handler.write_to_disk()
Beispiel #11
0
    def hamming(text1, text2, translator=None):
        if not translator:
            translator = Translator()

        transText1 = translator.translated(text1)
        transText2 = translator.translated(text2)

        value = 0
        size = min(len(text1), len(text2))
        for i in range(size):
            if text1[i] == text2[i]:
                continue
            if transText1[i] == transText2[i]:
                value += 1
                continue
            value += 2
        # Note that we need to multiply by 2 because 'errors' weight 2
        # and 'semi-errors' weight 1
        value += abs(len(text1) - len(text2)) * 2
        return value
Beispiel #12
0
 def mapper(self, _, line_path):
     read_file = open(
         b.main_dir + '/' + b.RTUD_DIR + b.THERE + b.BOOKDEPOSITORY_DIR +
         b.THERE + b.BOOKDEPOSITORY_DIR + ".json", "r")
     data = json.load(read_file)
     read_file.close()
     pieces = [i for i in data['Books'][int(line_path)]]
     name = data['Books'][int(line_path)]["Name"]
     ft = None
     fin = False
     part = None
     opps = []
     if pieces:
         name, neng = self.easy_turn_data("RU", name)
         fi = open(b.main_dir + b.THERE + b.RTUD_DIR + b.THERE +
                   b.AZON_AIM_FILE)
         for file_name in fi:
             file_name = file_name.replace('\n', '')
             read_file = open(b.main_dir + '/' + file_name, "r")
             cmps = json.load(read_file)
             d = int(cmps["Books"][-1]["Count"])
             for j in range(0, d):
                 part = cmps["Books"][j]["Part"]
                 cmp_name = cmps["Books"][j]["Name"]
                 cmp_name = cmp_name.split('–')[0].split(':')[0]
                 read_file.close()
                 tr = t.Translator(b.tr_mapfile)
                 if tr.diff_cmp(name, cmp_name, 200):
                     ft = file_name
                     fin = True
                     ft = file_name
                     fin = True
                     opps.append((name, neng, part))
         fi.close()
         if fin:
             yield opps, (line_path, ft)
         else:
             yield (name, neng, part), None
     else:
         yield (name, name), None
Beispiel #13
0
def main(path):
    """
    This fucntion classify the two options: .asm file path or directory path.
    """
    files = []
    if os.path.isfile(path):
        abs_path = os.path.abspath(path)
        files.append(abs_path)
        output_path = re.sub(r'(\.vm)$', '', abs_path) + ".asm"
    else:
        dir_path = os.path.abspath(path)
        for f in os.listdir(path):
            f_path = ''.join([path, "/", f])
            if os.path.isfile(f_path):
                if str(f).split('.')[-1] == "vm":
                    files.append(f_path)

        file_name = dir_path.split('/')[-1]
        output_path = ''.join([dir_path, "/", file_name, ".asm"])

    lines = Translator.Translator(files, output_path)
    lines.translate()
Beispiel #14
0
import asyncio
import random
import json

import discord
import datetime
import requests
from discord.ext import commands

from red-bot.core.bot import Red
from red-bot.core import checks, Config
from red-bot.core.i18n import Translator
from red-bot.core.commands import Context
from red-bot.core.utils.menus import menu, DEFAULT_CONTROLS

_ = Translator("Fortnite", __file__)

class Fortnite:
    """Fortnite commands."""


    def __init__(self, bot: Red):
        self.bot = bot
        self.config = Config.get_conf(self, 451736518321, force_registration=True)
        default_global_settings = {
            "fortnite_api_key": None
        }
        self.config.register_global(**default_global_settings)


    async def get_raw_player_data(self, url):
Beispiel #15
0
 def translateForecast(self, forecast, language):
     "Translate the forecast"
     if language == "english":
         return forecast
     trans = Translator.Translator(language)
     return trans.getForecast(forecast)
Beispiel #16
0
 def translateExpr(self, phrase, language):
     "Translate the time or heading"
     if language == "english" or phrase == "":
         return phrase
     trans = Translator.Translator(language)
     return trans.getExpression(phrase)
Beispiel #17
0
 def __init__(self, script):
     script = script.encode("utf-8", "ignore")
     script = script.decode("utf-8")
     trans = Translator(script)
     self.script = trans.translate(script)
Beispiel #18
0
 def __init__(self, script):
     trans = Translator(script)
     self.script = trans.translate(script)
Beispiel #19
0
    def findTemplateOffset(self, template):
        if not template.boxes:
            return QPoint(0, 0)

        lines = self.ocr.textLinesWithSpaces()
        print "FORMATED: ", self.ocr.formatedText().encode('ascii', 'replace')

        # Create a default translator only once
        translator = Translator()

        # This list will keep a pointer to each template box of type 'matcher'
        matchers = []
        for templateBox in template.boxes:
            if templateBox.type != 'matcher':
                continue

            templateBoxText = templateBox.text.strip()
            templateBox.ranges = Range.extractAllRangesFromDocument(
                lines, len(templateBoxText),
                templateBox.featureRect.width() + 2)
            for ran in templateBox.ranges:
                text = ran.text()
                #value = Hamming.hamming( text, templateBoxText, translator )
                #value = 1.0 - Trigram.trigram( text, templateBoxText )
                value = Levenshtein.levenshtein(text, templateBoxText)
                ran.distance = value
                #print "Comparison: '%s', '%s', '%f'" % (text.encode('ascii','ignore'), templateBoxText, value)

            #five = u'|'.join( [ x.text().encode('ascii','ignore') for x in templateBox.ranges[0:200] ])
            #print 'First five ranges: ', five

            templateBox.ranges.sort(rangeDistanceComparison)

            for x in templateBox.ranges[0:20]:
                print "Comparison: '%s', '%s', '%f'" % (x.text().encode(
                    'ascii', 'replace'), templateBoxText, x.distance)

            #five = u'|'.join( [ x.text().encode('ascii','ignore') for x in templateBox.ranges[0:10] ])
            #print 'First five ranges: ', five

            if templateBox.ranges:
                bestRange = templateBox.ranges[0]
                print "The best match for template box '%s' is '%s' with distance %d" % (
                    templateBoxText, bestRange.text().encode(
                        'ascii', 'replace'), bestRange.distance)
            matchers.append(templateBox)

        # Once we have all ranges sorted for each template box we search which
        # range combination matches the template.
        iterator = TemplateBoxRangeIterator(matchers)
        i = 0
        for ranges in iterator:
            documentBoxCenter = ranges[0].rect().center()
            templateBoxCenter = matchers[0].featureRect.center()
            diff = documentBoxCenter - templateBoxCenter
            #print "Difference: ", diff
            #print "Document: ", documentBoxCenter
            #print "Template: ", templateBoxCenter
            found = True
            for pos in range(1, len(ranges)):
                documentBoxCenter = ranges[pos].rect().center()
                templateBoxCenter = matchers[pos].featureRect.center()
                d = documentBoxCenter - templateBoxCenter
                # If difference of relative positions of boxes between
                # template and document are bigger than 5mm we discard
                # the ranges
                #print "Difference in loop: ", d
                #print "Document: %s, %s" % ( documentBoxCenter, ranges[pos].rect() )
                #print "Template: ", templateBoxCenter
                #print "Comparison: %s  --- %s" % (abs(d.x()) + 5.0, abs(diff.x() ) )
                if abs(d.x() - diff.x()) > 5:
                    found = False
                    break
                if abs(d.y() - diff.y()) > 5:
                    found = False
                    break
            if found:
                break
            i += 1
            if i > 1000:
                break
        if found:
            return diff
        else:
            return None
Beispiel #20
0
import sys
sys.path.insert(0, './src')
import Translator

#   trainSize < 100000
#   testSize < 10001
#   devSize < 10001
t = Translator.Translator(mode='train',
                          prepocessed=False,
                          srcVocaThreshold=0,
                          tgtVocaThreshold=0,
                          deprelLabelThreshold=0,
                          printEvery=50,
                          trainSize=99999,
                          testSize=10000,
                          devSize=10000)

t.demo(inputDim=128,
       inputActDim=32,
       hiddenDim=128,
       hiddenEncDim=128,
       hiddenActDim=16,
       scale=0,
       miniBatchSize=256,
       learningRate=0.01,
       loadModel=False,
       modelDir='./data/saved_model/',
       modelName='30000-10000-10-10-5.pt',
       startIter=1,
       epochs=30,
       useGCN=True,
Beispiel #21
0
#-*-coding:utf-8-*-
from Translator import *

csv = Translator("csv")
tsv = Translator("tsv")

print(csv.translate("archivo.csv"))

print(tsv.translate("archivo.tsv"))
Beispiel #22
0
    def processContent(self):
        if self.filetype == "ON":
            # Kick the useless first entry
            for a in range(1,len(self.rawcontent)):
                # Kick useless empty lines
                if self.rawcontent[a] != "" and "#begin" not in self.rawcontent[a] and "#end" not in self.rawcontent[a]:
                    splitLine = self.rawcontent[a].split()
                    # Pick out the juicy bits
                    dummy_lemma = Lemma.Lemma(int(splitLine[1]), int(splitLine[2]), str(splitLine[3]).lower(), str(splitLine[4]), str(splitLine[6]).lower(), str(splitLine[8]))
                    self.procontent.append(dummy_lemma)
        if self.filetype == "IN":
            # Kick the useless first 29 entries
            for a in range(29,len(self.rawcontent)):
                # Kick useless empty lines
                if self.rawcontent[a] != "":
                    splitLine = self.rawcontent[a].split()
                    # Pick out the juicy bits
                    dummy_list_of_senses = []
                    # Check for multiple senses
                    for b in range(6,len(splitLine)):
                        if len(splitLine[b]) > 3:
                            dummy_list_of_senses.append(splitLine[b])
                    # Putting juicy bits together
                    dummy_translation = Translation.Translation(str(splitLine[0]), str(splitLine[1]), dummy_list_of_senses)
                    self.procontent.append(dummy_translation)
        if self.filetype == "FW":
            # Kick the useless first 25 entries
            for a in range(25,len(self.rawcontent)):
                # Kick useless empty lines
                if self.rawcontent[a] != "" and "//" not in self.rawcontent[a]:
                    # Check for multiple examples
                    splitLine = self.rawcontent[a].split(", ")
                    dummy_functionWords = []
                    # Take all examples
                    for b in range(len(splitLine)):
                        # Kick constructions of multiple words
                        if " " not in splitLine[b]:
                            self.procontent.append(splitLine[b])
        if self.filetype == "TL":
            dummy_senselists = []
            dummy_switch = False
            # Get the info from filename back
            dir = os.path.realpath(__file__)
            dummy_string = self.filename.replace("\\".join(dir.split("\\")[:-1])+"\\Translation\\","").replace(".xml","")
            dummy_word_and_type = dummy_string.split("-")

            for a in range(0,len(self.rawcontent)):
                # Look out for juicy bits
                #
                # The following part is NSFW
                #
                # This is a dummy in case the file just wanted to put info in a new line
                
                if dummy_switch == True:
                    
                    dummy_string = self.rawcontent[a]
                    # This is in case the file wanted to add an additional empty line
                    if dummy_string != "":
                        # Yes, there are files with additional info instead
                        if "<wn lemma" not in dummy_string and dummy_string != "-" and "<omega" not in dummy_string:
                            splitLine = dummy_string.split(" ")
                            dummy_list = []
                            for b in range(len(splitLine)):
                                try:
                                    dummy_list.append(int(splitLine[b]))
                                # It is 3am , now I stop to care and start to botch
                                except ValueError:
                                    dummy_splitLine = splitLine[0].split(",")
                                    dummy_list.append(int(dummy_splitLine[b]))
                            dummy_senselists.append(dummy_list)
                            #print dummy_senselists
                        elif dummy_string != "-":
                            dummy_senselists.append([0])
                            #print dummy_senselists
                        # This is not the normal format either    
                        else:
                            # Kick useless stuff
                            dummy_splitLine1 = dummy_string.split("version=\"3.0\">")
                            dummy_splitLine2 = dummy_splitLine1[-1].split("</wn>")
                            splitLine = dummy_splitLine2[0].split(",")
                            if splitLine[0] != "" and splitLine[0] != "-":
                                dummy_list = []
                                for b in range(len(splitLine)):
                                        dummy_list.append(int(splitLine[b]))
                                dummy_senselists.append(dummy_list)
                                #print dummy_senselists
                        ###    elif splitLine[0] == "-":
                        ###        dummy_senselists.append([0])
                            else: 
                                dummy_senselists.append([0])
                                #print dummy_senselists
                        dummy_switch = False
                # That is the normal format I would say. Not sure though.
                if "<wn version=\"3.0\">" in self.rawcontent[a]:
                    # Kick the useless stuff around juicy bit
                    dummy_string = self.rawcontent[a].replace("<wn version=\"3.0\">","").replace("</wn>","").replace("<omega/>","")
                    splitLine = dummy_string.split(",")
                    if splitLine[0] != "" and splitLine[0] != "NM":
                        dummy_list = []
                        for b in range(len(splitLine)):
                            if "." in splitLine[b]:
                                dummy_list.append(int(splitLine[b].split(".")[0]))
                            else:
                                dummy_list.append(int(splitLine[b]))
                        dummy_senselists.append(dummy_list)
                        #print dummy_senselists
                    elif splitLine[0] == "NM":
                        dummy_senselists.append([0])
                        #print dummy_senselists
                    else:
                        dummy_switch = True
                if "<wn version=\"1.7\">" in self.rawcontent[a]:
                    # Blub
                    dummy_string = self.rawcontent[a].replace("<wn version=\"1.7\">","").replace("</wn>","").replace("<omega/>","")
                    splitLine = dummy_string.split(",")
                    if splitLine[0] != "" and splitLine[0] != "NM" and splitLine[0] != "?":
                        dummy_list = []
                        for b in range(len(splitLine)):
                            if "." in splitLine[b]:
                                dummy_list.append(int(splitLine[b].split(".")[0]))
                            else:
                                dummy_list.append(int(splitLine[b]))
                        dummy_senselists.append(dummy_list)
                        #print dummy_senselists
                    elif splitLine[0] == "NM" or splitLine[0] == "?" or splitLine[0] == "-":
                        dummy_senselists.append([0])
                        #print dummy_senselists
                    else:
                        dummy_switch = True
                # By now, anything could happen in these lines
                if "<wn version=\"2.0\">" in self.rawcontent[a] and "</wn>" in self.rawcontent[a]:
                    dummy_list = []
                    dummy_string = self.rawcontent[a]
                    dummy_splitLine1 = dummy_string.split("version=\"2.0\">")
                    dummy_splitLine2 = dummy_splitLine1[-1].split("</wn>")
                    dummy_splitLine3 = dummy_splitLine2[0].split(",")
                    splitLine = dummy_splitLine3[0].split(" ")
                    if splitLine[0] != "" and splitLine[0] != "-" and splitLine[0] != "Placeholder":
                        dummy_list = []
                        for b in range(len(splitLine)):
                            try:
                                dummy_list.append(int(splitLine[b]))
                            except ValueError:
                                print self.rawcontent[a]
                                print self.filename
                        dummy_senselists.append(dummy_list)
                        #print dummy_senselists
                    else: 
                        dummy_senselists.append([0])
                        #print dummy_senselists
                if "<wn version=\"2.0\">" in self.rawcontent[a] and "</wn>" not in self.rawcontent[a]:
                    dummy_switch = True
            dummy_translator = Translator.Translator(dummy_word_and_type[0],dummy_word_and_type[1],dummy_senselists)
            self.procontent.append(dummy_translator)
Beispiel #23
0
import pyttsx3
import PyPDF2
import Translator
book = open('oop.pdf', 'rb')
pdfReader = PyPDF2.PdfFileReader(book)
all=''
pages = pdfReader.numPages
speaker = pyttsx3.init()
for num in range(7, pages):
    page = pdfReader.getPage(num)
    text = page.extractText()
    all=text
    speaker.say(text)
    speaker.runAndWait()
 trans=Translator()
 t= trans.translate(all,src='en',dest='hi')
    obj=pyttsx3(text=t.text,slow='False',lang='hi')
    obj.save("audio.mp3")
Beispiel #24
0
import Translator as T
import sys
import os
import ntpath
if __name__ == '__main__':

    path = sys.argv[1]
    print(path)
    t = T.Translator()
    t.Translate(path)
Beispiel #25
0
    for obj in IDList:
        element = Element()
        element.id = obj[ATTRID][ATTRVAL]
        element.name = obj[ATTRNAME][ATTRVAL]
        element.data_from = obj[ATTRFROM][ATTRVAL]
        element.data_to = obj[ATTRTO][ATTRVAL]
        base_resources.append(element)

    del element

    element = Element()
    element.id = "BaseCanvas"
    element.name = ""
    element.data_target = ""
    translator = Translator(element)
    del element

    translator.treeStructurization(base_resources)
    result = translator.translating()

    print(result.html)
    print(result.view)
    print(result.control)
    print(result.model)

    print('saving index.html...')
    fp = open('../mwa/index.html', 'w')
    fp.write(result.html)
    fp.close()