00001 #pragma once 00002 00003 #include <string> 00004 00005 #include <boost/unordered_set.hpp> 00006 00007 #include <util/string_piece.hh> 00008 00009 #include "moses/Factor.h" 00010 #include "moses/Sentence.h" 00011 00012 #include "StatelessFeatureFunction.h" 00013 00014 namespace Moses 00015 { 00016 00017 class SparseHieroReorderingFeature : public StatelessFeatureFunction 00018 { 00019 public: 00020 enum Type { 00021 SourceCombined, 00022 SourceLeft, 00023 SourceRight 00024 }; 00025 00026 SparseHieroReorderingFeature(const std::string &line); 00027 00028 bool IsUseable(const FactorMask &mask) const { 00029 return true; 00030 } 00031 00032 void SetParameter(const std::string& key, const std::string& value); 00033 00034 void EvaluateInIsolation(const Phrase &source 00035 , const TargetPhrase &targetPhrase 00036 , ScoreComponentCollection &scoreBreakdown 00037 , ScoreComponentCollection &estimatedScores) const { 00038 } 00039 virtual void EvaluateWithSourceContext(const InputType &input 00040 , const InputPath &inputPath 00041 , const TargetPhrase &targetPhrase 00042 , const StackVec *stackVec 00043 , ScoreComponentCollection &scoreBreakdown 00044 , ScoreComponentCollection *estimatedScores = NULL) const { 00045 } 00046 00047 void EvaluateTranslationOptionListWithSourceContext(const InputType &input 00048 , const TranslationOptionList &translationOptionList) const { 00049 } 00050 00051 virtual void EvaluateWhenApplied(const Hypothesis& hypo, 00052 ScoreComponentCollection* accumulator) const { 00053 } 00054 void EvaluateWhenApplied(const ChartHypothesis &hypo, 00055 ScoreComponentCollection* accumulator) const; 00056 00057 00058 private: 00059 00060 typedef boost::unordered_set<const Factor*> Vocab; 00061 00062 void AddNonTerminalPairFeatures( 00063 const Sentence& sentence, const Range& nt1, const Range& nt2, 00064 bool isMonotone, ScoreComponentCollection* accumulator) const; 00065 00066 void LoadVocabulary(const std::string& filename, Vocab& vocab); 00067 const Factor* GetFactor(const Word& word, const Vocab& vocab, FactorType factor) const; 00068 00069 Type m_type; 00070 FactorType m_sourceFactor; 00071 FactorType m_targetFactor; 00072 std::string m_sourceVocabFile; 00073 std::string m_targetVocabFile; 00074 00075 const Factor* m_otherFactor; 00076 00077 Vocab m_sourceVocab; 00078 Vocab m_targetVocab; 00079 00080 }; 00081 00082 00083 } 00084