mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-28 14:32:38 +03:00
8c3b82e596
This change might be useful to avoid duplicating the names. The reason is that although MERT programs are standalone applications, some header files such as data.h and point.h have common guard macro names like "DATA_H" and "POINT_H", and this is not good naming conventions when you want to include external headers. Some files actually include headers in Moses and KenLM's util.
108 lines
2.0 KiB
C++
108 lines
2.0 KiB
C++
/*
|
|
* ScoreStats.h
|
|
* mert - Minimum Error Rate Training
|
|
*
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
*
|
|
*/
|
|
|
|
#ifndef MERT_SCORE_STATS_H_
|
|
#define MERT_SCORE_STATS_H_
|
|
|
|
#include <vector>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
|
|
#include "Types.h"
|
|
|
|
using namespace std;
|
|
|
|
class ScoreStats
|
|
{
|
|
private:
|
|
size_t available_;
|
|
size_t entries_;
|
|
|
|
// TODO: Use smart pointer for exceptional-safety.
|
|
scorestats_t array_;
|
|
|
|
public:
|
|
ScoreStats();
|
|
explicit ScoreStats(const size_t size);
|
|
explicit ScoreStats(std::string &theString);
|
|
~ScoreStats();
|
|
|
|
// We intentionally allow copying.
|
|
ScoreStats(const ScoreStats &stats);
|
|
ScoreStats& operator=(const ScoreStats &stats);
|
|
|
|
void Copy(const ScoreStats &stats);
|
|
|
|
bool isfull() const {
|
|
return (entries_ < available_) ? 0 : 1;
|
|
}
|
|
|
|
void expand();
|
|
void add(ScoreStatsType v);
|
|
|
|
void clear() {
|
|
memset((void*)array_, 0, GetArraySizeWithBytes());
|
|
}
|
|
|
|
void reset() {
|
|
entries_ = 0;
|
|
clear();
|
|
}
|
|
|
|
inline ScoreStatsType get(size_t i) {
|
|
return array_[i];
|
|
}
|
|
inline ScoreStatsType get(size_t i)const {
|
|
return array_[i];
|
|
}
|
|
inline scorestats_t getArray() const {
|
|
return array_;
|
|
}
|
|
|
|
void set(std::string &theString);
|
|
|
|
inline size_t bytes() const {
|
|
return GetArraySizeWithBytes();
|
|
}
|
|
|
|
size_t GetArraySizeWithBytes() const {
|
|
return entries_ * sizeof(ScoreStatsType);
|
|
}
|
|
|
|
inline size_t size() const {
|
|
return entries_;
|
|
}
|
|
inline size_t available() const {
|
|
return available_;
|
|
}
|
|
|
|
void savetxt(const std::string &file);
|
|
void savetxt(ofstream& outFile);
|
|
void savebin(ofstream& outFile);
|
|
inline void savetxt() {
|
|
savetxt("/dev/stdout");
|
|
}
|
|
|
|
void loadtxt(const std::string &file);
|
|
void loadtxt(ifstream& inFile);
|
|
void loadbin(ifstream& inFile);
|
|
|
|
/**
|
|
* Write the whole object to a stream.
|
|
*/
|
|
friend ostream& operator<<(ostream& o, const ScoreStats& e);
|
|
};
|
|
|
|
//ADDED_BY_TS
|
|
bool operator==(const ScoreStats& s1, const ScoreStats& s2);
|
|
//END_ADDED
|
|
|
|
#endif // MERT_SCORE_STATS_H_
|