Hi Simon, Our approach in Python might help you in Java. We load the moses binary and monitor the stderr output to determine if it loaded properly (Created input-output object) or failed. Assuming it loaded, we then initiate a thread to collect & dump output to stderr. We collect it to avoid locking from a full buffer. We dump it because we compile moses for multithreading and the output order of stderr is not correlated to the output order of stdout. In the main thread, we feed all source data lines (sentences) into stdin. Then, we loop to collect stdout. We break the loop when we've collected the same number of lines that we fed in.
If you don't compile for multithreading, or if you set -threads 1, the outputs from stderr and stdout are in lockstep and you can feed/collect line by line. Tom On Thu, 12 Jan 2012 14:20:12 +0000, Barry Haddow <[email protected]> wrote: > Hi Simon > > You could use the mose server. I've used this with a Java client > > http://www.statmt.org/moses/?n=Moses.AdvancedFeatures#ntoc20 > > cheers - Barry > > On Thursday 12 January 2012 13:42:36 Simon h s wrote: >> Thank you for your reply, >> >> This explains why the code worked with grep command but not with >> moses. But is there any workaround that still uses moses command >> line? To be honest, I have very minimal experience with c and no >> experience at all using JNI. So if there are other alternatives >> I >> would be very grateful. :) >> >> Thank you very much >> >> >> -- >> Simon H S >> >> >> >> ________________________________ >> From: Hieu Hoang <[email protected]> >> To: [email protected] >> Sent: Thursday, 12 January 2012, 10:44 >> Subject: Re: [Moses-support] can't find moses translation result >> from java >> app >> >> >> are you calling the moses command line program? the output >> Created input-output object : >> means it's waiting for an input sentence, you won't get any >> translation from the decoder until then. >> >> another approach is to use the moses library directly, rather than >> the command line version. You have to write c-based wrapper for >> the >> c++-based library, then call them via JNI. >> >> this was done in the iphone app >> >> >> https://github.com/moses-smt/mosesdecoder/blob/hieu_iphone/Classes/CFuncti >> ons.cpp >> >> On 11/01/2012 04:53, Simon wrote: >> Dear all, >> >> >I'm trying to call moses from inside java application, but after >> >> running the Runtime.exec, I can't retrieve the translation >> result >> using getInputStream method or the getErrorStream. >> >> >I'm pretty certain that the moses has produced some translation, >> >> because in the error stream I can read something like: >> >... >> >ERR>Finished loading phrase tables : [0.000] seconds >> >ERR>IO from STDOUT/STDIN >> >ERR>Created input-output object : [0.000] seconds >> >... >> > >> >but as I said before, I can't find the translation result when >> >> running the moses from inside the Java application. Running it >> directly from shell works fine. >> >> >Can anyone help? the code I'm using and the full result of error >> >> stream is in this pastebin: >> >http://pastebin.com/Z7Y3NsTU >> > >> >Thanks in advance, >> > >> >-- >> >Simon H S >> > >> > >> > >> >_______________________________________________ >> >> 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 >> > > -- > Barry Haddow > University of Edinburgh > +44 (0) 131 651 3173 _______________________________________________ Moses-support mailing list [email protected] http://mailman.mit.edu/mailman/listinfo/moses-support
