mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-08-16 15:00:33 +03:00
Reduction in number of #ifdef HAVE_XMLRPC_C, as per Hieu's request.
This commit is contained in:
parent
c435e46560
commit
ec1ef78d51
@ -1,4 +1,4 @@
|
||||
// -*- c++ -*-
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
// A class to store "local" information (such as task-specific caches).
|
||||
// The idea is for each translation task to have a scope, which stores
|
||||
// shared pointers to task-specific objects such as caches and priors.
|
||||
@ -14,16 +14,12 @@
|
||||
|
||||
// for some reason, the xmlrpc_c headers must be included AFTER the
|
||||
// boost thread-related ones ...
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
#include <xmlrpc-c/registry.hpp>
|
||||
#include <xmlrpc-c/server_abyss.hpp>
|
||||
#endif
|
||||
|
||||
#include "xmlrpc-c.h"
|
||||
|
||||
#include <map>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
// #include "thread_safe_container.h"
|
||||
#include "TypeDef.h"
|
||||
#include "Util.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
@ -40,25 +36,6 @@ protected:
|
||||
#endif
|
||||
SPTR<std::map<std::string,float> const> m_context_weights;
|
||||
public:
|
||||
// class write_access
|
||||
// {
|
||||
// boost::unique_lock<boost::shared_mutex> m_lock;
|
||||
// public:
|
||||
|
||||
// write_access(boost::shared_mutex& lock)
|
||||
// : m_lock(lock)
|
||||
// { }
|
||||
|
||||
// write_access(write_access& other)
|
||||
// {
|
||||
// swap(m_lock, other.m_lock);
|
||||
// }
|
||||
// };
|
||||
|
||||
// write_access lock() const
|
||||
// {
|
||||
// return write_access(m_lock);
|
||||
// }
|
||||
|
||||
template<typename T>
|
||||
boost::shared_ptr<void> const&
|
||||
@ -109,22 +86,10 @@ public:
|
||||
m_scratchpad = other.m_scratchpad;
|
||||
}
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
SPTR<std::map<std::string,float> const>
|
||||
GetContextWeights(xmlrpc_c::value const* spec = NULL) {
|
||||
if (spec && m_context_weights == NULL) {
|
||||
boost::unique_lock<boost::shared_mutex> lock(m_lock);
|
||||
SPTR<std::map<std::string,float> > M(new std::map<std::string, float>);
|
||||
|
||||
typedef std::map<std::string,xmlrpc_c::value> tmap;
|
||||
tmap const tmp = static_cast<tmap>(xmlrpc_c::value_struct(*spec));
|
||||
for(tmap::const_iterator m = tmp.begin(); m != tmp.end(); ++m)
|
||||
(*M)[m->first] = xmlrpc_c::value_double(m->second);
|
||||
m_context_weights = M;
|
||||
}
|
||||
GetContextWeights() {
|
||||
return m_context_weights;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool
|
||||
SetContextWeights(std::string const& spec) {
|
||||
@ -147,7 +112,9 @@ public:
|
||||
bool
|
||||
SetContextWeights(SPTR<std::map<std::string,float> const> const& w) {
|
||||
if (m_context_weights) return false;
|
||||
#ifdef WITH_THREADS
|
||||
boost::unique_lock<boost::shared_mutex> lock(m_lock);
|
||||
#endif
|
||||
m_context_weights = w;
|
||||
return true;
|
||||
}
|
||||
|
@ -60,13 +60,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#endif
|
||||
|
||||
#include "ExportInterface.h"
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
#include <xmlrpc-c/registry.hpp>
|
||||
#include <xmlrpc-c/server_abyss.hpp>
|
||||
#include "server/Server.h"
|
||||
#endif
|
||||
|
||||
#include "moses/server/Server.h"
|
||||
using namespace std;
|
||||
using namespace Moses;
|
||||
|
||||
@ -148,6 +142,9 @@ run_as_server()
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
MosesServer::Server server(params);
|
||||
return server.run(); // actually: don't return. see Server::run()
|
||||
#else
|
||||
UTIL_THROW2("Moses was compiled without xmlrpc-c. "
|
||||
<< "No server functionality available.");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -229,10 +226,8 @@ batch_run()
|
||||
if (context_window)
|
||||
task->SetContextWindow(context_window);
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
if (context_weights != "" && !task->GetScope()->GetContextWeights())
|
||||
task->GetScope()->SetContextWeights(context_weights);
|
||||
#endif
|
||||
|
||||
// Allow for (sentence-)context-specific processing prior to
|
||||
// decoding. This can be used, for example, for context-sensitive
|
||||
|
@ -811,11 +811,9 @@ namespace Moses
|
||||
Mmsapt::
|
||||
setup_bias(ttasksptr const& ttask)
|
||||
{
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
|
||||
// VERBOSE(2,"Setting up bias at " << HERE << std::endl);
|
||||
SPTR<ContextScope> const& scope = ttask->GetScope();
|
||||
SPTR<ContextForQuery> context = scope->get<ContextForQuery>(btfix.get(), true);
|
||||
SPTR<ContextForQuery> context;
|
||||
context = scope->get<ContextForQuery>(btfix.get(), true);
|
||||
if (context->bias) return;
|
||||
|
||||
// bias weights specified with the session?
|
||||
@ -853,7 +851,6 @@ namespace Moses
|
||||
context->bias_log = m_bias_log;
|
||||
context->bias->loglevel = m_bias_loglevel;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -90,7 +90,6 @@ namespace Moses
|
||||
if (!output.update(param)) return false;
|
||||
return sanity_check();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool
|
||||
|
@ -35,10 +35,7 @@ namespace Moses
|
||||
AllOptions() {}
|
||||
AllOptions(Parameter const& param);
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool update(std::map<std::string,xmlrpc_c::value>const& param);
|
||||
#endif
|
||||
|
||||
bool NBestDistinct() const;
|
||||
|
||||
};
|
||||
|
@ -18,10 +18,8 @@ namespace Moses
|
||||
CubePruningOptions(Parameter const& param);
|
||||
CubePruningOptions() {};
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool
|
||||
update(std::map<std::string,xmlrpc_c::value>const& params);
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -24,9 +24,7 @@ struct NBestOptions : public OptionsBaseClass
|
||||
|
||||
bool init(Parameter const& param);
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool update(std::map<std::string,xmlrpc_c::value>const& param);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width:2 -*-
|
||||
#include "OptionsBaseClass.h"
|
||||
namespace Moses {
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool
|
||||
OptionsBaseClass::
|
||||
@ -10,7 +9,9 @@ namespace Moses
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool
|
||||
OptionsBaseClass::
|
||||
check(std::map<std::string, xmlrpc_c::value> const& param,
|
||||
@ -19,7 +20,5 @@ namespace Moses
|
||||
std::map<std::string, xmlrpc_c::value>::const_iterator m;
|
||||
return (param.find(key) != param.end());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
#pragma once
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
#endif
|
||||
#include "moses/xmlrpc-c.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
namespace Moses
|
||||
@ -12,10 +10,9 @@ namespace Moses
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
virtual bool
|
||||
update(std::map<std::string,xmlrpc_c::value>const& params);
|
||||
|
||||
#endif
|
||||
bool
|
||||
check(std::map<std::string, xmlrpc_c::value> const& param,
|
||||
std::string const key);
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
@ -68,10 +68,11 @@ namespace Moses {
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool
|
||||
ReportingOptions::
|
||||
update(std::map<std::string,xmlrpc_c::value>const& param)
|
||||
update(std::map<std::string, xmlrpc_c::value>const& param)
|
||||
{
|
||||
ReportAllFactors = check(param, "report-all-factors");
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
@ -52,9 +52,8 @@ namespace Moses
|
||||
}
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool update(std::map<std::string,xmlrpc_c::value>const& param);
|
||||
bool update(std::map<std::string, xmlrpc_c::value>const& param);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -43,10 +43,8 @@ namespace Moses
|
||||
return early_discarding_threshold != -std::numeric_limits<float>::infinity();
|
||||
}
|
||||
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
bool
|
||||
update(std::map<std::string,xmlrpc_c::value>const& params);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width:2 -*-
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
#include "PackScores.h"
|
||||
#include "moses/FF/StatefulFeatureFunction.h"
|
||||
#include "moses/FF/StatelessFeatureFunction.h"
|
||||
@ -44,5 +43,3 @@ PackScores(ScoreComponentCollection const& S)
|
||||
return xmlrpc_c::value_struct(M);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,16 +1,10 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width:2 -*-
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
#pragma once
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
#include "moses/FF/FeatureFunction.h"
|
||||
#include "moses/ScoreComponentCollection.h"
|
||||
|
||||
namespace Moses {
|
||||
|
||||
xmlrpc_c::value
|
||||
PackScores(ScoreComponentCollection const& S);
|
||||
|
||||
xmlrpc_c::value
|
||||
PackScores(ScoreComponentCollection const& S);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,11 +1,9 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
#include "Server.h"
|
||||
|
||||
namespace MosesServer
|
||||
{
|
||||
Server::
|
||||
Server(Moses::Parameter& params)
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
: m_server_options(params),
|
||||
m_updater(new Updater),
|
||||
m_optimizer(new Optimizer),
|
||||
@ -17,15 +15,11 @@ namespace MosesServer
|
||||
m_registry.addMethod("optimize", m_optimizer);
|
||||
m_registry.addMethod("close_session", m_close_session);
|
||||
}
|
||||
#else
|
||||
{ }
|
||||
#endif
|
||||
|
||||
int
|
||||
Server::
|
||||
run()
|
||||
{
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
xmlrpc_c::serverAbyss myAbyssServer
|
||||
(xmlrpc_c::serverAbyss::constrOpt()
|
||||
.registryP(&m_registry)
|
||||
@ -42,12 +36,8 @@ namespace MosesServer
|
||||
}
|
||||
else myAbyssServer.run();
|
||||
|
||||
std::cerr << "xmlrpc_c::serverAbyss.run() returned but should not." << std::endl;
|
||||
// #pragma message("BUILDING MOSES WITH SERVER SUPPORT")
|
||||
#else
|
||||
// #pragma message("BUILDING MOSES WITHOUT SERVER SUPPORT")
|
||||
std::cerr << "Moses was compiled without server support." << std::endl;
|
||||
#endif
|
||||
std::cerr << "xmlrpc_c::serverAbyss.run() returned but it should not."
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -71,6 +61,4 @@ namespace MosesServer
|
||||
{
|
||||
return m_session_cache.erase(session_id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
|
||||
#pragma once
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
#include "moses/TypeDef.h"
|
||||
|
||||
#ifdef WITH_THREADS
|
||||
#include <boost/thread.hpp>
|
||||
#include "moses/ThreadPool.h"
|
||||
#endif
|
||||
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
#include <xmlrpc-c/registry.hpp>
|
||||
#include <xmlrpc-c/server_abyss.hpp>
|
||||
@ -14,7 +15,6 @@
|
||||
#include "Updater.h"
|
||||
#include "CloseSession.h"
|
||||
#include "Session.h"
|
||||
#endif
|
||||
#include "moses/parameters/ServerOptions.h"
|
||||
|
||||
namespace MosesServer
|
||||
@ -23,13 +23,11 @@ namespace MosesServer
|
||||
{
|
||||
Moses::ServerOptions m_server_options;
|
||||
SessionCache m_session_cache;
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
xmlrpc_c::registry m_registry;
|
||||
xmlrpc_c::methodPtr const m_updater;
|
||||
xmlrpc_c::methodPtr const m_optimizer;
|
||||
xmlrpc_c::methodPtr const m_translator;
|
||||
xmlrpc_c::methodPtr const m_close_session;
|
||||
#endif
|
||||
public:
|
||||
Server(Moses::Parameter& params);
|
||||
|
||||
|
@ -35,6 +35,17 @@ create(Translator* translator, xmlrpc_c::paramList const& paramList,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
SetContextWeights(Moses::ContextScope& s, xmlrpc_c::value const& w)
|
||||
{
|
||||
SPTR<std::map<std::string,float> > M(new std::map<std::string, float>);
|
||||
typedef std::map<std::string,xmlrpc_c::value> tmap;
|
||||
tmap const tmp = static_cast<tmap>(xmlrpc_c::value_struct(w));
|
||||
for(tmap::const_iterator m = tmp.begin(); m != tmp.end(); ++m)
|
||||
(*M)[m->first] = xmlrpc_c::value_double(m->second);
|
||||
s.SetContextWeights(M);
|
||||
}
|
||||
|
||||
void
|
||||
TranslationRequest::
|
||||
Run()
|
||||
@ -55,8 +66,8 @@ Run()
|
||||
|
||||
// settings within the session scope
|
||||
param_t::const_iterator si = params.find("context-weights");
|
||||
if (si != params.end()) m_scope->GetContextWeights(&si->second);
|
||||
|
||||
if (si != params.end()) SetContextWeights(*m_scope, si->second);
|
||||
|
||||
Moses::StaticData const& SD = Moses::StaticData::Instance();
|
||||
|
||||
//Make sure alternative paths are retained, if necessary
|
||||
|
5
moses/xmlrpc-c.h
Normal file
5
moses/xmlrpc-c.h
Normal file
@ -0,0 +1,5 @@
|
||||
#ifdef HAVE_XMLRPC_C
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
#else
|
||||
namespace xmlrpc_c { class value; }
|
||||
#endif
|
@ -6,4 +6,9 @@ set -e -o pipefail
|
||||
|
||||
git submodule init
|
||||
git submodule update regtest
|
||||
./bjam -j$(nproc) --with-irstlm=./opt --with-boost=./opt --with-cmph=./opt --with-xmlrpc-c=./opt --with-regtest=./regtest $@
|
||||
|
||||
# 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 $?
|
||||
|
||||
# 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 $@
|
||||
|
Loading…
Reference in New Issue
Block a user