blob: b7a72d85311d8ea93decb8297511b0d8811c4e9b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#ifndef moses_LanguageModelRemote_h
#define moses_LanguageModelRemote_h
#include "SingleFactor.h"
#include "moses/TypeDef.h"
#include "moses/Factor.h"
#include <sys/types.h>
#if defined(_WIN32) || defined(_WIN64)
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#endif
namespace Moses
{
/** @todo ask miles
*/
class LanguageModelRemote : public LanguageModelSingleFactor
{
private:
struct Cache {
std::map<const Factor*, Cache> tree;
float prob;
State boState;
Cache() : prob(0) {}
};
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;
}
virtual LMResult GetValue(const std::vector<const Word*> &contextFactor, State* finalState = 0) const;
bool Load(const std::string &filePath
, FactorType factorType
, size_t nGramOrder);
};
}
#endif
|