00001 #ifndef moses_TargetBigramFeature_h 00002 #define moses_TargetBigramFeature_h 00003 00004 #include <string> 00005 #include <map> 00006 #include <boost/unordered_set.hpp> 00007 00008 #include "moses/FF/FFState.h" 00009 #include "StatefulFeatureFunction.h" 00010 #include "moses/FactorCollection.h" 00011 #include "moses/Word.h" 00012 00013 namespace Moses 00014 { 00015 00016 class TargetBigramState : public FFState 00017 { 00018 public: 00019 TargetBigramState(const Word& word): m_word(word) {} 00020 const Word& GetWord() const { 00021 return m_word; 00022 } 00023 size_t hash() const; 00024 virtual bool operator==(const FFState& other) const; 00025 00026 private: 00027 Word m_word; 00028 }; 00029 00032 class TargetBigramFeature : public StatefulFeatureFunction 00033 { 00034 public: 00035 TargetBigramFeature(const std::string &line); 00036 00037 void Load(AllOptions::ptr const& opts); 00038 00039 bool IsUseable(const FactorMask &mask) const; 00040 00041 virtual const FFState* EmptyHypothesisState(const InputType &input) const; 00042 00043 virtual FFState* EvaluateWhenApplied(const Hypothesis& cur_hypo, const FFState* prev_state, 00044 ScoreComponentCollection* accumulator) const; 00045 00046 virtual FFState* EvaluateWhenApplied( const ChartHypothesis& /* cur_hypo */, 00047 int /* featureID */, 00048 ScoreComponentCollection* ) const { 00049 throw std::logic_error("TargetBigramFeature not valid in chart decoder"); 00050 } 00051 00052 void SetParameter(const std::string& key, const std::string& value); 00053 00054 private: 00055 FactorType m_factorType; 00056 Word m_bos; 00057 std::string m_filePath; 00058 boost::unordered_set<std::string> m_vocab; 00059 }; 00060 00061 } 00062 00063 #endif // moses_TargetBigramFeature_h