00001 // -*- mode: c++; indent-tabs-mode: nil; tab-width:2 -*- 00002 #pragma once 00003 00004 #include <string> 00005 #include <vector> 00006 #include <boost/scoped_ptr.hpp> 00007 #include "moses/Factor.h" 00008 #include "moses/Phrase.h" 00009 #include "moses/TypeDef.h" 00010 #include "moses/Util.h" 00011 #include "moses/Range.h" 00012 #include "moses/TranslationOption.h" 00013 00014 #include "moses/FF/StatefulFeatureFunction.h" 00015 #include "util/exception.hh" 00016 00017 #include "LRState.h" 00018 #include "LexicalReorderingTable.h" 00019 #include "SparseReordering.h" 00020 00021 00022 namespace Moses 00023 { 00024 class Factor; 00025 class Phrase; 00026 class Hypothesis; 00027 class InputType; 00028 00029 // implementation of lexical reordering (Tilman ...) for phrase-based 00030 // decoding 00031 class LexicalReordering : public StatefulFeatureFunction 00032 { 00033 public: 00034 LexicalReordering(const std::string &line); 00035 virtual ~LexicalReordering(); 00036 void Load(AllOptions::ptr const& opts); 00037 00038 virtual 00039 bool 00040 IsUseable(const FactorMask &mask) const; 00041 00042 virtual 00043 FFState const* 00044 EmptyHypothesisState(const InputType &input) const; 00045 00046 void 00047 InitializeForInput(ttasksptr const& ttask) { 00048 if (m_table) m_table->InitializeForInput(ttask); 00049 } 00050 00051 Scores 00052 GetProb(const Phrase& f, const Phrase& e) const; 00053 00054 virtual 00055 FFState* 00056 EvaluateWhenApplied(const Hypothesis& cur_hypo, 00057 const FFState* prev_state, 00058 ScoreComponentCollection* accumulator) const; 00059 00060 virtual 00061 FFState* 00062 EvaluateWhenApplied(const ChartHypothesis&, int featureID, 00063 ScoreComponentCollection*) const { 00064 UTIL_THROW2("LexicalReordering is not valid for chart decoder"); 00065 } 00066 00067 bool 00068 GetHaveDefaultScores() { 00069 return m_haveDefaultScores; 00070 } 00071 00072 float 00073 GetDefaultScore( size_t i ) { 00074 return m_defaultScores[i]; 00075 } 00076 00077 virtual 00078 void 00079 SetCache(TranslationOption& to) const; 00080 00081 virtual 00082 void 00083 SetCache(TranslationOptionList& tol) const; 00084 00085 private: 00086 bool DecodeCondition(std::string s); 00087 bool DecodeDirection(std::string s); 00088 bool DecodeNumFeatureFunctions(std::string s); 00089 00090 boost::scoped_ptr<LRModel> m_configuration; 00091 std::string m_modelTypeString; 00092 std::vector<std::string> m_modelType; 00093 boost::scoped_ptr<LexicalReorderingTable> m_table; 00094 std::vector<LRModel::Condition> m_condition; 00095 std::vector<FactorType> m_factorsE, m_factorsF; 00096 std::string m_filePath; 00097 bool m_haveDefaultScores; 00098 Scores m_defaultScores; 00099 public: 00100 LRModel const& GetModel() const; 00101 }; 00102 00103 } 00104 00105 00106