예제 #1
0
def main(argv=None):
    args = parse_args(argv)

    engine = Engine(args.engine)
    node = EngineNode(engine)
    ensure_node_running(node)
    ensure_node_has_api(node)

    mmt = ModernMTTranslate(node,
                            args.source_lang,
                            args.target_lang,
                            context_string=args.context,
                            context_file=args.context_file,
                            context_vector=args.context_vector,
                            split_lines=args.split_lines)

    if args.text is not None:
        print(mmt.translate_text(args.text.strip()))
    else:
        if args.is_xliff:
            translator = XLIFFTranslator(mmt)
        elif args.batch:
            translator = BatchTranslator(mmt)
        else:
            translator = InteractiveTranslator(mmt)

        try:
            translator.run(sys.stdin, sys.stdout, threads=args.threads)
        except KeyboardInterrupt:
            pass  # exit
예제 #2
0
def _load_node(engine_name):
    engine = Engine(engine_name)
    ensure_engine_exists(engine)

    node = EngineNode(engine)
    ensure_node_running(node)
    ensure_node_has_api(node)

    return node
예제 #3
0
def main(argv=None):
    args = parse_args(argv)

    engine = Engine(args.engine)
    ensure_engine_exists(engine)

    node = EngineNode(engine)
    ensure_node_running(node)
    ensure_node_has_api(node)

    wdir = engine.get_tempdir('evaluate')
    shutil.rmtree(wdir, ignore_errors=True)
    os.makedirs(wdir)

    activity = EvaluateActivity(node, args, wdir=wdir, delete_on_exit=not args.debug)
    activity.run()
예제 #4
0
파일: translate.py 프로젝트: motin/modernmt
def main(argv=None):
    args = parse_args(argv)

    if args.echo:
        engine = EchoTranslate(args.source_lang, args.target_lang)
    elif args.api_key is not None:
        engine = ModernMTEnterpriseTranslate(
            args.source_lang,
            args.target_lang,
            args.api_key,
            context_vector=args.context_vector)
    else:  # local ModernMT engine
        node = EngineNode(Engine(args.engine))
        ensure_node_running(node)
        ensure_node_has_api(node)

        engine = ModernMTTranslate(node,
                                   args.source_lang,
                                   args.target_lang,
                                   context_string=args.context,
                                   context_file=args.context_file,
                                   context_vector=args.context_vector,
                                   split_lines=args.split_lines)

    if args.text is not None:
        print(engine.translate_text(args.text.strip()))
    else:
        if args.is_xliff:
            translator = XLIFFTranslator(engine)
        elif args.batch:
            translator = BatchTranslator(engine)
        else:
            translator = InteractiveTranslator(engine)

        try:
            translator.run(sys.stdin,
                           sys.stdout,
                           threads=args.threads,
                           suppress_errors=args.quiet)
        except KeyboardInterrupt:
            pass  # exit