mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
Renamed MosesServer::TranslationTask to MosesServer::TranslationRequest and made that a subtype of Moses::TranslationTask to avoid name confusion.
This commit is contained in:
parent
ee4e396a4d
commit
85d2567b57
@ -1,18 +1,45 @@
|
||||
#include "TranslationTask.h"
|
||||
#include "TranslationRequest.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
namespace MosesServer
|
||||
{
|
||||
using namespace Moses;
|
||||
using namespace std;
|
||||
using Moses::Hypothesis;
|
||||
using Moses::StaticData;
|
||||
using Moses::WordsRange;
|
||||
using Moses::ChartHypothesis;
|
||||
using Moses::Phrase;
|
||||
using Moses::Manager;
|
||||
using Moses::SearchGraphNode;
|
||||
using Moses::TrellisPathList;
|
||||
using Moses::TranslationOptionCollection;
|
||||
using Moses::TranslationOptionList;
|
||||
using Moses::TranslationOption;
|
||||
using Moses::TargetPhrase;
|
||||
using Moses::FValue;
|
||||
using Moses::PhraseDictionaryMultiModel;
|
||||
using Moses::FindPhraseDictionary;
|
||||
using Moses::Sentence;
|
||||
|
||||
boost::shared_ptr<TranslationRequest>
|
||||
TranslationRequest::
|
||||
create(xmlrpc_c::paramList const& paramList,
|
||||
boost::condition_variable& cond,
|
||||
boost::mutex& mut)
|
||||
{
|
||||
boost::shared_ptr<TranslationRequest> ret;
|
||||
ret.reset(new TranslationRequest(paramList,cond, mut));
|
||||
ret->m_self = ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
Run()
|
||||
{
|
||||
parse_request(m_paramList.getStruct(0));
|
||||
|
||||
StaticData const& SD = Moses::StaticData::Instance();
|
||||
Moses::StaticData const& SD = Moses::StaticData::Instance();
|
||||
|
||||
//Make sure alternative paths are retained, if necessary
|
||||
if (m_withGraphInfo || m_nbestSize>0)
|
||||
@ -37,7 +64,7 @@ namespace MosesServer
|
||||
|
||||
/// add phrase alignment information from a Hypothesis
|
||||
void
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
add_phrase_aln_info(Hypothesis const& h, vector<xmlrpc_c::value>& aInfo) const
|
||||
{
|
||||
if (!m_withAlignInfo) return;
|
||||
@ -52,7 +79,7 @@ namespace MosesServer
|
||||
}
|
||||
|
||||
void
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
outputChartHypo(ostream& out, const ChartHypothesis* hypo)
|
||||
{
|
||||
Phrase outPhrase(20);
|
||||
@ -67,13 +94,13 @@ namespace MosesServer
|
||||
}
|
||||
|
||||
bool
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
compareSearchGraphNode(const Moses::SearchGraphNode& a,
|
||||
const Moses::SearchGraphNode& b)
|
||||
{ return a.hypo->GetId() < b.hypo->GetId(); }
|
||||
|
||||
void
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
insertGraphInfo(Manager& manager, map<string, xmlrpc_c::value>& retData)
|
||||
{
|
||||
using xmlrpc_c::value_int;
|
||||
@ -110,7 +137,7 @@ namespace MosesServer
|
||||
}
|
||||
|
||||
void
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
output_phrase(ostream& out, Phrase const& phrase) const
|
||||
{
|
||||
if (!m_reportAllFactors)
|
||||
@ -122,7 +149,7 @@ namespace MosesServer
|
||||
}
|
||||
|
||||
void
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
outputNBest(const Manager& manager, map<string, xmlrpc_c::value>& retData)
|
||||
{
|
||||
TrellisPathList nBestList;
|
||||
@ -151,7 +178,7 @@ namespace MosesServer
|
||||
}
|
||||
|
||||
void
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
insertTranslationOptions(Moses::Manager& manager,
|
||||
std::map<std::string, xmlrpc_c::value>& retData)
|
||||
{
|
||||
@ -197,14 +224,14 @@ namespace MosesServer
|
||||
return (params.find(key) != params.end());
|
||||
}
|
||||
|
||||
TranslationTask::
|
||||
TranslationTask(xmlrpc_c::paramList const& paramList,
|
||||
TranslationRequest::
|
||||
TranslationRequest(xmlrpc_c::paramList const& paramList,
|
||||
boost::condition_variable& cond, boost::mutex& mut)
|
||||
: m_cond(cond), m_mutex(mut), m_done(false), m_paramList(paramList)
|
||||
{ }
|
||||
|
||||
void
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
parse_request(std::map<std::string, xmlrpc_c::value> const& params)
|
||||
{ // parse XMLRPC request
|
||||
// params_t const params = m_paramList.getStruct(0);
|
||||
@ -215,8 +242,8 @@ namespace MosesServer
|
||||
params_t::const_iterator si = params.find("text");
|
||||
if (si == params.end())
|
||||
throw xmlrpc_c::fault("Missing source text", xmlrpc_c::fault::CODE_PARSE);
|
||||
m_source = xmlrpc_c::value_string(si->second);
|
||||
XVERBOSE(1,"Input: " << m_source << endl);
|
||||
m_source_string = xmlrpc_c::value_string(si->second);
|
||||
XVERBOSE(1,"Input: " << m_source_string << endl);
|
||||
|
||||
m_withAlignInfo = check(params, "align");
|
||||
m_withWordAlignInfo = check(params, "word-align");
|
||||
@ -258,11 +285,11 @@ namespace MosesServer
|
||||
|
||||
|
||||
void
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
run_chart_decoder()
|
||||
{
|
||||
Moses::TreeInput tinput(NULL);
|
||||
istringstream buf(m_source + "\n");
|
||||
Moses::TreeInput tinput;
|
||||
istringstream buf(m_source_string + "\n");
|
||||
tinput.Read(buf, StaticData::Instance().GetInputFactorOrder());
|
||||
|
||||
Moses::ChartManager manager(tinput);
|
||||
@ -272,8 +299,8 @@ namespace MosesServer
|
||||
ostringstream out;
|
||||
outputChartHypo(out,hypo);
|
||||
|
||||
m_target = out.str();
|
||||
m_retData["text"] = xmlrpc_c::value_string(m_target);
|
||||
m_target_string = out.str();
|
||||
m_retData["text"] = xmlrpc_c::value_string(m_target_string);
|
||||
|
||||
if (m_withGraphInfo)
|
||||
{
|
||||
@ -281,10 +308,10 @@ namespace MosesServer
|
||||
manager.OutputSearchGraphMoses(sgstream);
|
||||
m_retData["sg"] = xmlrpc_c::value_string(sgstream.str());
|
||||
}
|
||||
} // end of TranslationTask::run_chart_decoder()
|
||||
} // end of TranslationRequest::run_chart_decoder()
|
||||
|
||||
void
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
pack_hypothesis(vector<Hypothesis const* > const& edges, string const& key,
|
||||
map<string, xmlrpc_c::value> & dest) const
|
||||
{
|
||||
@ -313,7 +340,7 @@ namespace MosesServer
|
||||
}
|
||||
|
||||
void
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
pack_hypothesis(Hypothesis const* h, string const& key,
|
||||
map<string, xmlrpc_c::value>& dest) const
|
||||
{
|
||||
@ -326,10 +353,10 @@ namespace MosesServer
|
||||
|
||||
|
||||
void
|
||||
TranslationTask::
|
||||
TranslationRequest::
|
||||
run_phrase_decoder()
|
||||
{
|
||||
Manager manager(Sentence(NULL,0, m_source));
|
||||
Manager manager(Sentence(0, m_source_string));
|
||||
// if (m_bias.size()) manager.SetBias(&m_bias);
|
||||
manager.Decode();
|
||||
|
||||
|
@ -5,9 +5,6 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
|
||||
|
||||
#ifdef WITH_THREADS
|
||||
#include <boost/thread.hpp>
|
||||
#endif
|
||||
@ -20,11 +17,14 @@
|
||||
#include "moses/ThreadPool.h"
|
||||
#include "moses/TranslationModel/PhraseDictionaryMultiModel.h"
|
||||
#include "moses/TreeInput.h"
|
||||
#include "moses/TranslationTask.h"
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
namespace MosesServer
|
||||
{
|
||||
class
|
||||
TranslationTask : public virtual Moses::Task
|
||||
TranslationRequest : public virtual Moses::TranslationTask
|
||||
{
|
||||
boost::condition_variable& m_cond;
|
||||
boost::mutex& m_mutex;
|
||||
@ -34,7 +34,7 @@ namespace MosesServer
|
||||
std::map<std::string, xmlrpc_c::value> m_retData;
|
||||
std::map<uint32_t,float> m_bias; // for biased sampling
|
||||
|
||||
std::string m_source, m_target;
|
||||
std::string m_source_string, m_target_string;
|
||||
bool m_withAlignInfo;
|
||||
bool m_withWordAlignInfo;
|
||||
bool m_withGraphInfo;
|
||||
@ -90,12 +90,19 @@ namespace MosesServer
|
||||
void
|
||||
insertTranslationOptions(Moses::Manager& manager,
|
||||
std::map<std::string, xmlrpc_c::value>& retData);
|
||||
|
||||
public:
|
||||
|
||||
TranslationTask(xmlrpc_c::paramList const& paramList,
|
||||
protected:
|
||||
TranslationRequest(xmlrpc_c::paramList const& paramList,
|
||||
boost::condition_variable& cond,
|
||||
boost::mutex& mut);
|
||||
|
||||
public:
|
||||
|
||||
static
|
||||
boost::shared_ptr<TranslationRequest>
|
||||
create(xmlrpc_c::paramList const& paramList,
|
||||
boost::condition_variable& cond,
|
||||
boost::mutex& mut);
|
||||
|
||||
|
||||
virtual bool
|
||||
DeleteAfterExecution() { return false; }
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "Translator.h"
|
||||
#include "TranslationTask.h"
|
||||
#include "TranslationRequest.h"
|
||||
|
||||
namespace MosesServer
|
||||
{
|
||||
@ -25,12 +25,13 @@ namespace MosesServer
|
||||
{
|
||||
boost::condition_variable cond;
|
||||
boost::mutex mut;
|
||||
TranslationTask task(paramList,cond,mut);
|
||||
m_threadPool.Submit(&task);
|
||||
boost::shared_ptr<TranslationRequest> task
|
||||
= TranslationRequest::create(paramList,cond,mut);
|
||||
m_threadPool.Submit(task);
|
||||
boost::unique_lock<boost::mutex> lock(mut);
|
||||
while (!task.IsDone())
|
||||
while (!task->IsDone())
|
||||
cond.wait(lock);
|
||||
*retvalP = xmlrpc_c::value_struct(task.GetRetData());
|
||||
*retvalP = xmlrpc_c::value_struct(task->GetRetData());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user