00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef MERT_SCORE_ARRAY_H_
00010 #define MERT_SCORE_ARRAY_H_
00011
00012 #include <vector>
00013 #include <iostream>
00014 #include <string>
00015
00016 #include "ScoreStats.h"
00017
00018 namespace MosesTuning
00019 {
00020
00021 const char SCORES_TXT_BEGIN[] = "SCORES_TXT_BEGIN_0";
00022 const char SCORES_TXT_END[] = "SCORES_TXT_END_0";
00023 const char SCORES_BIN_BEGIN[] = "SCORES_BIN_BEGIN_0";
00024 const char SCORES_BIN_END[] = "SCORES_BIN_END_0";
00025
00026 class ScoreArray
00027 {
00028 private:
00029 scorearray_t m_array;
00030 std::string m_score_type;
00031 std::size_t m_num_scores;
00032
00033
00034
00035 int m_index;
00036
00037 public:
00038 ScoreArray();
00039 ~ScoreArray() {}
00040
00041 void clear() {
00042 m_array.clear();
00043 }
00044
00045 int getIndex() const {
00046 return m_index;
00047 }
00048
00049 void setIndex(int value) {
00050 m_index = value;
00051 }
00052
00053 ScoreStats& get(std::size_t i) {
00054 return m_array.at(i);
00055 }
00056
00057 const ScoreStats& get(std::size_t i) const {
00058 return m_array.at(i);
00059 }
00060
00061 void add(const ScoreStats& e) {
00062 m_array.push_back(e);
00063 }
00064
00065
00066 void swap(std::size_t i, std::size_t j) {
00067 std::swap(m_array[i], m_array[j]);
00068 }
00069
00070 void resize(std::size_t new_size) {
00071 m_array.resize(std::min(new_size, m_array.size()));
00072 }
00073
00074
00075 void merge(ScoreArray& e);
00076
00077 std::string name() const {
00078 return m_score_type;
00079 }
00080
00081 void name(std::string &score_type) {
00082 m_score_type = score_type;
00083 }
00084
00085 std::size_t size() const {
00086 return m_array.size();
00087 }
00088
00089 std::size_t NumberOfScores() const {
00090 return m_num_scores;
00091 }
00092
00093 void NumberOfScores(std::size_t v) {
00094 m_num_scores = v;
00095 }
00096
00097 void savetxt(std::ostream* os, const std::string& score_type);
00098 void savebin(std::ostream* os, const std::string& score_type);
00099 void save(std::ostream* os, const std::string& score_type, bool bin=false);
00100 void save(const std::string &file, const std::string& score_type, bool bin=false);
00101 void save(const std::string& score_type, bool bin=false);
00102
00103 void loadtxt(std::istream* is, std::size_t n);
00104 void loadbin(std::istream* is, std::size_t n);
00105 void load(std::istream* is);
00106 void load(const std::string &file);
00107
00108 bool check_consistency() const;
00109 };
00110
00111 }
00112
00113 #endif // MERT_SCORE_ARRAY_H_