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-05-10 02:51:05 +04:00
|
|
|
#include <iosfwd>
|
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"
|
|
|
|
|
2012-06-30 23:23:45 +04:00
|
|
|
namespace MosesTuning
|
|
|
|
{
|
2012-12-06 20:39:22 +04:00
|
|
|
|
2012-06-30 23:23:45 +04:00
|
|
|
|
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;
|
2012-05-10 02:51:05 +04:00
|
|
|
std::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
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
void clear() {
|
|
|
|
m_array.clear();
|
|
|
|
}
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2012-05-10 02:51:05 +04:00
|
|
|
inline ScoreArray& get(std::size_t idx) {
|
2012-03-10 12:12:34 +04:00
|
|
|
return m_array.at(idx);
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
2012-03-10 14:27:52 +04:00
|
|
|
|
2012-05-10 02:51:05 +04:00
|
|
|
inline const ScoreArray& get(std::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
|
|
|
}
|
|
|
|
|
2012-12-06 20:39:22 +04:00
|
|
|
inline bool exists(int sent_idx) const {
|
|
|
|
return existsInternal(getIndex(sent_idx));
|
2011-02-24 15:42:19 +03:00
|
|
|
}
|
2012-02-01 13:13:00 +04:00
|
|
|
|
2012-12-06 20:39:22 +04:00
|
|
|
inline bool existsInternal(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
|
|
|
}
|
|
|
|
|
2012-05-10 02:51:05 +04:00
|
|
|
inline ScoreStats& get(std::size_t i, std::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
|
|
|
}
|
2012-03-10 14:27:52 +04:00
|
|
|
|
2012-05-10 02:51:05 +04:00
|
|
|
inline const ScoreStats& get(std::size_t i, std::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
|
|
|
}
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
std::string name() const {
|
|
|
|
return m_score_type;
|
|
|
|
}
|
2011-11-12 04:40:01 +04:00
|
|
|
|
2012-03-10 14:27:52 +04:00
|
|
|
std::string name(const std::string &score_type) {
|
|
|
|
return m_score_type = score_type;
|
2011-11-12 04:40:01 +04:00
|
|
|
}
|
2011-02-24 15:42:19 +03:00
|
|
|
|
|
|
|
void add(ScoreArray& e);
|
2012-12-06 20:39:22 +04:00
|
|
|
void add(const ScoreStats& e, int sent_idx);
|
2011-02-24 15:42:19 +03:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
std::size_t NumberOfScores() const {
|
|
|
|
return m_num_scores;
|
|
|
|
}
|
|
|
|
std::size_t size() const {
|
|
|
|
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;
|
2012-03-10 14:27:52 +04:00
|
|
|
|
2011-02-24 15:42:19 +03:00
|
|
|
void setIndex();
|
|
|
|
|
2012-12-06 20:39:22 +04:00
|
|
|
inline int getIndex(const int 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;
|
|
|
|
}
|
2012-03-10 14:27:52 +04:00
|
|
|
|
2012-12-06 20:39:22 +04:00
|
|
|
inline int getName(std::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())
|
2012-05-10 02:51:05 +04:00
|
|
|
throw std::runtime_error("there is no entry at index " + idx);
|
2011-02-24 15:42:19 +03:00
|
|
|
return i->second;
|
2008-05-27 20:50:52 +04:00
|
|
|
}
|
2008-05-14 12:14:13 +04:00
|
|
|
};
|
|
|
|
|
2012-06-30 23:23:45 +04:00
|
|
|
}
|
|
|
|
|
2012-02-20 04:46:08 +04:00
|
|
|
#endif // MERT_SCORE_DATA_H_
|