#include "comb_scorer.h" #include using namespace std; class BLEUTERCombinationScore : public ScoreBase { 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(delta).bleu, scale); ter->PlusEquals(*static_cast(delta).ter, scale); } void PlusEquals(const Score& delta) { bleu->PlusEquals(*static_cast(delta).bleu); ter->PlusEquals(*static_cast(delta).ter); } ScoreP GetOne() const { BLEUTERCombinationScore* res = new BLEUTERCombinationScore; res->bleu = bleu->GetOne(); res->ter = ter->GetOne(); return ScoreP(res); } ScoreP GetZero() const { BLEUTERCombinationScore* res = new BLEUTERCombinationScore; res->bleu = bleu->GetZero(); res->ter = ter->GetZero(); return ScoreP(res); } void Subtract(const Score& rhs, Score* res) const { bleu->Subtract(*static_cast(rhs).bleu, static_cast(res)->bleu.get()); ter->Subtract(*static_cast(rhs).ter, static_cast(res)->ter.get()); } void Encode(std::string* out) const { string bs, ts; bleu->Encode(&bs); ter->Encode(&ts); out->clear(); (*out) += static_cast(bs.size()); (*out) += bs; (*out) += ts; } bool IsAdditiveIdentity() const { return bleu->IsAdditiveIdentity() && ter->IsAdditiveIdentity(); } private: ScoreP bleu; ScoreP ter; }; BLEUTERCombinationScore::~BLEUTERCombinationScore() { } BLEUTERCombinationScorer::BLEUTERCombinationScorer(const vector >& refs) { bleu_ = SentenceScorer::CreateSentenceScorer(IBM_BLEU, refs); ter_ = SentenceScorer::CreateSentenceScorer(TER, refs); } BLEUTERCombinationScorer::~BLEUTERCombinationScorer() { } ScoreP BLEUTERCombinationScorer::ScoreCCandidate(const vector& hyp) const { return ScoreP(); } ScoreP BLEUTERCombinationScorer::ScoreCandidate(const std::vector& hyp) const { BLEUTERCombinationScore* res = new BLEUTERCombinationScore; res->bleu = bleu_->ScoreCandidate(hyp); res->ter = ter_->ScoreCandidate(hyp); return ScoreP(res); } ScoreP 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 ScoreP(r); } class BLEUCBLEUCombinationScore : public ScoreBase { friend class BLEUCBLEUCombinationScorer; public: ~BLEUCBLEUCombinationScore(); float ComputePartialScore() const { return 0.0;} float ComputeScore() const { return (bleu->ComputeScore() + cbleu->ComputeScore()) / 2.0f; } void ScoreDetails(string* details) const { char buf[160]; sprintf(buf, "Combi = %.2f, BLEU = %.2f, CBLEU = %.2f", ComputeScore()*100.0f, bleu->ComputeScore()*100.0f, cbleu->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(delta).bleu, scale); cbleu->PlusEquals(*static_cast(delta).cbleu, scale); } void PlusEquals(const Score& delta) { bleu->PlusEquals(*static_cast(delta).bleu); cbleu->PlusEquals(*static_cast(delta).cbleu); } ScoreP GetOne() const { BLEUCBLEUCombinationScore* res = new BLEUCBLEUCombinationScore; res->bleu = bleu->GetOne(); res->cbleu = cbleu->GetOne(); return ScoreP(res); } ScoreP GetZero() const { BLEUCBLEUCombinationScore* res = new BLEUCBLEUCombinationScore; res->bleu = bleu->GetZero(); res->cbleu = cbleu->GetZero(); return ScoreP(res); } void Subtract(const Score& rhs, Score* res) const { bleu->Subtract(*static_cast(rhs).bleu, static_cast(res)->bleu.get()); cbleu->Subtract(*static_cast(rhs).cbleu, static_cast(res)->cbleu.get()); } void Encode(std::string* out) const { string bs, ts; bleu->Encode(&bs); cbleu->Encode(&ts); out->clear(); (*out) += static_cast(bs.size()); (*out) += bs; (*out) += ts; } bool IsAdditiveIdentity() const { return bleu->IsAdditiveIdentity() && cbleu->IsAdditiveIdentity(); } private: ScoreP bleu; ScoreP cbleu; }; BLEUCBLEUCombinationScore::~BLEUCBLEUCombinationScore() { } BLEUCBLEUCombinationScorer::BLEUCBLEUCombinationScorer(const vector >& refs) { bleu_ = SentenceScorer::CreateSentenceScorer(IBM_BLEU, refs); cbleu_ = SentenceScorer::CreateSentenceScorer(CBLEU, refs); } BLEUCBLEUCombinationScorer::~BLEUCBLEUCombinationScorer() { } ScoreP BLEUCBLEUCombinationScorer::ScoreCCandidate(const vector& hyp) const { return ScoreP(); } ScoreP BLEUCBLEUCombinationScorer::ScoreCandidate(const std::vector& hyp) const { BLEUCBLEUCombinationScore* res = new BLEUCBLEUCombinationScore; res->bleu = bleu_->ScoreCandidate(hyp); res->cbleu = cbleu_->ScoreCandidate(hyp); return ScoreP(res); } ScoreP BLEUCBLEUCombinationScorer::ScoreFromString(const std::string& in) { int bss = in[0]; BLEUCBLEUCombinationScore* r = new BLEUCBLEUCombinationScore; r->bleu = SentenceScorer::CreateScoreFromString(IBM_BLEU, in.substr(1, bss)); r->cbleu = SentenceScorer::CreateScoreFromString(CBLEU, in.substr(1 + bss)); return ScoreP(r); }