mosesdecoder/mert/Util.h

95 lines
1.9 KiB
C
Raw Normal View History

/*
* Util.h
* met - Minimum Error Training
*
* Created by Nicola Bertoldi on 13/05/08.
*
*/
#ifndef UTIL_H
#define UTIL_H
using namespace std;
#include <stdexcept>
#include <limits>
#define US_NOSET (numeric_limits<unsigned short>::max())
#define MAX_LINE 1024
#include <vector>
#include <map>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include "Types.h"
#include "ScoreStats.h"
#include "FeatureStats.h"
class ScoreStats;
class FeatureStats;
#ifdef TRACE_ENABLE
#define TRACE_ERR(str) { std::cerr << str; }
#else
#define TRACE_ERR(str) { }
#endif
#define DELIMITER_SYMBOL " "
int verboselevel();
int setverboselevel(int v);
2011-11-11 17:00:30 +04:00
size_t getNextPound(std::string &theString, std::string &substring, const std::string delimiter=DELIMITER_SYMBOL);
void split(const std::string &s, char delim, std::vector<std::string> &elems);
2011-11-11 17:00:30 +04:00
void Tokenize(const char *str, const char delim, std::vector<std::string> *res);
template<typename T>
inline T Scan(const std::string &input)
{
std::stringstream stream(input);
T ret;
stream >> ret;
return ret;
}
template<typename T>
inline std::string stringify(T x)
{
std::ostringstream o;
if (!(o << x))
throw std::runtime_error("stringify(template<typename T>)");
return o.str();
}
inline ScoreStatsType ConvertCharToScoreStatsType(const char *str)
{
return std::atoi(str);
}
inline ScoreStatsType ConvertStringToScoreStatsType(const std::string& str)
{
return ConvertCharToScoreStatsType(str.c_str());
}
inline FeatureStatsType ConvertCharToFeatureStatsType(const char *str)
{
return static_cast<FeatureStatsType>(std::atof(str));
}
inline FeatureStatsType ConvertStringToFeatureStatsType(const std::string &str)
{
return ConvertCharToFeatureStatsType(str.c_str());
}
// Utilities to measure decoding time
void ResetUserTime();
void PrintUserTime(const std::string &message);
double GetUserTime();
#endif // UTIL_H