Exemplo n.º 1
0
    def get(self):

        toTranslate = self.get_argument('q')

        try:
            l1, l2 = map(toAlpha3Code, self.get_argument('langpair').split('|'))
        except ValueError:
            self.send_error(400, explanation='That pair is invalid, use e.g. eng|spa')

        mode_path = self.pairs['%s-%s' % (l1, l2)]
        try:
            _, commands = translation.parseModeFile(mode_path)
        except Exception:
            self.send_error(500)
            return

        res = yield translation.translatePipeline(toTranslate, commands)
        if self.get_status() != 200:
            self.send_error(self.get_status())
            return

        output, pipeline = res

        self.sendResponse({
            'responseData': {'output': output, 'pipeline': pipeline},
           'responseDetails': None,
           'responseStatus': 200
        })
Exemplo n.º 2
0
    def runPipeline(self, l1, l2):
        if (l1, l2) not in self.pipelines:
            logging.info('%s-%s not in pipelines of this process, starting …' % (l1, l2))
            mode_path = self.pairs['%s-%s' % (l1, l2)]
            try:
                do_flush, commands = parseModeFile(mode_path)
            except Exception:
                self.send_error(500)
                return

            procs = []
            for cmd in commands:
                if len(procs)>0:
                    newP = Popen(cmd, stdin=procs[-1].stdout, stdout=PIPE)
                else:
                    newP = Popen(cmd, stdin=PIPE, stdout=PIPE)
                procs.append(newP)

            self.pipeline_locks[(l1, l2)] = threading.RLock()
            self.pipelines[(l1, l2)] = (procs[0], procs[-1], do_flush)
Exemplo n.º 3
0
 def getPipeCmds(self, l1, l2):
     if (l1, l2) not in self.pipeline_cmds:
         mode_path = self.pairs['%s-%s' % (l1, l2)]
         self.pipeline_cmds[(l1, l2)] = translation.parseModeFile(mode_path)
     return self.pipeline_cmds[(l1, l2)]