00001 #ifndef GLOBALLEXICALMODELUNLIMITED_H_
00002 #define GLOBALLEXICALMODELUNLIMITED_H_
00003
00004 #include <stdexcept>
00005 #include <string>
00006 #include <vector>
00007 #include <boost/unordered_set.hpp>
00008 #include <boost/unordered_map.hpp>
00009
00010 #include "StatelessFeatureFunction.h"
00011 #include "moses/Factor.h"
00012 #include "moses/Phrase.h"
00013 #include "moses/TypeDef.h"
00014 #include "moses/Util.h"
00015 #include "moses/Range.h"
00016 #include "moses/FactorTypeSet.h"
00017 #include "moses/Sentence.h"
00018
00019 #ifdef WITH_THREADS
00020 #include <boost/thread/tss.hpp>
00021 #endif
00022
00023 namespace Moses
00024 {
00025
00026 class Factor;
00027 class Phrase;
00028 class Hypothesis;
00029 class InputType;
00030
00037 class GlobalLexicalModelUnlimited : public StatelessFeatureFunction
00038 {
00039 typedef std::map< char, short > CharHash;
00040 typedef std::map< std::string, short > StringHash;
00041
00042 struct ThreadLocalStorage {
00043
00044 const Sentence *input;
00045 };
00046
00047 private:
00048 #ifdef WITH_THREADS
00049 boost::thread_specific_ptr<ThreadLocalStorage> m_local;
00050 #else
00051 std::auto_ptr<ThreadLocalStorage> m_local;
00052 #endif
00053
00054 CharHash m_punctuationHash;
00055
00056 std::vector< FactorType > m_inputFactors;
00057 std::vector< FactorType > m_outputFactors;
00058 bool m_unrestricted;
00059
00060 bool m_sourceContext;
00061 bool m_biphrase;
00062 bool m_bitrigger;
00063
00064 bool m_biasFeature;
00065 bool m_ignorePunctuation;
00066
00067 boost::unordered_set<std::string> m_vocabSource;
00068 boost::unordered_set<std::string> m_vocabTarget;
00069
00070 public:
00071 GlobalLexicalModelUnlimited(const std::string &line);
00072
00073 bool Load(const std::string &filePathSource, const std::string &filePathTarget);
00074
00075 void InitializeForInput(ttasksptr const& ttask);
00076
00077
00078
00079 void EvaluateWhenApplied(const Hypothesis& cur_hypo,
00080 ScoreComponentCollection* accumulator) const;
00081
00082 void EvaluateWhenApplied(const ChartHypothesis& ,
00083 int ,
00084 ScoreComponentCollection* ) const {
00085 throw std::logic_error("GlobalLexicalModelUnlimited not supported in chart decoder, yet");
00086 }
00087
00088 void EvaluateWithSourceContext(const InputType &input
00089 , const InputPath &inputPath
00090 , const TargetPhrase &targetPhrase
00091 , const StackVec *stackVec
00092 , ScoreComponentCollection &scoreBreakdown
00093 , ScoreComponentCollection *estimatedScores = NULL) const {
00094 }
00095
00096 void EvaluateTranslationOptionListWithSourceContext(const InputType &input
00097 , const TranslationOptionList &translationOptionList) const {
00098 }
00099
00100 void EvaluateInIsolation(const Phrase &source
00101 , const TargetPhrase &targetPhrase
00102 , ScoreComponentCollection &scoreBreakdown
00103 , ScoreComponentCollection &estimatedScores) const {
00104 }
00105
00106 void AddFeature(ScoreComponentCollection* accumulator,
00107 StringPiece sourceTrigger, StringPiece sourceWord, StringPiece targetTrigger,
00108 StringPiece targetWord) const;
00109 };
00110
00111 }
00112 #endif