blob: 9565d5af9455cf959fe908ebd7c4bbd0ea41d1ed (
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
|
#ifndef EXTERNAL_SCORER_H_
#define EXTERNAL_SCORER_H_
#include <vector>
#include <string>
#include <map>
#include <boost/shared_ptr.hpp>
#include "scorer.h"
class ScoreServer {
friend class ScoreServerManager;
protected:
explicit ScoreServer(const std::string& cmd);
virtual ~ScoreServer();
public:
float ComputeScore(const std::vector<float>& fields);
void Evaluate(const std::vector<std::vector<WordID> >& refs, const std::vector<WordID>& hyp, std::vector<float>* fields);
private:
void RequestResponse(const std::string& request, std::string* response);
int p2c[2];
int c2p[2];
};
class ScoreServerManager {
public:
static ScoreServer* Instance(const std::string& score_type);
private:
static std::map<std::string, boost::shared_ptr<ScoreServer> > servers_;
};
class ExternalSentenceScorer : public SentenceScorer {
public:
ExternalSentenceScorer(ScoreServer* server, const std::vector<std::vector<WordID> >& r) :
SentenceScorer("External", r), eval_server(server) {}
virtual ScoreP ScoreCandidate(const Sentence& hyp) const;
virtual ScoreP ScoreCCandidate(const Sentence& hyp) const;
static ScoreP ScoreFromString(ScoreServer* s, const std::string& data);
protected:
ScoreServer* eval_server;
};
#endif
|