2010-02-24 14:15:44 +03:00
|
|
|
#ifndef moses_LanguageModelRemote_h
|
|
|
|
#define moses_LanguageModelRemote_h
|
2009-01-23 00:31:17 +03:00
|
|
|
|
2012-11-12 23:56:18 +04:00
|
|
|
#include "SingleFactor.h"
|
|
|
|
#include "moses/TypeDef.h"
|
|
|
|
#include "moses/Factor.h"
|
2009-01-23 00:31:17 +03:00
|
|
|
#include <sys/types.h>
|
2015-04-17 20:59:40 +03:00
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
|
|
|
#include <winsock2.h>
|
|
|
|
#else
|
|
|
|
#include <sys/socket.h>
|
2009-01-23 00:31:17 +03:00
|
|
|
#include <netinet/in.h>
|
2015-04-17 20:59:40 +03:00
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
2009-01-23 00:31:17 +03:00
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
2012-06-29 02:29:46 +04:00
|
|
|
/** @todo ask miles
|
|
|
|
*/
|
2013-02-21 02:09:00 +04:00
|
|
|
class LanguageModelRemote : public LanguageModelSingleFactor
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
struct Cache {
|
|
|
|
std::map<const Factor*, Cache> tree;
|
|
|
|
float prob;
|
|
|
|
State boState;
|
|
|
|
Cache() : prob(0) {}
|
|
|
|
};
|
2009-01-23 00:31:17 +03:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
int sock, port;
|
|
|
|
struct hostent *hp;
|
|
|
|
struct sockaddr_in server;
|
|
|
|
mutable size_t m_curId;
|
|
|
|
mutable Cache m_cache;
|
|
|
|
bool start(const std::string& host, int port);
|
|
|
|
static const Factor* BOS;
|
|
|
|
static const Factor* EOS;
|
|
|
|
public:
|
|
|
|
~LanguageModelRemote();
|
|
|
|
void ClearSentenceCache() {
|
|
|
|
m_cache.tree.clear();
|
|
|
|
m_curId = 1000;
|
|
|
|
}
|
2011-03-08 02:21:09 +03:00
|
|
|
virtual LMResult GetValue(const std::vector<const Word*> &contextFactor, State* finalState = 0) const;
|
2011-02-24 16:14:42 +03:00
|
|
|
bool Load(const std::string &filePath
|
|
|
|
, FactorType factorType
|
|
|
|
, size_t nGramOrder);
|
2009-01-23 00:31:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|