mosesdecoder/mert/ScoreArray.h

114 lines
2.2 KiB
C
Raw Normal View History

/*
* ScoreArray.h
2012-02-20 03:29:53 +04:00
* mert - Minimum Error Rate Training
*
* Created by Nicola Bertoldi on 13/05/08.
*
*/
#ifndef MERT_SCORE_ARRAY_H_
#define MERT_SCORE_ARRAY_H_
#include <vector>
#include <iostream>
#include <string>
#include "ScoreStats.h"
namespace MosesTuning
{
const char SCORES_TXT_BEGIN[] = "SCORES_TXT_BEGIN_0";
const char SCORES_TXT_END[] = "SCORES_TXT_END_0";
const char SCORES_BIN_BEGIN[] = "SCORES_BIN_BEGIN_0";
const char SCORES_BIN_END[] = "SCORES_BIN_END_0";
class ScoreArray
{
2013-05-29 21:16:15 +04:00
private:
scorearray_t m_array;
std::string m_score_type;
std::size_t m_num_scores;
// indexx to identify the utterance.
// It can differ from the index inside the vector.
int m_index;
public:
ScoreArray();
~ScoreArray() {}
2013-05-29 21:16:15 +04:00
void clear() {
m_array.clear();
}
2013-05-29 21:16:15 +04:00
int getIndex() const {
return m_index;
}
2013-05-29 21:16:15 +04:00
void setIndex(int value) {
m_index = value;
}
2013-05-29 21:16:15 +04:00
ScoreStats& get(std::size_t i) {
return m_array.at(i);
}
2013-05-29 21:16:15 +04:00
const ScoreStats& get(std::size_t i) const {
return m_array.at(i);
}
2013-05-29 21:16:15 +04:00
void add(const ScoreStats& e) {
m_array.push_back(e);
}
2011-12-12 17:48:42 +04:00
//ADDED BY TS
void swap(std::size_t i, std::size_t j) {
std::swap(m_array[i], m_array[j]);
2011-12-12 17:48:42 +04:00
}
void resize(std::size_t new_size) {
m_array.resize(std::min(new_size, m_array.size()));
2011-12-12 17:48:42 +04:00
}
//END_ADDED
void merge(ScoreArray& e);
2013-05-29 21:16:15 +04:00
std::string name() const {
return m_score_type;
}
2013-05-29 21:16:15 +04:00
void name(std::string &score_type) {
m_score_type = score_type;
}
2013-05-29 21:16:15 +04:00
std::size_t size() const {
return m_array.size();
}
2013-05-29 21:16:15 +04:00
std::size_t NumberOfScores() const {
return m_num_scores;
}
2013-05-29 21:16:15 +04:00
void NumberOfScores(std::size_t v) {
m_num_scores = v;
}
void savetxt(std::ostream* os, const std::string& score_type);
void savebin(std::ostream* os, const std::string& score_type);
void save(std::ostream* os, const std::string& score_type, bool bin=false);
void save(const std::string &file, const std::string& score_type, bool bin=false);
void save(const std::string& score_type, bool bin=false);
void loadtxt(std::istream* is, std::size_t n);
void loadbin(std::istream* is, std::size_t n);
void load(std::istream* is);
void load(const std::string &file);
bool check_consistency() const;
};
}
#endif // MERT_SCORE_ARRAY_H_