2008-05-14 12:14:13 +04:00
|
|
|
/*
|
|
|
|
* ScoreData.h
|
|
|
|
* met - Minimum Error Training
|
|
|
|
*
|
|
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SCORE_DATA_H
|
|
|
|
#define SCORE_DATA_H
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "Util.h"
|
|
|
|
#include "ScoreArray.h"
|
2008-05-14 20:31:22 +04:00
|
|
|
|
|
|
|
class Scorer;
|
2008-05-14 12:14:13 +04:00
|
|
|
|
|
|
|
class ScoreData
|
|
|
|
{
|
|
|
|
protected:
|
2008-05-27 20:50:52 +04:00
|
|
|
scoredata_t array_;
|
|
|
|
idx2name idx2arrayname_; //map from index to name of array
|
|
|
|
name2idx arrayname2idx_; //map from name to index of array
|
2008-05-14 12:14:13 +04:00
|
|
|
|
|
|
|
private:
|
2008-05-14 14:51:42 +04:00
|
|
|
Scorer* theScorer;
|
|
|
|
std::string score_type;
|
2008-05-20 18:15:30 +04:00
|
|
|
size_t number_of_scores;
|
2008-05-14 12:14:13 +04:00
|
|
|
|
|
|
|
public:
|
2008-05-14 14:51:42 +04:00
|
|
|
ScoreData(Scorer& sc);
|
2008-05-14 12:14:13 +04:00
|
|
|
|
|
|
|
~ScoreData(){};
|
|
|
|
|
|
|
|
inline void clear() { array_.clear(); }
|
|
|
|
|
2008-05-27 20:50:52 +04:00
|
|
|
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){ return exists(getIndex(sent_idx)); }
|
|
|
|
inline bool exists(int sent_idx){ return (sent_idx>-1 && sent_idx<(int)array_.size())?true:false; }
|
2008-05-14 14:51:42 +04:00
|
|
|
|
2008-05-27 20:50:52 +04:00
|
|
|
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); }
|
|
|
|
|
2008-05-14 14:51:42 +04:00
|
|
|
inline std::string name(){ return score_type; };
|
2008-05-27 20:50:52 +04:00
|
|
|
inline std::string name(std::string &sctype){ return score_type = sctype; };
|
2008-05-14 12:14:13 +04:00
|
|
|
|
2008-05-27 20:50:52 +04:00
|
|
|
void add(ScoreArray& e);
|
|
|
|
void add(const ScoreStats& e, const std::string& sent_idx);
|
2008-05-14 12:14:13 +04:00
|
|
|
|
2008-05-27 20:50:52 +04:00
|
|
|
inline size_t NumberOfScores(){ return number_of_scores; }
|
2008-05-14 12:14:13 +04:00
|
|
|
inline size_t size(){ return array_.size(); }
|
|
|
|
|
2008-05-15 12:35:56 +04:00
|
|
|
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); }
|
2008-05-14 12:14:13 +04:00
|
|
|
|
2008-05-15 12:35:56 +04:00
|
|
|
void load(ifstream& inFile);
|
|
|
|
void load(const std::string &file);
|
2008-05-27 20:50:52 +04:00
|
|
|
|
|
|
|
bool check_consistency();
|
|
|
|
void setIndex();
|
|
|
|
|
|
|
|
inline int getIndex(const std::string& idx){
|
|
|
|
name2idx::iterator i = arrayname2idx_.find(idx);
|
|
|
|
if (i!=arrayname2idx_.end())
|
|
|
|
return i->second;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
inline std::string getIndex(size_t idx){
|
|
|
|
idx2name::iterator i = idx2arrayname_.find(idx);
|
|
|
|
if (i!=idx2arrayname_.end())
|
|
|
|
throw runtime_error("there is no entry at index " + idx);
|
|
|
|
return i->second;
|
|
|
|
}
|
2008-05-14 12:14:13 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-05-14 20:31:22 +04:00
|
|
|
#endif
|