class Session: def __init__(self, host, context=None, document=None, args=None, handler=None): self.mmt = MMTApi(host) self.context = context self.args = args self.document = document self.handler = handler if context: C = self.mmt.get_context_s(context) S = self.mmt.create_session(C) self.session = S['id'] else: self.session = None return def __del__(self): if self.session != None: self.mmt.close_session(self.session) return def translate(self, line): return self.mmt.translate(line, session=self.session, nbest=None)
def __init__(self, host, context=None, document=None, args=None, handler=None): self.mmt = MMTApi(host) self.context = context self.args = args self.document = document self.handler = handler if context: C = self.mmt.get_context_s(context) S = self.mmt.create_session(C) self.session = S['id'] else: self.session = None return
class Session: def __init__(self, host, context=None, document=None, args=None, handler=None): self.mmt = MMTApi(host) self.context = context self.args = args self.document = document self.handler = handler if context: C = self.mmt.get_context_s(context) S = self.mmt.create_session(C) self.session = S['id'] else: self.session = None return def __del__(self): if self.session != None: self.mmt.close_session(self.session) return def translate(self,line): return self.mmt.translate(line,session=self.session, nbest=None)
parser.add_argument('-input-file', dest='input_file') realargv = [] for arg in sys.argv: if arg.startswith('--'): realargv += arg.split() else: realargv.append(arg) args, _ = parser.parse_known_args(realargv) if len(sys.argv) == 1 or args.port is None: parser.print_help() exit(1) Api = MMTApi(port=args.port, root=args.root) if args.show_weights: # Show weights show_weighs() else: translator = _DocumentTranslator(args.input_file, int(args.nbest_list[1]), args.nbest_list[0]) translator.set_weights(args.weights) if args.context_analysis is not None: translator.set_skipcontext(True) translator.run()
parser.add_argument('-input-file', dest='input_file') realargv = [] for arg in sys.argv: if arg.startswith('--'): realargv += arg.split() else: realargv.append(arg) args, _ = parser.parse_known_args(realargv) if len(sys.argv) == 1 or args.port is None: parser.print_help() exit(1) Api = MMTApi(port=args.port) if args.show_weights: # Show weights show_weighs() else: translator = _DocumentTranslator(args.input_file, int(args.nbest_list[1]), args.nbest_list[0]) translator.set_weights(args.weights) if args.context_analysis is not None: translator.set_skipcontext(True) translator.run()
import time MMT_HOME = os.path.abspath( os.path.join(__file__, os.pardir, os.pardir, os.pardir, os.pardir, os.pardir)) sys.path.insert(0, MMT_HOME) os.environ['LD_LIBRARY_PATH'] = os.path.join(MMT_HOME, 'build', 'lib') os.environ['LC_ALL'] = 'en_US.UTF-8' os.environ['LANG'] = 'en_US.UTF-8' from cli.cluster import MMTApi from cli.libs.shell import ShellError _api = MMTApi(port=8045) def _log(message, nl=True): sys.stderr.write(message) if nl: sys.stderr.write('\n') sys.stderr.flush() def _exe(cmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE): process = subprocess.Popen(cmd, stdin=stdin, stdout=stdout, stderr=stderr, shell=True,