00001 #include "ContextParameters.h"
00002 #include "moses/Util.h"
00003
00004 namespace Moses
00005 {
00006
00007 ContextParameters::
00008 ContextParameters()
00009 : look_ahead(0), look_back(0)
00010 { }
00011
00012 bool
00013 ContextParameters::
00014 init(Parameter const& params)
00015 {
00016 look_back = look_ahead = 0;
00017 params.SetParameter(context_string, "context-string", std::string(""));
00018 std::string context_window;
00019 params.SetParameter(context_window, "context-window", std::string(""));
00020
00021 if (context_window == "")
00022 return true;
00023
00024 if (context_window.substr(0,3) == "all")
00025 {
00026 look_back = look_ahead = std::numeric_limits<size_t>::max();
00027 return true;
00028 }
00029
00030 size_t p = context_window.find_first_of("0123456789");
00031 if (p == 0)
00032 look_back = look_ahead = atoi(context_window.c_str());
00033
00034 if (p == 1) {
00035 if (context_window[0] == '-')
00036 look_back = atoi(context_window.substr(1).c_str());
00037 else if (context_window[0] == '+')
00038 look_ahead = atoi(context_window.substr(1).c_str());
00039 else
00040 UTIL_THROW2("Invalid specification of context window.");
00041 }
00042
00043 if (p == 2) {
00044 if (context_window.substr(0,2) == "+-" ||
00045 context_window.substr(0,2) == "-+")
00046 look_back = look_ahead = atoi(context_window.substr(p).c_str());
00047 else
00048 UTIL_THROW2("Invalid specification of context window.");
00049 }
00050 return true;
00051 }
00052 }