summaryrefslogtreecommitdiff
path: root/vest/comb_scorer.cc
blob: 3dd077a6d7b65d23bdef1c18eef9d525ebe53f67 (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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "comb_scorer.h"

#include <cstdio>

using namespace std;

class BLEUTERCombinationScore : public Score {
  friend class BLEUTERCombinationScorer;
 public:
  ~BLEUTERCombinationScore();
  float ComputePartialScore() const { return 0.0;}
  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 PlusPartialEquals(const Score& rhs, int oracle_e_cover, int oracle_f_cover, int src_len){}

  void PlusEquals(const Score& delta, const float scale) {
    bleu->PlusEquals(*static_cast<const BLEUTERCombinationScore&>(delta).bleu, scale);
    ter->PlusEquals(*static_cast<const BLEUTERCombinationScore&>(delta).ter, scale);
  }
  void PlusEquals(const Score& delta) {
    bleu->PlusEquals(*static_cast<const BLEUTERCombinationScore&>(delta).bleu);
    ter->PlusEquals(*static_cast<const BLEUTERCombinationScore&>(delta).ter);
  }



  Score* GetOne() const {
    BLEUTERCombinationScore* res = new BLEUTERCombinationScore;
    res->bleu = bleu->GetOne();
    res->ter = ter->GetOne();
    return res;    
  }
  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::ScoreCCandidate(const vector<WordID>& hyp) const {
  Score* a = NULL;
  return a;
}

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;
}