2008-05-14 12:14:13 +04:00
|
|
|
/*
|
|
|
|
* ScoreData.h
|
2012-02-20 03:29:53 +04:00
|
|
|
* mert - Minimum Error Rate Training
|
2008-05-14 12:14:13 +04:00
|
|
|
*
|
|
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-02-20 04:46:08 +04:00
|
|
|
#ifndef MERT_SCORE_DATA_H_
|
|
|
|
#define MERT_SCORE_DATA_H_
|
2008-05-14 12:14:13 +04:00
|
|
|
|
2011-11-14 10:15:30 +04:00
|
|
|
#include <fstream>
|
2008-05-14 12:14:13 +04:00
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
2011-11-14 10:15:30 +04:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
2008-05-14 12:14:13 +04:00
|
|
|
#include "ScoreArray.h"
|
2011-11-14 10:15:30 +04:00
|
|
|
#include "ScoreStats.h"
|
|
|
|
|
|
|
|
using namespace std;
|
2008-05-14 20:31:22 +04:00
|
|
|
|
|
|
|
class Scorer;
|
2008-05-14 12:14:13 +04:00
|
|
|
|
|
|
|
class ScoreData
|
|
|
|
{
|
|
|
|
protected:
|
2011-02-24 15:42:19 +03:00
|
|
|
scoredata_t array_;
|
2011-11-12 03:58:23 +04:00
|
|
|
idx2name idx2arrayname_; // map from index to name of array
|
|
|
|
name2idx arrayname2idx_; // map from name to index of array
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2008-05-14 12:14:13 +04:00
|
|
|
private:
|
2011-11-14 07:58:42 +04:00
|
|
|
// Do not allow the user to instanciate without arguments.
|
|
|
|
ScoreData() {}
|
|
|
|
|
2011-02-24 15:42:19 +03:00
|
|
|
Scorer* theScorer;
|
|
|
|
std::string score_type;
|
|
|
|
size_t number_of_scores;
|
|
|
|
|
2008-05-14 12:14:13 +04:00
|
|
|
public:
|
2011-02-24 15:42:19 +03:00
|
|
|
ScoreData(Scorer& sc);
|
2011-11-12 04:40:01 +04:00
|
|
|
~ScoreData() {}
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-11-14 09:00:47 +04:00
|
|
|
inline bool exists(const std::string& sent_idx) const {
|
2011-02-24 15:42:19 +03:00
|
|
|
return exists(getIndex(sent_idx));
|
|
|
|
}
|
2012-02-01 13:13:00 +04:00
|
|
|
|
2011-11-12 06:26:13 +04:00
|
|
|
inline bool exists(int sent_idx) const {
|
2012-02-01 13:13:00 +04:00
|
|
|
return (sent_idx > -1 && sent_idx < static_cast<int>(array_.size())) ? true : false;
|
2011-02-24 15:42:19 +03: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);
|
|
|
|
}
|
|
|
|
|
2011-11-12 06:26:13 +04:00
|
|
|
inline std::string name() const {
|
2011-02-24 15:42:19 +03:00
|
|
|
return score_type;
|
2011-11-12 04:40:01 +04:00
|
|
|
}
|
|
|
|
|
2011-11-14 09:00:47 +04:00
|
|
|
inline std::string name(const std::string &sctype) {
|
2011-02-24 15:42:19 +03:00
|
|
|
return score_type = sctype;
|
2011-11-12 04:40:01 +04:00
|
|
|
}
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
void add(ScoreArray& e);
|
|
|
|
void add(const ScoreStats& e, const std::string& sent_idx);
|
|
|
|
|
2011-11-12 06:26:13 +04:00
|
|
|
inline size_t NumberOfScores() const {
|
2011-02-24 15:42:19 +03:00
|
|
|
return number_of_scores;
|
|
|
|
}
|
2011-11-12 06:26:13 +04:00
|
|
|
inline size_t size() const {
|
2011-02-24 15:42:19 +03:00
|
|
|
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);
|
|
|
|
|
2011-11-12 06:26:13 +04:00
|
|
|
bool check_consistency() const;
|
2011-02-24 15:42:19 +03:00
|
|
|
void setIndex();
|
|
|
|
|
2011-11-12 06:26:13 +04:00
|
|
|
inline int getIndex(const std::string& idx) const {
|
|
|
|
name2idx::const_iterator i = arrayname2idx_.find(idx);
|
|
|
|
if (i != arrayname2idx_.end())
|
2011-02-24 15:42:19 +03:00
|
|
|
return i->second;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
2011-11-12 06:26:13 +04:00
|
|
|
inline std::string getIndex(size_t idx) const {
|
|
|
|
idx2name::const_iterator i = idx2arrayname_.find(idx);
|
|
|
|
if (i != idx2arrayname_.end())
|
2011-02-24 15:42:19 +03:00
|
|
|
throw runtime_error("there is no entry at index " + idx);
|
|
|
|
return i->second;
|
2008-05-27 20:50:52 +04:00
|
|
|
}
|
2008-05-14 12:14:13 +04:00
|
|
|
};
|
|
|
|
|
2012-02-20 04:46:08 +04:00
|
|
|
#endif // MERT_SCORE_DATA_H_
|