From 7c088c9a95ee6fdbd211f2b2ae9606ecf1ccba3c Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Tue, 17 Nov 2015 14:19:36 +0100 Subject: [PATCH 01/13] first commit of placeholder changes to moses server --- moses/server/TranslationRequest.cpp | 37 +++++++++++++++++++++++++---- moses/server/TranslationRequest.h | 2 +- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/moses/server/TranslationRequest.cpp b/moses/server/TranslationRequest.cpp index 8f15b30ff..f23b378f6 100644 --- a/moses/server/TranslationRequest.cpp +++ b/moses/server/TranslationRequest.cpp @@ -11,6 +11,8 @@ using Moses::StaticData; using Moses::Range; using Moses::ChartHypothesis; using Moses::Phrase; +using Moses::Factor; +using Moses::FactorType; using Moses::Manager; using Moses::SearchGraphNode; using Moses::TrellisPathList; @@ -164,16 +166,43 @@ insertGraphInfo(Manager& manager, map& retData) retData["sg"] = xmlrpc_c::value_array(searchGraphXml); } +// void +// TranslationRequest:: +// output_phrase(ostream& out, Phrase const& phrase) const +// { +// if (!m_options.output.ReportAllFactors) { +// for (size_t i = 0 ; i < phrase.GetSize(); ++i) +// out << *phrase.GetFactor(i, 0) << " "; +// } else out << phrase; +// } + void TranslationRequest:: -output_phrase(ostream& out, Phrase const& phrase) const +output_phrase(ostream& out, const Hypothesis* hypo) const { + Phrase phrase = hypo->GetCurrTargetPhrase(); + if (!m_options.output.ReportAllFactors) { - for (size_t i = 0 ; i < phrase.GetSize(); ++i) - out << *phrase.GetFactor(i, 0) << " "; + FactorType placeholderFactor = StaticData::Instance().GetPlaceholderFactor(); + std::map placeholders; + if (placeholderFactor != NOT_FOUND) { + // creates map of target position -> factor for placeholders + placeholders = GetPlaceholders(*hypo, placeholderFactor); + } + for (size_t i = 0 ; i < phrase.GetSize(); ++i) { + const Factor *factor = phrase.GetFactor(i, 0); + if (placeholders.size()) { + // do placeholders + std::map::const_iterator iter = placeholders.find(i); + if (iter != placeholders.end()) { + factor = iter->second; + } + } + out << *factor << " "; + } } else out << phrase; } - + void TranslationRequest:: outputNBest(const Manager& manager, map& retData) diff --git a/moses/server/TranslationRequest.h b/moses/server/TranslationRequest.h index b93043b9b..24adb7888 100644 --- a/moses/server/TranslationRequest.h +++ b/moses/server/TranslationRequest.h @@ -68,7 +68,7 @@ TranslationRequest : public virtual Moses::TranslationTask void - output_phrase(std::ostream& out, Moses::Phrase const& phrase) const; + output_phrase(std::ostream& out, const Moses::Hypothesis* hypo) const; void add_phrase_aln_info(Moses::Hypothesis const& h, From 66928f682f55cb6e6b105dd71a358354963e91d3 Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Tue, 17 Nov 2015 15:06:48 +0100 Subject: [PATCH 02/13] second commit of moses server placeholder fix --- moses/server/TranslationRequest.cpp | 47 +++++++---------------------- moses/server/TranslationRequest.h | 8 ++--- 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/moses/server/TranslationRequest.cpp b/moses/server/TranslationRequest.cpp index f23b378f6..433e37a27 100644 --- a/moses/server/TranslationRequest.cpp +++ b/moses/server/TranslationRequest.cpp @@ -3,6 +3,8 @@ #include "moses/ContextScope.h" #include #include "moses/Util.h" +#include "moses/Hypothesis.h" + namespace MosesServer { using namespace std; @@ -11,8 +13,6 @@ using Moses::StaticData; using Moses::Range; using Moses::ChartHypothesis; using Moses::Phrase; -using Moses::Factor; -using Moses::FactorType; using Moses::Manager; using Moses::SearchGraphNode; using Moses::TrellisPathList; @@ -175,33 +175,6 @@ insertGraphInfo(Manager& manager, map& retData) // out << *phrase.GetFactor(i, 0) << " "; // } else out << phrase; // } - -void -TranslationRequest:: -output_phrase(ostream& out, const Hypothesis* hypo) const -{ - Phrase phrase = hypo->GetCurrTargetPhrase(); - - if (!m_options.output.ReportAllFactors) { - FactorType placeholderFactor = StaticData::Instance().GetPlaceholderFactor(); - std::map placeholders; - if (placeholderFactor != NOT_FOUND) { - // creates map of target position -> factor for placeholders - placeholders = GetPlaceholders(*hypo, placeholderFactor); - } - for (size_t i = 0 ; i < phrase.GetSize(); ++i) { - const Factor *factor = phrase.GetFactor(i, 0); - if (placeholders.size()) { - // do placeholders - std::map::const_iterator iter = placeholders.find(i); - if (iter != placeholders.end()) { - factor = iter->second; - } - } - out << *factor << " "; - } - } else out << phrase; -} void TranslationRequest:: @@ -222,7 +195,7 @@ outputNBest(const Manager& manager, map& retData) vector const& E = path->GetEdges(); if (!E.size()) continue; std::map nBestXmlItem; - pack_hypothesis(E, "hyp", nBestXmlItem); + pack_hypothesis(manager, E, "hyp", nBestXmlItem); if (m_withScoreBreakdown) { // should the score breakdown be reported in a more structured manner? ostringstream buf; @@ -396,13 +369,15 @@ run_chart_decoder() void TranslationRequest:: -pack_hypothesis(vector const& edges, string const& key, +pack_hypothesis(Moses::Manager& manager, vector const& edges, string const& key, map & dest) const { // target string ostringstream target; - BOOST_REVERSE_FOREACH(Hypothesis const* e, edges) - output_phrase(target, e->GetCurrTargetPhrase()); + BOOST_REVERSE_FOREACH(Hypothesis const* e, edges) + manager.OutputSurface(target, *e, StaticData::Instance().GetOutputFactorOrder(), + options().output.ReportSegmentation, m_options.output.ReportAllFactors); +// output_phrase(target, e->GetTargetPhrase()); XVERBOSE(1,"SERVER TRANSLATION: " << target.str() << std::endl); dest[key] = xmlrpc_c::value_string(target.str()); @@ -427,7 +402,7 @@ pack_hypothesis(vector const& edges, string const& key, void TranslationRequest:: -pack_hypothesis(Hypothesis const* h, string const& key, +pack_hypothesis(Moses::Manager& manager, Hypothesis const* h, string const& key, map& dest) const { using namespace std; @@ -450,8 +425,8 @@ run_phrase_decoder() manager.Decode(); - - pack_hypothesis(manager.GetBestHypothesis(), "text", m_retData); + + pack_hypothesis(manager, manager.GetBestHypothesis(), "text", m_retData); if (m_session_id) m_retData["session-id"] = xmlrpc_c::value_int(m_session_id); diff --git a/moses/server/TranslationRequest.h b/moses/server/TranslationRequest.h index 24adb7888..f3984d35a 100644 --- a/moses/server/TranslationRequest.h +++ b/moses/server/TranslationRequest.h @@ -58,17 +58,17 @@ TranslationRequest : public virtual Moses::TranslationTask run_phrase_decoder(); void - pack_hypothesis(std::vector const& edges, + pack_hypothesis(Moses::Manager& manager, std::vector const& edges, std::string const& key, std::map & dest) const; void - pack_hypothesis(Moses::Hypothesis const* h, std::string const& key, + pack_hypothesis(Moses::Manager& manager, Moses::Hypothesis const* h, std::string const& key, std::map & dest) const; - void - output_phrase(std::ostream& out, const Moses::Hypothesis* hypo) const; +// void +// output_phrase(std::ostream& out, Moses::Phrase const& phrase) const; void add_phrase_aln_info(Moses::Hypothesis const& h, From 5e1340cf63b1e263ff7336075bf791642fd616db Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Tue, 17 Nov 2015 15:16:39 +0100 Subject: [PATCH 03/13] fixed moses server placehoders ; correctly implemented the boolean parameter check function for mosesserver request parameters --- moses/server/TranslationRequest.cpp | 13 ++++++++----- moses/server/TranslationRequest.h | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/moses/server/TranslationRequest.cpp b/moses/server/TranslationRequest.cpp index 433e37a27..fca1c85a5 100644 --- a/moses/server/TranslationRequest.cpp +++ b/moses/server/TranslationRequest.cpp @@ -264,8 +264,11 @@ bool check(std::map const& param, std::string const key) { - std::map::const_iterator m; - return (param.find(key) != param.end()); + std::map::const_iterator m = param.find(key); + if(m == param.end()) return false; + std::string val = string(xmlrpc_c::value_string(m->second)); + if(val == "true" || val == "True" || val == "TRUE" || val == "1") return true; + return false; } void @@ -369,7 +372,7 @@ run_chart_decoder() void TranslationRequest:: -pack_hypothesis(Moses::Manager& manager, vector const& edges, string const& key, +pack_hypothesis(const Moses::Manager& manager, vector const& edges, string const& key, map & dest) const { // target string @@ -402,14 +405,14 @@ pack_hypothesis(Moses::Manager& manager, vector const& edges void TranslationRequest:: -pack_hypothesis(Moses::Manager& manager, Hypothesis const* h, string const& key, +pack_hypothesis(const Moses::Manager& manager, Hypothesis const* h, string const& key, map& dest) const { using namespace std; vector edges; for (; h; h = h->GetPrevHypo()) edges.push_back(h); - pack_hypothesis(edges, key, dest); + pack_hypothesis(manager, edges, key, dest); } diff --git a/moses/server/TranslationRequest.h b/moses/server/TranslationRequest.h index f3984d35a..94d055fd2 100644 --- a/moses/server/TranslationRequest.h +++ b/moses/server/TranslationRequest.h @@ -58,12 +58,12 @@ TranslationRequest : public virtual Moses::TranslationTask run_phrase_decoder(); void - pack_hypothesis(Moses::Manager& manager, std::vector const& edges, + pack_hypothesis(const Moses::Manager& manager, std::vector const& edges, std::string const& key, std::map & dest) const; void - pack_hypothesis(Moses::Manager& manager, Moses::Hypothesis const* h, std::string const& key, + pack_hypothesis(const Moses::Manager& manager, Moses::Hypothesis const* h, std::string const& key, std::map & dest) const; From 4e8396744cec72d7f2926c2d972b86f3b20cbb93 Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Wed, 18 Nov 2015 16:21:50 +0100 Subject: [PATCH 04/13] added first version of regression testing for moses server --- moses/server/TranslationRequest.cpp | 16 ++------ moses/server/TranslationRequest.h | 4 -- regression-testing/Jamfile | 12 +++++- regression-testing/run-single-test.perl | 52 ++++++++++++++++++++++++- run-regtests.sh | 7 +++- 5 files changed, 69 insertions(+), 22 deletions(-) diff --git a/moses/server/TranslationRequest.cpp b/moses/server/TranslationRequest.cpp index fca1c85a5..2317d6434 100644 --- a/moses/server/TranslationRequest.cpp +++ b/moses/server/TranslationRequest.cpp @@ -165,16 +165,6 @@ insertGraphInfo(Manager& manager, map& retData) } retData["sg"] = xmlrpc_c::value_array(searchGraphXml); } - -// void -// TranslationRequest:: -// output_phrase(ostream& out, Phrase const& phrase) const -// { -// if (!m_options.output.ReportAllFactors) { -// for (size_t i = 0 ; i < phrase.GetSize(); ++i) -// out << *phrase.GetFactor(i, 0) << " "; -// } else out << phrase; -// } void TranslationRequest:: @@ -380,7 +370,7 @@ pack_hypothesis(const Moses::Manager& manager, vector const& BOOST_REVERSE_FOREACH(Hypothesis const* e, edges) manager.OutputSurface(target, *e, StaticData::Instance().GetOutputFactorOrder(), options().output.ReportSegmentation, m_options.output.ReportAllFactors); -// output_phrase(target, e->GetTargetPhrase()); + XVERBOSE(1,"SERVER TRANSLATION: " << target.str() << std::endl); dest[key] = xmlrpc_c::value_string(target.str()); @@ -390,7 +380,7 @@ pack_hypothesis(const Moses::Manager& manager, vector const& vector p_aln; BOOST_REVERSE_FOREACH(Hypothesis const* e, edges) - add_phrase_aln_info(*e, p_aln); + add_phrase_aln_info(*e, p_aln); dest["align"] = xmlrpc_c::value_array(p_aln); } @@ -398,7 +388,7 @@ pack_hypothesis(const Moses::Manager& manager, vector const& // word alignment, if requested vector w_aln; BOOST_FOREACH(Hypothesis const* e, edges) - e->OutputLocalWordAlignment(w_aln); + e->OutputLocalWordAlignment(w_aln); dest["word-align"] = xmlrpc_c::value_array(w_aln); } } diff --git a/moses/server/TranslationRequest.h b/moses/server/TranslationRequest.h index 94d055fd2..8d97aed42 100644 --- a/moses/server/TranslationRequest.h +++ b/moses/server/TranslationRequest.h @@ -66,10 +66,6 @@ TranslationRequest : public virtual Moses::TranslationTask pack_hypothesis(const Moses::Manager& manager, Moses::Hypothesis const* h, std::string const& key, std::map & dest) const; - -// void -// output_phrase(std::ostream& out, Moses::Phrase const& phrase) const; - void add_phrase_aln_info(Moses::Hypothesis const& h, std::vector& aInfo) const; diff --git a/regression-testing/Jamfile b/regression-testing/Jamfile index 3f07744c6..f2649908c 100644 --- a/regression-testing/Jamfile +++ b/regression-testing/Jamfile @@ -1,6 +1,7 @@ import option path ; with-regtest = [ option.get "with-regtest" ] ; +with-xmlrpc = [ option.get "with-xmlrpc-c" ] ; if $(with-regtest) { with-regtest = [ path.root $(with-regtest) [ path.pwd ] ] ; @@ -24,7 +25,11 @@ if $(with-regtest) { actions reg_test_decode { $(TOP)/regression-testing/run-single-test.perl --decoder=$(>) --test=$(<:B) --data-dir=$(with-regtest) --test-dir=$(test-dir) && touch $(<) } + actions reg_test_decode_server { + $(TOP)/regression-testing/run-single-test.perl --server --decoder=$(>) --test=$(<:B) --data-dir=$(with-regtest) --test-dir=$(test-dir) && touch $(<) + } reg_test phrase : [ glob $(test-dir)/phrase.* ] : ../moses-cmd//moses : @reg_test_decode ; + reg_test phrase-server : [ glob $(test-dir)/phrase.* ] : ../moses-cmd//moses : @reg_test_decode_server ; reg_test chart : [ glob $(test-dir)/chart.* ] : ../moses-cmd//moses : @reg_test_decode ; actions reg_test_score { @@ -55,5 +60,10 @@ if $(with-regtest) { reg_test misc : [ glob $(test-dir)/misc.* : $(test-dir)/misc.mml* ] : ..//prefix-bin ..//prefix-lib : @reg_test_misc ; reg_test misc-mml : [ glob $(test-dir)/misc.mml* ] : $(TOP)/scripts/ems/support/mml-filter.py $(TOP)/scripts/ems/support/defaultconfig.py : @reg_test_misc ; - alias all : phrase chart mert score extract extractrules misc misc-mml ; + if $(with-xmlrpc) { + alias all : phrase phrase-server chart mert score extract extractrules misc misc-mml ; + } + else { + alias all : phrase chart mert score extract extractrules misc misc-mml ; + } } diff --git a/regression-testing/run-single-test.perl b/regression-testing/run-single-test.perl index 94a247e46..f5ff96e0a 100755 --- a/regression-testing/run-single-test.perl +++ b/regression-testing/run-single-test.perl @@ -2,6 +2,9 @@ # $Id$ +use Encode; +use XMLRPC::Lite; +use utf8; use warnings; use strict; my $script_dir; BEGIN { use Cwd qw/ abs_path /; use File::Basename; $script_dir = dirname(abs_path($0)); push @INC, $script_dir; } @@ -17,12 +20,16 @@ my $data_dir; my $BIN_TEST = $script_dir; my $results_dir; my $NBEST = 0; +my $run_server_test = 0; +my $serverport = 16531; +my $url = "http://localhost:$serverport/RPC2"; GetOptions("decoder=s" => \$decoder, "test=s" => \$test_name, "data-dir=s"=> \$data_dir, "test-dir=s"=> \$test_dir, "results-dir=s"=> \$results_dir, + "server"=> \$run_server_test, ) or exit 1; die "Please specify a decoder with --decoder\n" unless $decoder; @@ -72,8 +79,13 @@ if (!-d $truth) { } print "RESULTS AVAILABLE IN: $results\n\n"; - -my ($o, $elapsed, $ec, $sig) = exec_moses($decoder, $local_moses_ini, $input, $results); +my ($o, $elapsed, $ec, $sig); +if($run_server_test) { + ($o, $elapsed, $ec, $sig) = exec_moses($decoder, $local_moses_ini, $input, $results); +} +else { + ($o, $elapsed, $ec, $sig) = exec_moses_server($decoder, $local_moses_ini, $input, $results); +} my $error = ($sig || $ec > 0); if ($error) { open OUT, ">$results/Summary"; @@ -139,6 +151,42 @@ sub exec_moses { return ($o, $elapsed, $ec, $sig); } +sub exec_moses_server { + my ($decoder, $conf, $input, $results) = @_; + my $start_time = time; + my ($o, $ec, $sig); + my $pid = fork(); + if (not defined $pid) { + warn "resources not avilable to fork Moses server\n"; + $ec = 1; # to generate error + $sig = 'SIGABRT'; + } elsif ($pid == 0) { + warn "Starting Moses server...\n"; + ($o, $ec, $sig) = run_command("$decoder --server --server-port $serverport -f $conf --server-log $results/run.stderr"); + # this should not be reached unless the server fails to start + } + else { + sleep 10; + my $proxy = XMLRPC::Lite->proxy($url); + open(TEXTIN, "$input") or die "Can not open the input file to translate with Moses server\n"; + binmode TEXTIN, ':utf8'; + open(TEXTOUT, ">$results/run.stdout"); + binmode TEXTOUT, ':utf8'; + while() + { + chop; + my $encoded = SOAP::Data->type(string => Encode::encode("utf8", $_)); + my %param = ("text" => $encoded); + my $result = $proxy->call("translate",\%param)->result; + print TEXTOUT $result->{'text'} . "\n"; + } + close(TEXTOUT); + kill('-SIGTERM', $pid); + } + my $elapsed = time - $start_time; + return ($o, $elapsed, $ec, $sig); +} + sub run_command { my ($cmd) = @_; my $o = `$cmd`; diff --git a/run-regtests.sh b/run-regtests.sh index 8b64eac22..5b814e444 100755 --- a/run-regtests.sh +++ b/run-regtests.sh @@ -7,8 +7,11 @@ set -e -o pipefail git submodule init git submodule update regtest +RECOMPILE=${RECOMPILE:-"-a"} + # test compilation without xmlrpc-c -./bjam -j$(nproc) --with-irstlm=./opt --with-boost=./opt --with-cmph=./opt --no-xmlrpc-c --with-regtest=./regtest -a -q $@ || exit $? +# ./bjam -j$(nproc) --with-irstlm=./opt --with-boost=./opt --with-cmph=./opt --no-xmlrpc-c --with-regtest=./regtest $RECOMPILE -q $@ || exit $? # test compilation with xmlrpc-c -./bjam -j$(nproc) --with-irstlm=./opt --with-boost=./opt --with-cmph=./opt --with-xmlrpc-c=./opt --with-regtest=./regtest -a -q $@ +./bjam -j$(nproc) --with-irstlm=./opt --with-boost=./opt --with-cmph=./opt --with-xmlrpc-c=./opt --with-regtest=./regtest $RECOMPILE -q $@ + From fb1195e14cd549f230594bbc2a73c7dbf46952e1 Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Wed, 18 Nov 2015 16:54:34 +0100 Subject: [PATCH 05/13] fixed an error in regression testing for moses server --- regression-testing/Jamfile | 2 +- regression-testing/run-single-test.perl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/regression-testing/Jamfile b/regression-testing/Jamfile index f2649908c..2a1b58364 100644 --- a/regression-testing/Jamfile +++ b/regression-testing/Jamfile @@ -29,7 +29,7 @@ if $(with-regtest) { $(TOP)/regression-testing/run-single-test.perl --server --decoder=$(>) --test=$(<:B) --data-dir=$(with-regtest) --test-dir=$(test-dir) && touch $(<) } reg_test phrase : [ glob $(test-dir)/phrase.* ] : ../moses-cmd//moses : @reg_test_decode ; - reg_test phrase-server : [ glob $(test-dir)/phrase.* ] : ../moses-cmd//moses : @reg_test_decode_server ; + reg_test phrase-server : [ glob $(test-dir)/phrase-server.* ] : ../moses-cmd//moses : @reg_test_decode_server ; reg_test chart : [ glob $(test-dir)/chart.* ] : ../moses-cmd//moses : @reg_test_decode ; actions reg_test_score { diff --git a/regression-testing/run-single-test.perl b/regression-testing/run-single-test.perl index f5ff96e0a..70bb12b65 100755 --- a/regression-testing/run-single-test.perl +++ b/regression-testing/run-single-test.perl @@ -81,10 +81,10 @@ if (!-d $truth) { print "RESULTS AVAILABLE IN: $results\n\n"; my ($o, $elapsed, $ec, $sig); if($run_server_test) { - ($o, $elapsed, $ec, $sig) = exec_moses($decoder, $local_moses_ini, $input, $results); + ($o, $elapsed, $ec, $sig) = exec_moses_server($decoder, $local_moses_ini, $input, $results); } else { - ($o, $elapsed, $ec, $sig) = exec_moses_server($decoder, $local_moses_ini, $input, $results); + ($o, $elapsed, $ec, $sig) = exec_moses($decoder, $local_moses_ini, $input, $results); } my $error = ($sig || $ec > 0); if ($error) { From 0f16e804b55f0c4cb96cc4139a7b3ad17fdde546 Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Thu, 19 Nov 2015 04:02:28 -0700 Subject: [PATCH 06/13] continuing to fix regression tests --- regression-testing/run-single-test.perl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/regression-testing/run-single-test.perl b/regression-testing/run-single-test.perl index 70bb12b65..0d5b85f09 100755 --- a/regression-testing/run-single-test.perl +++ b/regression-testing/run-single-test.perl @@ -155,14 +155,17 @@ sub exec_moses_server { my ($decoder, $conf, $input, $results) = @_; my $start_time = time; my ($o, $ec, $sig); + $ec = 0; $sig = 0; $o = 0; my $pid = fork(); if (not defined $pid) { warn "resources not avilable to fork Moses server\n"; $ec = 1; # to generate error - $sig = 'SIGABRT'; +# $sig = 'SIGABRT'; } elsif ($pid == 0) { + setpgrp(0, 0); warn "Starting Moses server...\n"; - ($o, $ec, $sig) = run_command("$decoder --server --server-port $serverport -f $conf --server-log $results/run.stderr"); + ($o, $ec, $sig) = run_command("$decoder --server --server-port $serverport -f $conf -verbose 2 --server-log $results/run.stderr.server 2> $results/run.stderr "); + exit; # this should not be reached unless the server fails to start } else { @@ -175,14 +178,16 @@ sub exec_moses_server { while() { chop; - my $encoded = SOAP::Data->type(string => Encode::encode("utf8", $_)); + my $encoded = SOAP::Data->type(string => $_); my %param = ("text" => $encoded); my $result = $proxy->call("translate",\%param)->result; print TEXTOUT $result->{'text'} . "\n"; } close(TEXTOUT); - kill('-SIGTERM', $pid); + kill 9, -$pid; } + kill 9, -$pid; + waitpid $pid, 0; my $elapsed = time - $start_time; return ($o, $elapsed, $ec, $sig); } From d3fb16d39f4d7b1ff48d90dbaf2550ea7dff0a94 Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Thu, 19 Nov 2015 12:03:19 +0100 Subject: [PATCH 07/13] changed debug output for moses server --- moses/server/TranslationRequest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moses/server/TranslationRequest.cpp b/moses/server/TranslationRequest.cpp index 2317d6434..c749d6210 100644 --- a/moses/server/TranslationRequest.cpp +++ b/moses/server/TranslationRequest.cpp @@ -370,8 +370,8 @@ pack_hypothesis(const Moses::Manager& manager, vector const& BOOST_REVERSE_FOREACH(Hypothesis const* e, edges) manager.OutputSurface(target, *e, StaticData::Instance().GetOutputFactorOrder(), options().output.ReportSegmentation, m_options.output.ReportAllFactors); - - XVERBOSE(1,"SERVER TRANSLATION: " << target.str() << std::endl); + XVERBOSE(1, *(manager.GetBestHypothesis()) << std::endl); +// XVERBOSE(1,"SERVER TRANSLATION: " << target.str() << std::endl); dest[key] = xmlrpc_c::value_string(target.str()); From aa7ef1738b506ddb57f2205c4774352dc9b50ea6 Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Thu, 19 Nov 2015 12:20:48 +0100 Subject: [PATCH 08/13] another update in Debug output for Moses server --- moses/server/TranslationRequest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moses/server/TranslationRequest.cpp b/moses/server/TranslationRequest.cpp index c749d6210..d6a70ecc6 100644 --- a/moses/server/TranslationRequest.cpp +++ b/moses/server/TranslationRequest.cpp @@ -370,7 +370,7 @@ pack_hypothesis(const Moses::Manager& manager, vector const& BOOST_REVERSE_FOREACH(Hypothesis const* e, edges) manager.OutputSurface(target, *e, StaticData::Instance().GetOutputFactorOrder(), options().output.ReportSegmentation, m_options.output.ReportAllFactors); - XVERBOSE(1, *(manager.GetBestHypothesis()) << std::endl); + XVERBOSE(1, "BEST TRANLSLATION:" << *(manager.GetBestHypothesis()) << std::endl); // XVERBOSE(1,"SERVER TRANSLATION: " << target.str() << std::endl); dest[key] = xmlrpc_c::value_string(target.str()); From f346dcd37fbaf2381c30d1ec58da7ea9a7c21842 Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Thu, 19 Nov 2015 12:42:07 +0100 Subject: [PATCH 09/13] another fix to debug output for moses server --- moses/server/TranslationRequest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moses/server/TranslationRequest.cpp b/moses/server/TranslationRequest.cpp index d6a70ecc6..fa9c9c636 100644 --- a/moses/server/TranslationRequest.cpp +++ b/moses/server/TranslationRequest.cpp @@ -370,7 +370,7 @@ pack_hypothesis(const Moses::Manager& manager, vector const& BOOST_REVERSE_FOREACH(Hypothesis const* e, edges) manager.OutputSurface(target, *e, StaticData::Instance().GetOutputFactorOrder(), options().output.ReportSegmentation, m_options.output.ReportAllFactors); - XVERBOSE(1, "BEST TRANLSLATION:" << *(manager.GetBestHypothesis()) << std::endl); + XVERBOSE(1, "BEST TRANSLATION: " << *(manager.GetBestHypothesis()) << std::endl); // XVERBOSE(1,"SERVER TRANSLATION: " << target.str() << std::endl); dest[key] = xmlrpc_c::value_string(target.str()); From c60d23ecb361bec5470d8286d2f789f94bdd601f Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Thu, 19 Nov 2015 07:56:53 -0700 Subject: [PATCH 10/13] updated regression testing to work correctly with moses server tests --- regression-testing/run-single-test.perl | 68 ++++++++++++++++--------- regtest | 2 +- run-regtests.sh | 11 ++-- 3 files changed, 53 insertions(+), 28 deletions(-) diff --git a/regression-testing/run-single-test.perl b/regression-testing/run-single-test.perl index 0d5b85f09..1ff8ddb12 100755 --- a/regression-testing/run-single-test.perl +++ b/regression-testing/run-single-test.perl @@ -3,7 +3,6 @@ # $Id$ use Encode; -use XMLRPC::Lite; use utf8; use warnings; use strict; @@ -12,6 +11,7 @@ use MosesRegressionTesting; use Getopt::Long; use File::Temp qw ( tempfile ); use POSIX qw ( strftime ); +use POSIX ":sys_wait_h"; my @SIGS = qw ( SIGHUP SIGINT SIGQUIT SIGILL SIGTRAP SIGABRT SIGIOT SIGBUS SIGFPE SIGKILL SIGUSR1 SIGSEGV SIGUSR2 SIGPIPE SIGALRM SIGTERM SIGSTKFLT SIGCHLD SIGCONT SIGSTOP SIGTSTP SIGTTIN SIGTTOU SIGURG SIGXCPU SIGXFSZ SIGVTALRM SIGPROF SIGWINCH SIGIO SIGPWR SIGSYS SIGUNUSED SIGRTMIN ); my ($decoder, $test_name); @@ -21,17 +21,30 @@ my $BIN_TEST = $script_dir; my $results_dir; my $NBEST = 0; my $run_server_test = 0; -my $serverport = 16531; +my $serverport = int(rand(9999)) + 10001; my $url = "http://localhost:$serverport/RPC2"; - +my $startupTest = 0; GetOptions("decoder=s" => \$decoder, "test=s" => \$test_name, "data-dir=s"=> \$data_dir, "test-dir=s"=> \$test_dir, "results-dir=s"=> \$results_dir, "server"=> \$run_server_test, + "startuptest"=> \$startupTest ) or exit 1; +if($run_server_test) +{ + eval { + require XMLRPC::Lite; + import XMLRPC::Lite; + }; + if ($@) { + die "Error: XMLRPC::Lite not installed, moses server regression tests will not be run. $@"; + } + exit(1) if($startupTest); +} + die "Please specify a decoder with --decoder\n" unless $decoder; die "Please specify a test to run with --test\n" unless $test_name; @@ -160,35 +173,42 @@ sub exec_moses_server { if (not defined $pid) { warn "resources not avilable to fork Moses server\n"; $ec = 1; # to generate error -# $sig = 'SIGABRT'; } elsif ($pid == 0) { setpgrp(0, 0); - warn "Starting Moses server...\n"; + warn "Starting Moses server on port $serverport ...\n"; ($o, $ec, $sig) = run_command("$decoder --server --server-port $serverport -f $conf -verbose 2 --server-log $results/run.stderr.server 2> $results/run.stderr "); exit; # this should not be reached unless the server fails to start } - else { - sleep 10; - my $proxy = XMLRPC::Lite->proxy($url); - open(TEXTIN, "$input") or die "Can not open the input file to translate with Moses server\n"; - binmode TEXTIN, ':utf8'; - open(TEXTOUT, ">$results/run.stdout"); - binmode TEXTOUT, ':utf8'; - while() - { - chop; - my $encoded = SOAP::Data->type(string => $_); - my %param = ("text" => $encoded); - my $result = $proxy->call("translate",\%param)->result; - print TEXTOUT $result->{'text'} . "\n"; - } - close(TEXTOUT); + while( 1==1 ) # wait until the server is listening for requests + { + sleep 5; + my $str = `grep "Listening on port $serverport" $results/run.stderr`; + last if($str =~ /Listening/); + } + my $proxy = XMLRPC::Lite->proxy($url); + warn "Opening file $input to write to $results\n"; + open(TEXTIN, "$input") or die "Can not open the input file to translate with Moses server\n"; + binmode TEXTIN, ':utf8'; + open(TEXTOUT, ">$results/run.stdout"); + binmode TEXTOUT, ':utf8'; + while() + { + chop; + my $encoded = SOAP::Data->type(string => $_); # NOTE: assuming properly encoded UTF-8 input: check tests before adding them! + my %param = ("text" => $encoded); + my $result = $proxy->call("translate",\%param)->result; + print TEXTOUT $result->{'text'} . "\n"; + } + close(TEXTIN); + close(TEXTOUT); + my $elapsed = time - $start_time; + print STDERR "Finished translating file $input\n"; + if(waitpid($pid, WNOHANG) <= 0) + { + warn "Killing process group $pid of the $decoder --server ... \n"; kill 9, -$pid; } - kill 9, -$pid; - waitpid $pid, 0; - my $elapsed = time - $start_time; return ($o, $elapsed, $ec, $sig); } diff --git a/regtest b/regtest index e07a00c97..f434f7e9b 160000 --- a/regtest +++ b/regtest @@ -1 +1 @@ -Subproject commit e07a00c9733e0fecb8433f1c9d5805d3f0b35c6f +Subproject commit f434f7e9b04057d82b4e5c55bd49962c8a2852be diff --git a/run-regtests.sh b/run-regtests.sh index 5b814e444..e4120ea26 100755 --- a/run-regtests.sh +++ b/run-regtests.sh @@ -7,11 +7,16 @@ set -e -o pipefail git submodule init git submodule update regtest -RECOMPILE=${RECOMPILE:-"-a"} +if [ "$RECOMPILE" == "NO" ] ; then + RECOMPILE= +else + RECOMPILE="-a" +fi # test compilation without xmlrpc-c # ./bjam -j$(nproc) --with-irstlm=./opt --with-boost=./opt --with-cmph=./opt --no-xmlrpc-c --with-regtest=./regtest $RECOMPILE -q $@ || exit $? # test compilation with xmlrpc-c -./bjam -j$(nproc) --with-irstlm=./opt --with-boost=./opt --with-cmph=./opt --with-xmlrpc-c=./opt --with-regtest=./regtest $RECOMPILE -q $@ - +if [ ./regression-testing/run-single-test.perl --server --startuptest ] ; then + ./bjam -j$(nproc) --with-irstlm=./opt --with-boost=./opt --with-cmph=./opt --with-xmlrpc-c=./opt --with-regtest=./regtest $RECOMPILE -q $@ +fi From 6c7e69996f5ac1be846d0c04f7cee6444ebfdbb5 Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Thu, 19 Nov 2015 08:03:12 -0700 Subject: [PATCH 11/13] updated the regression testing wrapper script --- regression-testing/run-single-test.perl | 2 +- run-regtests.sh | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/regression-testing/run-single-test.perl b/regression-testing/run-single-test.perl index 1ff8ddb12..c99165247 100755 --- a/regression-testing/run-single-test.perl +++ b/regression-testing/run-single-test.perl @@ -42,7 +42,7 @@ if($run_server_test) if ($@) { die "Error: XMLRPC::Lite not installed, moses server regression tests will not be run. $@"; } - exit(1) if($startupTest); + exit(0) if($startupTest); } die "Please specify a decoder with --decoder\n" unless $decoder; diff --git a/run-regtests.sh b/run-regtests.sh index e4120ea26..2cb73aa2d 100755 --- a/run-regtests.sh +++ b/run-regtests.sh @@ -4,8 +4,8 @@ set -e -o pipefail -git submodule init -git submodule update regtest +# git submodule init +# git submodule update regtest if [ "$RECOMPILE" == "NO" ] ; then RECOMPILE= @@ -14,9 +14,9 @@ else fi # test compilation without xmlrpc-c -# ./bjam -j$(nproc) --with-irstlm=./opt --with-boost=./opt --with-cmph=./opt --no-xmlrpc-c --with-regtest=./regtest $RECOMPILE -q $@ || exit $? +./bjam -j$(nproc) --with-irstlm=./opt --with-boost=./opt --with-cmph=./opt --no-xmlrpc-c --with-regtest=./regtest $RECOMPILE -q $@ || exit $? # test compilation with xmlrpc-c -if [ ./regression-testing/run-single-test.perl --server --startuptest ] ; then +if ./regression-testing/run-single-test.perl --server --startuptest ; then ./bjam -j$(nproc) --with-irstlm=./opt --with-boost=./opt --with-cmph=./opt --with-xmlrpc-c=./opt --with-regtest=./regtest $RECOMPILE -q $@ fi From 66be9acc4e6da7ddc3878851f9c71b13b499d8cc Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Thu, 19 Nov 2015 08:12:31 -0700 Subject: [PATCH 12/13] restored submodule update in run-regtests.sh --- run-regtests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run-regtests.sh b/run-regtests.sh index 2cb73aa2d..a8a22d292 100755 --- a/run-regtests.sh +++ b/run-regtests.sh @@ -4,8 +4,8 @@ set -e -o pipefail -# git submodule init -# git submodule update regtest +git submodule init +git submodule update regtest if [ "$RECOMPILE" == "NO" ] ; then RECOMPILE= From 694c449b0d373c4d0ca591a984f72804d2acf305 Mon Sep 17 00:00:00 2001 From: Evgeny Matusov Date: Thu, 19 Nov 2015 08:56:20 -0700 Subject: [PATCH 13/13] final change to regression-test Jamfile to run server tests only when --with-xmlrpc-c option is present. --- regression-testing/Jamfile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/regression-testing/Jamfile b/regression-testing/Jamfile index 2a1b58364..ec6626475 100644 --- a/regression-testing/Jamfile +++ b/regression-testing/Jamfile @@ -25,13 +25,18 @@ if $(with-regtest) { actions reg_test_decode { $(TOP)/regression-testing/run-single-test.perl --decoder=$(>) --test=$(<:B) --data-dir=$(with-regtest) --test-dir=$(test-dir) && touch $(<) } - actions reg_test_decode_server { + + if $(with-xmlrpc) { + actions reg_test_decode_server { $(TOP)/regression-testing/run-single-test.perl --server --decoder=$(>) --test=$(<:B) --data-dir=$(with-regtest) --test-dir=$(test-dir) && touch $(<) + } + reg_test phrase-server : [ glob $(test-dir)/phrase-server.* ] : ../moses-cmd//moses : @reg_test_decode_server ; } + reg_test phrase : [ glob $(test-dir)/phrase.* ] : ../moses-cmd//moses : @reg_test_decode ; - reg_test phrase-server : [ glob $(test-dir)/phrase-server.* ] : ../moses-cmd//moses : @reg_test_decode_server ; + reg_test chart : [ glob $(test-dir)/chart.* ] : ../moses-cmd//moses : @reg_test_decode ; - + actions reg_test_score { $(TOP)/regression-testing/run-test-scorer.perl --scorer=$(>) --test=$(<:B) --data-dir=$(with-regtest) --test-dir=$(test-dir) && touch $(<) } @@ -60,10 +65,5 @@ if $(with-regtest) { reg_test misc : [ glob $(test-dir)/misc.* : $(test-dir)/misc.mml* ] : ..//prefix-bin ..//prefix-lib : @reg_test_misc ; reg_test misc-mml : [ glob $(test-dir)/misc.mml* ] : $(TOP)/scripts/ems/support/mml-filter.py $(TOP)/scripts/ems/support/defaultconfig.py : @reg_test_misc ; - if $(with-xmlrpc) { - alias all : phrase phrase-server chart mert score extract extractrules misc misc-mml ; - } - else { - alias all : phrase chart mert score extract extractrules misc misc-mml ; - } + alias all : phrase chart mert score extract extractrules misc misc-mml ; }