2015-05-11 02:34:24 +03:00
|
|
|
#include "ContextParameters.h"
|
|
|
|
#include "moses/Util.h"
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
|
|
|
ContextParameters::
|
|
|
|
ContextParameters()
|
2015-06-08 14:10:48 +03:00
|
|
|
: look_ahead(0), look_back(0)
|
|
|
|
{ }
|
2015-05-11 02:34:24 +03:00
|
|
|
|
2015-08-05 04:15:34 +03:00
|
|
|
bool
|
2015-05-11 02:34:24 +03:00
|
|
|
ContextParameters::
|
2015-08-05 04:15:34 +03:00
|
|
|
init(Parameter const& params)
|
2015-05-11 02:34:24 +03:00
|
|
|
{
|
|
|
|
look_back = look_ahead = 0;
|
|
|
|
params.SetParameter(context_string, "context-string", std::string(""));
|
|
|
|
std::string context_window;
|
|
|
|
params.SetParameter(context_window, "context-window", std::string(""));
|
|
|
|
|
2015-05-13 13:05:43 +03:00
|
|
|
if (context_window == "")
|
2015-08-05 04:15:34 +03:00
|
|
|
return true;
|
2015-06-08 14:10:48 +03:00
|
|
|
|
|
|
|
if (context_window.substr(0,3) == "all")
|
|
|
|
{
|
|
|
|
look_back = look_ahead = std::numeric_limits<size_t>::max();
|
2015-08-05 04:15:34 +03:00
|
|
|
return true;
|
2015-06-08 14:10:48 +03:00
|
|
|
}
|
|
|
|
|
2015-05-11 02:34:24 +03:00
|
|
|
size_t p = context_window.find_first_of("0123456789");
|
2015-05-13 13:05:43 +03:00
|
|
|
if (p == 0)
|
2015-05-11 02:34:24 +03:00
|
|
|
look_back = look_ahead = atoi(context_window.c_str());
|
2015-06-08 14:10:48 +03:00
|
|
|
|
|
|
|
if (p == 1) {
|
2015-05-13 13:29:16 +03:00
|
|
|
if (context_window[0] == '-')
|
|
|
|
look_back = atoi(context_window.substr(1).c_str());
|
|
|
|
else if (context_window[0] == '+')
|
|
|
|
look_ahead = atoi(context_window.substr(1).c_str());
|
|
|
|
else
|
|
|
|
UTIL_THROW2("Invalid specification of context window.");
|
|
|
|
}
|
2015-06-08 14:10:48 +03:00
|
|
|
|
2015-05-13 13:29:16 +03:00
|
|
|
if (p == 2) {
|
|
|
|
if (context_window.substr(0,2) == "+-" ||
|
|
|
|
context_window.substr(0,2) == "-+")
|
|
|
|
look_back = look_ahead = atoi(context_window.substr(p).c_str());
|
|
|
|
else
|
|
|
|
UTIL_THROW2("Invalid specification of context window.");
|
|
|
|
}
|
2015-08-05 04:15:34 +03:00
|
|
|
return true;
|
2015-05-11 02:34:24 +03:00
|
|
|
}
|
|
|
|
}
|