00001 // $Id$ 00002 #pragma once 00003 00004 #include <vector> 00005 00006 #include "moses/LM/SingleFactor.h" 00007 00008 // lbl stuff 00009 #include "lbl/model.h" 00010 #include "lbl/query_cache.h" 00011 00012 #include "OxLMMapper.h" 00013 00014 namespace Moses 00015 { 00016 00017 template<class Model> 00018 class OxLM : public LanguageModelSingleFactor 00019 { 00020 public: 00021 OxLM(const std::string &line); 00022 00023 ~OxLM(); 00024 00025 void SetParameter(const std::string& key, const std::string& value); 00026 00027 void Load(AllOptions::ptr const& opts); 00028 00029 virtual LMResult GetValue( 00030 const std::vector<const Word*> &contextFactor, 00031 State* finalState = 0) const; 00032 00033 virtual void InitializeForInput(ttasksptr const& ttask); 00034 00035 virtual void CleanUpAfterSentenceProcessing(const InputType& source); 00036 00037 private: 00038 double GetScore(int word, const vector<int>& context) const; 00039 00040 void loadPersistentCache(const string& cache_file) const; 00041 00042 void savePersistentCache(const string& cache_file) const; 00043 00044 protected: 00045 Model model; 00046 boost::shared_ptr<OxLMMapper> mapper; 00047 00048 int kSTART; 00049 int kSTOP; 00050 int kUNKNOWN; 00051 00052 bool normalized; 00053 00054 bool posBackOff; 00055 FactorType posFactorType; 00056 00057 bool persistentCache; 00058 mutable boost::thread_specific_ptr<oxlm::QueryCache> cache; 00059 mutable int cacheHits, totalHits; 00060 }; 00061 00062 } // namespace Moses