00001
00002
00003
00004
00005
00006
00007
00008
00009 #pragma once
00010
00011 #include <vector>
00012 #include <string>
00013 #include <fstream>
00014
00015 #include "util/string_piece.hh"
00016 #include "../OutputFileStream.h"
00017
00018 enum ORIENTATION {MONO, SWAP, DRIGHT, DLEFT, OTHER, NOMONO};
00019
00020
00021
00022
00023 class ModelScore
00024 {
00025 private:
00026 std::vector<double> count_fe_prev;
00027 std::vector<double> count_fe_next;
00028 std::vector<double> count_f_prev;
00029 std::vector<double> count_f_next;
00030
00031 protected:
00032 virtual ORIENTATION getType(const StringPiece& s);
00033
00034 public:
00035 ModelScore();
00036 virtual ~ModelScore();
00037 void add_example(const StringPiece& previous, const StringPiece& next, float weight);
00038 void reset_fe();
00039 void reset_f();
00040 const std::vector<double>& get_scores_fe_prev() const;
00041 const std::vector<double>& get_scores_fe_next() const;
00042 const std::vector<double>& get_scores_f_prev() const;
00043 const std::vector<double>& get_scores_f_next() const;
00044
00045 static ModelScore* createModelScore(const std::string& modeltype);
00046 };
00047
00048 class ModelScoreMSLR : public ModelScore
00049 {
00050 protected:
00051 virtual ORIENTATION getType(const StringPiece& s);
00052 };
00053
00054 class ModelScoreLR : public ModelScore
00055 {
00056 protected:
00057 virtual ORIENTATION getType(const StringPiece& s);
00058 };
00059
00060 class ModelScoreMSD : public ModelScore
00061 {
00062 protected:
00063 virtual ORIENTATION getType(const StringPiece& s);
00064 };
00065
00066 class ModelScoreMonotonicity : public ModelScore
00067 {
00068 protected:
00069 virtual ORIENTATION getType(const StringPiece& s);
00070 };
00071
00072
00073 class Scorer
00074 {
00075 public:
00076 virtual ~Scorer() {}
00077 virtual void score(const std::vector<double>&, std::vector<double>&) const = 0;
00078 virtual void createSmoothing(const std::vector<double>&, double, std::vector<double>&) const = 0;
00079 virtual void createConstSmoothing(double, std::vector<double>&) const = 0;
00080 };
00081
00082 class ScorerMSLR : public Scorer
00083 {
00084 public:
00085 virtual void score(const std::vector<double>&, std::vector<double>&) const;
00086 virtual void createSmoothing(const std::vector<double>&, double, std::vector<double>&) const;
00087 virtual void createConstSmoothing(double, std::vector<double>&) const;
00088 };
00089
00090 class ScorerMSD : public Scorer
00091 {
00092 public:
00093 virtual void score(const std::vector<double>&, std::vector<double>&) const;
00094 virtual void createSmoothing(const std::vector<double>&, double, std::vector<double>&) const;
00095 virtual void createConstSmoothing(double, std::vector<double>&) const;
00096 };
00097
00098 class ScorerMonotonicity : public Scorer
00099 {
00100 public:
00101 virtual void score(const std::vector<double>&, std::vector<double>&) const;
00102 virtual void createSmoothing(const std::vector<double>&, double, std::vector<double>&) const;
00103 virtual void createConstSmoothing(double, std::vector<double>&) const;
00104 };
00105
00106 class ScorerLR : public Scorer
00107 {
00108 public:
00109 virtual void score(const std::vector<double>&, std::vector<double>&) const;
00110 virtual void createSmoothing(const std::vector<double>&, double, std::vector<double>&) const;
00111 virtual void createConstSmoothing(double, std::vector<double>&) const;
00112 };
00113
00114
00115
00116
00117
00118
00119 class Model
00120 {
00121 private:
00122 ModelScore* modelscore;
00123 Scorer* scorer;
00124
00125 std::string filename;
00126 Moses::OutputFileStream outputFile;
00127
00128 bool fe;
00129 bool previous;
00130 bool next;
00131
00132 std::vector<double> smoothing_prev;
00133 std::vector<double> smoothing_next;
00134
00135 static void split_config(const std::string& config, std::string& dir,
00136 std::string& lang, std::string& orient);
00137 public:
00138 Model(ModelScore* ms, Scorer* sc, const std::string& dir,
00139 const std::string& lang, const std::string& fn);
00140 ~Model();
00141 static Model* createModel(ModelScore*, const std::string&, const std::string&);
00142 void createSmoothing(double w);
00143 void createConstSmoothing(double w);
00144 void score_fe(const std::string& f, const std::string& e);
00145 void score_f(const std::string& f);
00146 void zipFile();
00147 };
00148