summaryrefslogtreecommitdiff
path: root/mteval/wer.cc
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2016-04-12 10:59:34 +0200
committerPatrick Simianer <p@simianer.de>2016-04-12 10:59:34 +0200
commit833d84354b9c57068723e9d7a2e87a409eddd329 (patch)
tree8e9d55934ef666f1acd0bcb1317943ff80598e97 /mteval/wer.cc
parentd0613843f2ce5628aa6728f3672d59877ef85833 (diff)
parentee4f3c5581e43510d98de1274c6c1c2984c87faf (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'mteval/wer.cc')
-rw-r--r--mteval/wer.cc16
1 files changed, 10 insertions, 6 deletions
diff --git a/mteval/wer.cc b/mteval/wer.cc
index c806b3be..b8cfd3d8 100644
--- a/mteval/wer.cc
+++ b/mteval/wer.cc
@@ -31,16 +31,17 @@ class WERScore : public ScoreBase<WERScore> {
WERScore() : stats(0,kDUMMY_LAST_ENTRY) {}
float ComputePartialScore() const { return 0.0;}
float ComputeScore() const {
+ if (static_cast<float>(stats[kCHARCOUNT]) < 0.5)
+ return 0;
return static_cast<float>(stats[kEDITDISTANCE]) / static_cast<float>(stats[kCHARCOUNT]);
}
void ScoreDetails(string* details) const;
void PlusPartialEquals(const Score& rhs, int oracle_e_cover, int oracle_f_cover, int src_len){}
void PlusEquals(const Score& delta, const float scale) {
- if (scale==1)
- stats += static_cast<const WERScore&>(delta).stats;
- if (scale==-1)
- stats -= static_cast<const WERScore&>(delta).stats;
- throw std::runtime_error("WERScore::PlusEquals with scale != +-1");
+ const WERScore& delta_stats = static_cast<const WERScore&>(delta);
+ for (unsigned i = 0; i < kDUMMY_LAST_ENTRY; ++i) {
+ stats[i] += scale * static_cast<float>(delta_stats.stats[i]);
+ }
}
void PlusEquals(const Score& delta) {
stats += static_cast<const WERScore&>(delta).stats;
@@ -88,7 +89,7 @@ void WERScore::ScoreDetails(std::string* details) const {
}
WERScorer::~WERScorer() {}
-WERScorer::WERScorer(const vector<vector<WordID> >& refs) {}
+WERScorer::WERScorer(const vector<vector<WordID> >& refs) {this->refs = refs;}
ScoreP WERScorer::ScoreCCandidate(const vector<WordID>& hyp) const {
return ScoreP();
@@ -97,6 +98,9 @@ ScoreP WERScorer::ScoreCCandidate(const vector<WordID>& hyp) const {
float WERScorer::Calculate(const std::vector<WordID>& hyp, const Sentence& ref, int& edits, int& char_count) const {
edits = cdec::LevenshteinDistance(hyp, ref);
char_count = ref.size();
+ if (char_count == 0) {
+ return 0;
+ }
return static_cast<float>(edits) / static_cast<float>(char_count);
}