mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 05:55:02 +03:00
47ac8a474d
This change might be useful to avoid duplicating the names. The reason is that although MERT programs are standalone applications, some header files such as data.h and point.h have common guard macro names like "DATA_H" and "POINT_H", and this is not good naming conventions when you want to include external headers. Some files actually include headers in Moses and KenLM's util.
111 lines
2.3 KiB
C++
111 lines
2.3 KiB
C++
/*
|
|
* FeatureArray.h
|
|
* mert - Minimum Error Rate Training
|
|
*
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
*
|
|
*/
|
|
|
|
#ifndef MERT_FEATURE_ARRAY_H_
|
|
#define MERT_FEATURE_ARRAY_H_
|
|
|
|
#include <vector>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include "FeatureStats.h"
|
|
|
|
using namespace std;
|
|
|
|
const char FEATURES_TXT_BEGIN[] = "FEATURES_TXT_BEGIN_0";
|
|
const char FEATURES_TXT_END[] = "FEATURES_TXT_END_0";
|
|
const char FEATURES_BIN_BEGIN[] = "FEATURES_BIN_BEGIN_0";
|
|
const char FEATURES_BIN_END[] = "FEATURES_BIN_END_0";
|
|
|
|
class FeatureArray
|
|
{
|
|
private:
|
|
// idx to identify the utterance. It can differ from
|
|
// the index inside the vector.
|
|
std::string idx;
|
|
|
|
protected:
|
|
featarray_t array_;
|
|
size_t number_of_features;
|
|
std::string features;
|
|
bool _sparse_flag;
|
|
|
|
public:
|
|
FeatureArray();
|
|
~FeatureArray();
|
|
|
|
inline void clear() {
|
|
array_.clear();
|
|
}
|
|
|
|
inline bool hasSparseFeatures() const {
|
|
return _sparse_flag;
|
|
}
|
|
|
|
inline std::string getIndex() const {
|
|
return idx;
|
|
}
|
|
inline void setIndex(const std::string& value) {
|
|
idx = value;
|
|
}
|
|
|
|
inline FeatureStats& get(size_t i) {
|
|
return array_.at(i);
|
|
}
|
|
inline const FeatureStats& get(size_t i)const {
|
|
return array_.at(i);
|
|
}
|
|
void add(FeatureStats& e) {
|
|
array_.push_back(e);
|
|
}
|
|
|
|
//ADDED BY TS
|
|
void swap(size_t i, size_t j) {
|
|
std::swap(array_[i],array_[j]);
|
|
}
|
|
|
|
void resize(size_t new_size) {
|
|
array_.resize(std::min(new_size,array_.size()));
|
|
}
|
|
//END_ADDED
|
|
|
|
void merge(FeatureArray& e);
|
|
|
|
inline size_t size() const {
|
|
return array_.size();
|
|
}
|
|
inline size_t NumberOfFeatures() const {
|
|
return number_of_features;
|
|
}
|
|
inline void NumberOfFeatures(size_t v) {
|
|
number_of_features = v;
|
|
}
|
|
inline std::string Features() const {
|
|
return features;
|
|
}
|
|
inline void Features(const std::string& f) {
|
|
features = f;
|
|
}
|
|
|
|
void savetxt(ofstream& outFile);
|
|
void savebin(ofstream& outFile);
|
|
void save(ofstream& outFile, bool bin=false);
|
|
void save(const std::string &file, bool bin=false);
|
|
inline void save(bool bin=false) {
|
|
save("/dev/stdout",bin);
|
|
}
|
|
|
|
void loadtxt(ifstream& inFile, size_t n);
|
|
void loadbin(ifstream& inFile, size_t n);
|
|
void load(ifstream& inFile);
|
|
void load(const std::string &file);
|
|
|
|
bool check_consistency() const;
|
|
};
|
|
|
|
#endif // MERT_FEATURE_ARRAY_H_
|