00001 #pragma once
00002
00003 #include <string>
00004 #include <limits>
00005 #include <set>
00006 #include <boost/unordered_map.hpp>
00007 #include "StatelessFeatureFunction.h"
00008 #include "moses/Factor.h"
00009
00010 #ifdef WITH_THREADS
00011 #include <boost/thread/shared_mutex.hpp>
00012 #endif
00013
00014 namespace Moses
00015 {
00016
00017 class Model1Vocabulary
00018 {
00019 public:
00020
00021 #define INVALID_ID std::numeric_limits<unsigned>::max() // UINT_MAX
00022 static const std::string GIZANULL;
00023
00024 Model1Vocabulary();
00025 bool Store(const Factor* word, const unsigned id);
00026 unsigned StoreIfNew(const Factor* word);
00027 unsigned GetWordID(const Factor* word) const;
00028 const Factor* GetWord(unsigned id) const;
00029 void Load(const std::string& fileName);
00030
00031 protected:
00032 boost::unordered_map<const Factor*, unsigned> m_lookup;
00033 std::vector< const Factor* > m_vocab;
00034 const Factor* m_NULL;
00035 };
00036
00037
00038 class Model1LexicalTable
00039 {
00040 public:
00041 Model1LexicalTable(float floor=1e-7) : m_floor(floor)
00042 {}
00043
00044 void Load(const std::string& fileName, const Model1Vocabulary& vcbS, const Model1Vocabulary& vcbT);
00045
00046
00047 float GetProbability(const Factor* wordS, const Factor* wordT) const;
00048
00049 protected:
00050 boost::unordered_map< const Factor*, boost::unordered_map< const Factor*, float > > m_ltable;
00051 const float m_floor;
00052 };
00053
00054
00055
00056 class Model1Feature : public StatelessFeatureFunction
00057 {
00058 public:
00059 Model1Feature(const std::string &line);
00060
00061 bool IsUseable(const FactorMask &mask) const {
00062 return true;
00063 }
00064
00065 void SetParameter(const std::string& key, const std::string& value);
00066
00067 void EvaluateInIsolation(const Phrase &source
00068 , const TargetPhrase &targetPhrase
00069 , ScoreComponentCollection &scoreBreakdown
00070 , ScoreComponentCollection &estimatedScores) const
00071 {};
00072
00073 void EvaluateWithSourceContext(const InputType &input
00074 , const InputPath &inputPath
00075 , const TargetPhrase &targetPhrase
00076 , const StackVec *stackVec
00077 , ScoreComponentCollection &scoreBreakdown
00078 , ScoreComponentCollection *estimatedScores = NULL) const;
00079
00080 void EvaluateTranslationOptionListWithSourceContext(const InputType &input
00081 , const TranslationOptionList &translationOptionList) const
00082 {}
00083
00084 void EvaluateWhenApplied(
00085 const Hypothesis& cur_hypo,
00086 ScoreComponentCollection* accumulator) const
00087 {}
00088
00089 void EvaluateWhenApplied(
00090 const ChartHypothesis& cur_hypo,
00091 ScoreComponentCollection* accumulator) const
00092 {}
00093
00094 void CleanUpAfterSentenceProcessing(const InputType& source);
00095
00096 private:
00097 std::string m_fileNameVcbS;
00098 std::string m_fileNameVcbT;
00099 std::string m_fileNameModel1;
00100 Model1LexicalTable m_model1;
00101 const Factor* m_emptyWord;
00102 bool m_skipTargetPunctuation;
00103 std::set<const Factor*> m_punctuation;
00104 bool m_is_syntax;
00105
00106 void Load(AllOptions::ptr const& opts);
00107
00108
00109 mutable boost::unordered_map<const InputType*, boost::unordered_map<const Factor*, float> > m_cache;
00110 #ifdef WITH_THREADS
00111
00112 mutable boost::shared_mutex m_accessLock;
00113 #endif
00114 };
00115
00116
00117 }
00118