Exemplo n.º 1
0
                # parse the n-best list output of Marian
                n_best_outputs = [
                    segment.split(u' ||| ')[1]
                    for segment in trans.split(u'\n')
                ]
                wsock.send(json.dumps({'segments': n_best_outputs}))

        except WebSocketError:
            break


def parse_args():
    """ parse command arguments """
    parser = argparse.ArgumentParser()
    parser.add_argument("-c", dest="config")
    parser.add_argument('-p', dest="port", default=8080, type=int)
    return parser.parse_args()


if __name__ == "__main__":
    args = parse_args()
    nmt.init("-c {}".format(args.config))

    from gevent.pywsgi import WSGIServer
    from geventwebsocket import WebSocketError
    from geventwebsocket.handler import WebSocketHandler
    server = WSGIServer(("0.0.0.0", args.port),
                        app,
                        handler_class=WebSocketHandler)
    server.serve_forever()
Exemplo n.º 2
0
def test_init():
    nmt.init('-c config.yml')
Exemplo n.º 3
0
#!/usr/bin/env python

import libamunmt as nmt
import sys

nmt.init(sys.argv[1])

sentences = []
for line in sys.stdin:
    sentences.append(line.rstrip())

output = nmt.translate(sentences)

for line in output:
    sys.stdout.write(line)
Exemplo n.º 4
0
#!/usr/bin/env python
# script by Ulrich Germann
# This script is meant to test the python interface of amun by emulating the amun executable.
import sys, os

if 'AMUN_PYLIB_DIR' in os.environ:
    sys.path.append(os.environ['AMUN_PYLIB_DIR'])
    pass

import libamunmt
if __name__ == "__main__":
    libamunmt.init(" ".join(sys.argv[1:]))
    print libamunmt.translate(sys.stdin.readlines())
    libamunmt.shutdown()