mosesdecoder/mert/ScoreData.h
Tetsuo Kiso 8c3b82e596 Change the naming conventions for the guard macros; Rename TER directory.
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.
2012-02-20 09:46:08 +09:00

118 lines
2.5 KiB
C++

/*
* ScoreData.h
* mert - Minimum Error Rate Training
*
* Created by Nicola Bertoldi on 13/05/08.
*
*/
#ifndef MERT_SCORE_DATA_H_
#define MERT_SCORE_DATA_H_
#include <fstream>
#include <vector>
#include <iostream>
#include <stdexcept>
#include <string>
#include "ScoreArray.h"
#include "ScoreStats.h"
using namespace std;
class Scorer;
class ScoreData
{
protected:
scoredata_t array_;
idx2name idx2arrayname_; // map from index to name of array
name2idx arrayname2idx_; // map from name to index of array
private:
// Do not allow the user to instanciate without arguments.
ScoreData() {}
Scorer* theScorer;
std::string score_type;
size_t number_of_scores;
public:
ScoreData(Scorer& sc);
~ScoreData() {}
inline void clear() {
array_.clear();
}
inline ScoreArray get(const std::string& idx) {
return array_.at(getIndex(idx));
}
inline ScoreArray& get(size_t idx) {
return array_.at(idx);
}
inline const ScoreArray& get(size_t idx) const {
return array_.at(idx);
}
inline bool exists(const std::string& sent_idx) const {
return exists(getIndex(sent_idx));
}
inline bool exists(int sent_idx) const {
return (sent_idx > -1 && sent_idx < static_cast<int>(array_.size())) ? true : false;
}
inline ScoreStats& get(size_t i, size_t j) {
return array_.at(i).get(j);
}
inline const ScoreStats& get(size_t i, size_t j) const {
return array_.at(i).get(j);
}
inline std::string name() const {
return score_type;
}
inline std::string name(const std::string &sctype) {
return score_type = sctype;
}
void add(ScoreArray& e);
void add(const ScoreStats& e, const std::string& sent_idx);
inline size_t NumberOfScores() const {
return number_of_scores;
}
inline size_t size() const {
return array_.size();
}
void save(const std::string &file, bool bin=false);
void save(ofstream& outFile, bool bin=false);
inline void save(bool bin=false) {
save("/dev/stdout", bin);
}
void load(ifstream& inFile);
void load(const std::string &file);
bool check_consistency() const;
void setIndex();
inline int getIndex(const std::string& idx) const {
name2idx::const_iterator i = arrayname2idx_.find(idx);
if (i != arrayname2idx_.end())
return i->second;
else
return -1;
}
inline std::string getIndex(size_t idx) const {
idx2name::const_iterator i = idx2arrayname_.find(idx);
if (i != idx2arrayname_.end())
throw runtime_error("there is no entry at index " + idx);
return i->second;
}
};
#endif // MERT_SCORE_DATA_H_