|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MERT_DATA_H_ |
|
#define MERT_DATA_H_ |
|
|
|
#include <vector> |
|
#include <boost/shared_ptr.hpp> |
|
|
|
#include "Util.h" |
|
#include "FeatureData.h" |
|
#include "ScoreData.h" |
|
|
|
namespace MosesTuning |
|
{ |
|
|
|
class Scorer; |
|
|
|
typedef boost::shared_ptr<ScoreData> ScoreDataHandle; |
|
typedef boost::shared_ptr<FeatureData> FeatureDataHandle; |
|
|
|
|
|
|
|
class Data |
|
{ |
|
private: |
|
Scorer* m_scorer; |
|
std::string m_score_type; |
|
std::size_t m_num_scores; |
|
ScoreDataHandle m_score_data; |
|
FeatureDataHandle m_feature_data; |
|
SparseVector m_sparse_weights; |
|
|
|
public: |
|
explicit Data(Scorer* scorer, const std::string& sparseweightsfile=""); |
|
|
|
void clear() { |
|
m_score_data->clear(); |
|
m_feature_data->clear(); |
|
} |
|
|
|
ScoreDataHandle getScoreData() { |
|
return m_score_data; |
|
} |
|
|
|
FeatureDataHandle getFeatureData() { |
|
return m_feature_data; |
|
} |
|
|
|
Scorer* getScorer() { |
|
return m_scorer; |
|
} |
|
|
|
std::size_t NumberOfFeatures() const { |
|
return m_feature_data->NumberOfFeatures(); |
|
} |
|
|
|
std::string Features() const { |
|
return m_feature_data->Features(); |
|
} |
|
void Features(const std::string &f) { |
|
m_feature_data->Features(f); |
|
} |
|
|
|
void loadNBest(const std::string &file, bool oneBest=false); |
|
|
|
void load(const std::string &featfile, const std::string &scorefile); |
|
|
|
void save(const std::string &featfile, const std::string &scorefile, bool bin=false); |
|
|
|
|
|
void removeDuplicates(); |
|
|
|
|
|
inline bool existsFeatureNames() const { |
|
return m_feature_data->existsFeatureNames(); |
|
} |
|
|
|
inline std::string getFeatureName(std::size_t idx) const { |
|
return m_feature_data->getFeatureName(idx); |
|
} |
|
|
|
inline std::size_t getFeatureIndex(const std::string& name) const { |
|
return m_feature_data->getFeatureIndex(name); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void createShards(std::size_t shard_count, float shard_size, const std::string& scorerconfig, |
|
std::vector<Data>& shards); |
|
|
|
|
|
void InitFeatureMap(const std::string& str); |
|
void AddFeatures(const std::string& str, |
|
int sentence_index); |
|
}; |
|
|
|
} |
|
|
|
#endif |
|
|