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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#include "comb_scorer.h"
#include <cstdio>
using namespace std;
class BLEUTERCombinationScore : public Score {
friend class BLEUTERCombinationScorer;
public:
~BLEUTERCombinationScore();
float ComputeScore() const {
return (bleu->ComputeScore() - ter->ComputeScore()) / 2.0f;
}
void ScoreDetails(string* details) const {
char buf[160];
sprintf(buf, "Combi = %.2f, BLEU = %.2f, TER = %.2f",
ComputeScore()*100.0f, bleu->ComputeScore()*100.0f, ter->ComputeScore()*100.0f);
*details = buf;
}
void PlusEquals(const Score& delta) {
bleu->PlusEquals(*static_cast<const BLEUTERCombinationScore&>(delta).bleu);
ter->PlusEquals(*static_cast<const BLEUTERCombinationScore&>(delta).ter);
}
Score* GetZero() const {
BLEUTERCombinationScore* res = new BLEUTERCombinationScore;
res->bleu = bleu->GetZero();
res->ter = ter->GetZero();
return res;
}
void Subtract(const Score& rhs, Score* res) const {
bleu->Subtract(*static_cast<const BLEUTERCombinationScore&>(rhs).bleu,
static_cast<BLEUTERCombinationScore*>(res)->bleu);
ter->Subtract(*static_cast<const BLEUTERCombinationScore&>(rhs).ter,
static_cast<BLEUTERCombinationScore*>(res)->ter);
}
void Encode(std::string* out) const {
string bs, ts;
bleu->Encode(&bs);
ter->Encode(&ts);
out->clear();
(*out) += static_cast<char>(bs.size());
(*out) += bs;
(*out) += ts;
}
bool IsAdditiveIdentity() const {
return bleu->IsAdditiveIdentity() && ter->IsAdditiveIdentity();
}
private:
Score* bleu;
Score* ter;
};
BLEUTERCombinationScore::~BLEUTERCombinationScore() {
delete bleu;
delete ter;
}
BLEUTERCombinationScorer::BLEUTERCombinationScorer(const vector<vector<WordID> >& refs) {
bleu_ = SentenceScorer::CreateSentenceScorer(IBM_BLEU, refs);
ter_ = SentenceScorer::CreateSentenceScorer(TER, refs);
}
BLEUTERCombinationScorer::~BLEUTERCombinationScorer() {
delete bleu_;
delete ter_;
}
Score* BLEUTERCombinationScorer::ScoreCandidate(const std::vector<WordID>& hyp) const {
BLEUTERCombinationScore* res = new BLEUTERCombinationScore;
res->bleu = bleu_->ScoreCandidate(hyp);
res->ter = ter_->ScoreCandidate(hyp);
return res;
}
Score* BLEUTERCombinationScorer::ScoreFromString(const std::string& in) {
int bss = in[0];
BLEUTERCombinationScore* r = new BLEUTERCombinationScore;
r->bleu = SentenceScorer::CreateScoreFromString(IBM_BLEU, in.substr(1, bss));
r->ter = SentenceScorer::CreateScoreFromString(TER, in.substr(1 + bss));
return r;
}
|