Hi Nakul,

 In May 2010, Ivan shared the code below for running Moses with Python. 
 We used it as the foundation for our moses.py plugin for Do Moses 
 Yourself (DoMY).

 I think Ken's stackoverflow.com and this sample should put you on 
 track.

 Tom


 -------- Original Message --------

 Subject: Re: [Moses-support] Keep files required for decoding in cache

 Date: Tue, 25 May 2010 13:16:34 +0100

 From: Ivan Uemlianin <[email protected]>

 To: [email protected]



 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()



        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.'





 On Fri, 03 Jun 2011 13:37:47 -0400, Kenneth Heafield 
 <[email protected]> wrote:
> Moses outputs translations to stdout and advisory messages to stderr.
> This is the correct behavior.
>
> I think you're referring to Java's rudimentary process IO handling.
> 
> http://stackoverflow.com/questions/60302/starting-a-process-with-inherited-stdin-stdout-stderr-in-java-6
>
> On 06/03/11 05:50, nakul sharma wrote:
>> Hi All,
>>
>> i am developing an application using Java Swing  which invokes Moses
>> decoder to undertake translation. the moses decoder runs in 
>> ErrorStream
>> instead of standard output. i have passed all the paramters to Moses
>> decoder correctly, but i still face this problem. Can anyone suggest 
>> how
>> to recover from this problem ? i am using Process class in java.
>>
>> Please tell how to resolve this problem.
>>
>>
>> --
>> Thanks & Regards,
>> nakul
>>
>>
>>
>> _______________________________________________
>> Moses-support mailing list
>> [email protected]
>> http://mailman.mit.edu/mailman/listinfo/moses-support
> _______________________________________________
> Moses-support mailing list
> [email protected]
> http://mailman.mit.edu/mailman/listinfo/moses-support

_______________________________________________
Moses-support mailing list
[email protected]
http://mailman.mit.edu/mailman/listinfo/moses-support

Reply via email to