00001 #ifndef moses_LanguageModelRemote_h 00002 #define moses_LanguageModelRemote_h 00003 00004 #include "SingleFactor.h" 00005 #include "moses/TypeDef.h" 00006 #include "moses/Factor.h" 00007 #include <sys/types.h> 00008 00009 #if defined(_WIN32) || defined(_WIN64) 00010 #include <winsock2.h> 00011 #else 00012 #include <sys/socket.h> 00013 #include <netinet/in.h> 00014 #include <netdb.h> 00015 #endif 00016 00017 namespace Moses 00018 { 00019 00022 class LanguageModelRemote : public LanguageModelSingleFactor 00023 { 00024 private: 00025 struct Cache { 00026 std::map<const Factor*, Cache> tree; 00027 float prob; 00028 State boState; 00029 Cache() : prob(0) {} 00030 }; 00031 00032 int sock, port; 00033 struct hostent *hp; 00034 struct sockaddr_in server; 00035 mutable size_t m_curId; 00036 mutable Cache m_cache; 00037 bool start(const std::string& host, int port); 00038 static const Factor* BOS; 00039 static const Factor* EOS; 00040 public: 00041 ~LanguageModelRemote(); 00042 void ClearSentenceCache() { 00043 m_cache.tree.clear(); 00044 m_curId = 1000; 00045 } 00046 virtual LMResult GetValue(const std::vector<const Word*> &contextFactor, State* finalState = 0) const; 00047 bool Load(const std::string &filePath 00048 , FactorType factorType 00049 , size_t nGramOrder); 00050 }; 00051 00052 } 00053 #endif