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
|
|
|
|
2012-03-10 14:04:43 +04:00
|
|
|
#include <iostream>
|
2008-05-14 12:14:13 +04:00
|
|
|
#include <vector>
|
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
|
|
|
|
{
|
|
|
|
private:
|
2011-11-14 07:58:42 +04:00
|
|
|
// Do not allow the user to instanciate without arguments.
|
|
|
|
ScoreData() {}
|
|
|
|
|
2012-03-10 12:12:34 +04:00
|
|
|
scoredata_t m_array;
|
|
|
|
idx2name m_index_to_array_name; // map from index to name of array
|
|
|
|
name2idx m_array_name_to_index; // map from name to index of array
|
|
|
|
|
|
|
|
Scorer* m_scorer;
|
|
|
|
std::string m_score_type;
|
|
|
|
size_t m_num_scores;
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2008-05-14 12:14:13 +04:00
|
|
|
public:
|
2012-03-10 12:28:38 +04:00
|
|
|
ScoreData(Scorer* scorer);
|
2011-11-12 04:40:01 +04:00
|
|
|
~ScoreData() {}
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
inline void clear() {
|
2012-03-10 12:12:34 +04:00
|
|
|
m_array.clear();
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline ScoreArray get(const std::string& idx) {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_array.at(getIndex(idx));
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
|
|
|
inline ScoreArray& get(size_t idx) {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_array.at(idx);
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
|
|
|
inline const ScoreArray& get(size_t idx) const {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_array.at(idx);
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
|
|
|
|
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-03-10 12:12:34 +04:00
|
|
|
return (sent_idx > -1 && sent_idx < static_cast<int>(m_array.size())) ? true : false;
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline ScoreStats& get(size_t i, size_t j) {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_array.at(i).get(j);
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
|
|
|
inline const ScoreStats& get(size_t i, size_t j) const {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_array.at(i).get(j);
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
|
|
|
|
2011-11-12 06:26:13 +04:00
|
|
|
inline std::string name() const {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_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) {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_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 {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_num_scores;
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
2011-11-12 06:26:13 +04:00
|
|
|
inline size_t size() const {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_array.size();
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void save(const std::string &file, bool bin=false);
|
2012-03-10 14:04:43 +04:00
|
|
|
void save(std::ostream* os, bool bin=false);
|
|
|
|
void save(bool bin=false);
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2012-03-10 14:04:43 +04:00
|
|
|
void load(std::istream* is);
|
2011-02-24 15:42:19 +03:00
|
|
|
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 {
|
2012-03-10 12:12:34 +04:00
|
|
|
name2idx::const_iterator i = m_array_name_to_index.find(idx);
|
|
|
|
if (i != m_array_name_to_index.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 {
|
2012-03-10 12:12:34 +04:00
|
|
|
idx2name::const_iterator i = m_index_to_array_name.find(idx);
|
|
|
|
if (i != m_index_to_array_name.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_
|