00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef MERT_SCORE_DATA_H_
00010 #define MERT_SCORE_DATA_H_
00011
00012 #include <iosfwd>
00013 #include <vector>
00014 #include <stdexcept>
00015 #include <string>
00016 #include <boost/lexical_cast.hpp>
00017 #include "ScoreArray.h"
00018 #include "ScoreStats.h"
00019
00020 namespace MosesTuning
00021 {
00022
00023
00024 class Scorer;
00025
00026 class ScoreData
00027 {
00028 private:
00029
00030 ScoreData() {}
00031
00032 scoredata_t m_array;
00033 idx2name m_index_to_array_name;
00034 name2idx m_array_name_to_index;
00035
00036 Scorer* m_scorer;
00037 std::string m_score_type;
00038 std::size_t m_num_scores;
00039
00040 public:
00041 ScoreData(Scorer* scorer);
00042 ~ScoreData() {}
00043
00044 void clear() {
00045 m_array.clear();
00046 }
00047
00048 inline ScoreArray& get(std::size_t idx) {
00049 return m_array.at(idx);
00050 }
00051
00052 inline const ScoreArray& get(std::size_t idx) const {
00053 return m_array.at(idx);
00054 }
00055
00056 inline bool exists(int sent_idx) const {
00057 return existsInternal(getIndex(sent_idx));
00058 }
00059
00060 inline bool existsInternal(int sent_idx) const {
00061 return (sent_idx > -1 && sent_idx < static_cast<int>(m_array.size())) ? true : false;
00062 }
00063
00064 inline ScoreStats& get(std::size_t i, std::size_t j) {
00065 return m_array.at(i).get(j);
00066 }
00067
00068 inline const ScoreStats& get(std::size_t i, std::size_t j) const {
00069 return m_array.at(i).get(j);
00070 }
00071
00072 std::string name() const {
00073 return m_score_type;
00074 }
00075
00076 std::string name(const std::string &score_type) {
00077 return m_score_type = score_type;
00078 }
00079
00080 void add(ScoreArray& e);
00081 void add(const ScoreStats& e, int sent_idx);
00082
00083 std::size_t NumberOfScores() const {
00084 return m_num_scores;
00085 }
00086 std::size_t size() const {
00087 return m_array.size();
00088 }
00089
00090 void save(const std::string &file, bool bin=false);
00091 void save(std::ostream* os, bool bin=false);
00092 void save(bool bin=false);
00093
00094 void load(std::istream* is);
00095 void load(const std::string &file);
00096
00097 bool check_consistency() const;
00098
00099 void setIndex();
00100
00101 inline int getIndex(const int idx) const {
00102 name2idx::const_iterator i = m_array_name_to_index.find(idx);
00103 if (i != m_array_name_to_index.end())
00104 return i->second;
00105 else
00106 return -1;
00107 }
00108
00109 inline int getName(std::size_t idx) const {
00110 idx2name::const_iterator i = m_index_to_array_name.find(idx);
00111 if (i != m_index_to_array_name.end())
00112 throw std::runtime_error("there is no entry at index " + boost::lexical_cast<std::string>(idx));
00113 return i->second;
00114 }
00115 };
00116
00117 }
00118
00119 #endif // MERT_SCORE_DATA_H_