Dear Nata
The python script below (discussed in a recent thread) sets up a moses
process; you send text in on stdin and receive transaltions on stdout.
With a bit of scaffolding, the process can act as a server for a small
number of clients.
Best
Ivan
#! /usr/bin/env python
import subprocess, time
class MosesCMD(object):
def ___init___(self):
self.cmd_path = ''
self.model_path = ''
self.recaser_model_path = ''
self.proc = None
def start(self):
cmd = "%s -f %s" % (self.cmd_path, self.model_path)
if self.recaser_model_path:
cmd = "%s | %s -v 0 -f %s -dl 1" \
% (cmd, self.cmd_path, self.recaser_model_path)
self.proc = subprocess.Popen(cmd, shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=None)
def translate(self, line):
line = '%s\n' % line.strip()
self.proc.stdin.write(line)
return self.proc.stdout.readline().capitalize()
def close(self):
self.proc.kill()
def main():
mc = MosesCMD()
mc.cmd_path = "/path/to/mosesdecoder/moses-cmd/src/moses"
mc.model_path = "/path/to/model/moses.ini"
mc.recaser_model_path = "/path/to/recase/moses.ini"
mc.start()
time.sleep(1)
print 'Ready.'
cy = '*'
while cy:
cy = raw_input('cymraeg> ')
en = mc.translate(cy)
print 'saesneg> %s\n' % en
mc.close()
if ___name___ == "___main___":
main()
On Monday 24 May 2010 18:50:54 Nata Sekhar wrote:
Hello friends,
i am looking for possibites to load the required files needed for decoding
such as phrase table, reordering table, lm in RAM
so that i can invoke decoder as when translations are needed for new
strings.(already have mapped the phrase, reordering tables mapped to disk
fies)
Simple to say, i need moses engine running all the time and get the strings
translated as and when needed.
Friends, please share your ideas on this.
Thanks in advance.
--
********************************
Ivan Uemlianin
Canolfan Bedwyr
Safle'r Normal Site
Prifysgol Bangor University
BANGOR
Gwynedd
LL57 2PZ
[email protected]
http://www.bangor.ac.uk/~cbs007/
********************************
_______________________________________________
Moses-support mailing list
[email protected]
http://mailman.mit.edu/mailman/listinfo/moses-support