00001 #pragma once 00002 00003 #include <string> 00004 #include <vector> 00005 #include "moses/Factor.h" 00006 #include "moses/Util.h" 00007 #include "SingleFactor.h" 00008 #include "moses/TranslationModel/DynSAInclude/onlineRLM.h" 00009 //#include "multiOnlineRLM.h" 00010 #include "moses/TranslationModel/DynSAInclude/FileHandler.h" 00011 #include "moses/TranslationModel/DynSAInclude/vocab.h" 00012 00013 namespace Moses 00014 { 00015 class Factor; 00016 class Phrase; 00017 00020 class LanguageModelORLM : public LanguageModelSingleFactor 00021 { 00022 public: 00023 typedef count_t T; // type for ORLM filter 00024 LanguageModelORLM(const std::string &line) 00025 :LanguageModelSingleFactor(line) 00026 ,m_lm(0) { 00027 } 00028 bool Load(const std::string &filePath, FactorType factorType, size_t nGramOrder); 00029 virtual LMResult GetValue(const std::vector<const Word*> &contextFactor, State* finalState = NULL) const; 00030 ~LanguageModelORLM() { 00031 //save LM with markings 00032 Utils::rtrim(m_filePath, ".gz"); 00033 FileHandler fout(m_filePath + ".marked.gz", std::ios::out|std::ios::binary, false); 00034 m_lm->save(&fout); 00035 fout.close(); 00036 delete m_lm; 00037 } 00038 void CleanUpAfterSentenceProcessing() { 00039 m_lm->clearCache(); // clear caches 00040 } 00041 00042 bool UpdateORLM(const std::vector<std::string>& ngram, const int value); 00043 protected: 00044 OnlineRLM<T>* m_lm; 00045 //MultiOnlineRLM<T>* m_lm; 00046 wordID_t m_oov_id; 00047 std::vector<wordID_t> lm_ids_vec_; 00048 void CreateFactors(); 00049 wordID_t GetLmID(const std::string &str) const; 00050 wordID_t GetLmID(const Factor *factor) const; 00051 }; 00052 } // end namespace 00053