<commit_before>// -*- mode: c++; cc-style: gnu -*-
#include "ServerOptions.h"
#include <boost/foreach.hpp>
#include <string>
namespace Moses
{

// parse the session timeout specifciation for moses server
// Format is "<number>d[<number>[h[<number>m[<number>s]]]]".
// If none of 'dhms' is given, it is assumed that it's seconds.
// Specs can be combined, e.g. 2h30m, although it's probably nonsense
// to be so specific.
size_t 
parse_timespec(std::string const& spec)
{
  size_t t = 0, timeout = 0;
  BOOST_FOREACH(char const& c, spec)
    {
      if (c >= '0' && c <= '9') 
	{
	  t = t * 10 + c - '0';
	}
      else 
	{
	  if (c == 'd')      timeout  = t * 24 * 3600;
	  else if (c == 'h') timeout += t * 3600;
	  else if (c == 'm') timeout += t * 60;
	  else if (c == 's') timeout += t;
	  else UTIL_THROW2("Can't parse specification '" << spec 
			   << " at " << HERE);
	  t = 0;
	}
    }
  return timeout;
}

ServerOptions::
ServerOptions(Parameter const& P)
{ 
  init(P);
}

bool
ServerOptions::
init(Parameter const& P)
{
  P.SetParameter(this->port, "server-port", 8080);
  P.SetParameter(this->is_serial, "serial", false);
  P.SetParameter(this->logfile, "server-log", std::string("/dev/null"));
  P.SetParameter(this->num_threads, "threads", uint32_t(10));
  P.SetParameter(this->session_cache_size, "session-cache_size",25UL);
  std::string timeout_spec;
  P.SetParameter(timeout_spec, "session-timeout",std::string("30m"));
  this->session_timeout = parse_timespec(timeout_spec);
  return true;
}
} // namespace Moses<commit_msg>ServerOptions.cpp would't compile on systems where size_t != unsigned long int.<commit_after>// -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*-
#include "ServerOptions.h"
#include <boost/foreach.hpp>
#include <string>
namespace Moses
{

// parse the session timeout specifciation for moses server
// Format is "<number>d[<number>[h[<number>m[<number>s]]]]".
// If none of 'dhms' is given, it is assumed that it's seconds.
// Specs can be combined, e.g. 2h30m, although it's probably nonsense
// to be so specific.
size_t 
parse_timespec(std::string const& spec)
{
  size_t t = 0, timeout = 0;
  BOOST_FOREACH(char const& c, spec)
    {
      if (c >= '0' && c <= '9') 
	{
	  t = t * 10 + c - '0';
	}
      else 
	{
	  if (c == 'd')      timeout  = t * 24 * 3600;
	  else if (c == 'h') timeout += t * 3600;
	  else if (c == 'm') timeout += t * 60;
	  else if (c == 's') timeout += t;
	  else UTIL_THROW2("Can't parse specification '" << spec 
			   << " at " << HERE);
	  t = 0;
	}
    }
  return timeout;
}

ServerOptions::
ServerOptions(Parameter const& P)
{ 
  init(P);
}

bool
ServerOptions::
init(Parameter const& P)
{
  P.SetParameter(this->port, "server-port", 8080);
  P.SetParameter(this->is_serial, "serial", false);
  P.SetParameter(this->logfile, "server-log", std::string("/dev/null"));
  P.SetParameter(this->num_threads, "threads", uint32_t(10));
  P.SetParameter(this->session_cache_size, "session-cache_size",(size_t)25);
  std::string timeout_spec;
  P.SetParameter(timeout_spec, "session-timeout",std::string("30m"));
  this->session_timeout = parse_timespec(timeout_spec);
  return true;
}
} // namespace Moses
{'fraction_non_alphanumeric': 0.1765261170547514, 'fraction_numerical': 0.022970421648835747, 'mean_word_length': 3.6544655929721817, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5917680', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1139, 'n_words': 302}