From 30fa97e404d773a6359c1063405cbcab2db20f6a Mon Sep 17 00:00:00 2001 From: Tetsuo Kiso Date: Wed, 1 Feb 2012 20:24:48 +0900 Subject: [PATCH] Move reference length type into a private member of BleuScorer. The reason is that the type is used as internal purpose. --- mert/BleuScorer.cpp | 14 +++++++------- mert/BleuScorer.h | 11 +++++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/mert/BleuScorer.cpp b/mert/BleuScorer.cpp index 68c1c1e26..73dead0ed 100644 --- a/mert/BleuScorer.cpp +++ b/mert/BleuScorer.cpp @@ -11,7 +11,7 @@ BleuScorer::BleuScorer(const string& config) : StatisticsBasedScorer("BLEU",config), kLENGTH(4), - _refLengthStrategy(BLEU_CLOSEST) { + m_ref_length_type(CLOSEST) { //configure regularisation static string KEY_REFLEN = "reflen"; static string REFLEN_AVERAGE = "average"; @@ -20,11 +20,11 @@ BleuScorer::BleuScorer(const string& config) string reflen = getConfig(KEY_REFLEN,REFLEN_CLOSEST); if (reflen == REFLEN_AVERAGE) { - _refLengthStrategy = BLEU_AVERAGE; + m_ref_length_type = AVERAGE; } else if (reflen == REFLEN_SHORTEST) { - _refLengthStrategy = BLEU_SHORTEST; + m_ref_length_type = SHORTEST; } else if (reflen == REFLEN_CLOSEST) { - _refLengthStrategy = BLEU_CLOSEST; + m_ref_length_type = CLOSEST; } else { throw runtime_error("Unknown reference length strategy: " + reflen); } @@ -133,18 +133,18 @@ void BleuScorer::prepareStats(size_t sid, const string& text, ScoreStats& entry) vector stats(kLENGTH*2);; size_t length = countNgrams(text,testcounts,kLENGTH); //dump_counts(testcounts); - if (_refLengthStrategy == BLEU_SHORTEST) { + if (m_ref_length_type == SHORTEST) { //cerr << reflengths.size() << " " << sid << endl; int shortest = *min_element(_reflengths[sid].begin(),_reflengths[sid].end()); stats.push_back(shortest); - } else if (_refLengthStrategy == BLEU_AVERAGE) { + } else if (m_ref_length_type == AVERAGE) { int total = 0; for (size_t i = 0; i < _reflengths[sid].size(); ++i) { total += _reflengths[sid][i]; } const float mean = static_cast(total) /_reflengths[sid].size(); stats.push_back(mean); - } else if (_refLengthStrategy == BLEU_CLOSEST) { + } else if (m_ref_length_type == CLOSEST) { int min_diff = INT_MAX; int min_idx = 0; for (size_t i = 0; i < _reflengths[sid].size(); ++i) { diff --git a/mert/BleuScorer.h b/mert/BleuScorer.h index a10b09a7a..f4d568639 100644 --- a/mert/BleuScorer.h +++ b/mert/BleuScorer.h @@ -12,9 +12,6 @@ using namespace std; -enum BleuReferenceLengthStrategy { BLEU_AVERAGE, BLEU_SHORTEST, BLEU_CLOSEST }; - - /** * Bleu scoring */ @@ -33,6 +30,12 @@ public: } private: + enum ReferenceLengthType { + AVERAGE, + SHORTEST, + CLOSEST, + }; + //Used to construct the ngram map struct CompareNgrams { bool operator()(const vector& a, const vector& b) const { @@ -67,7 +70,7 @@ private: void dump_counts(counts_t& counts) const; const int kLENGTH; - BleuReferenceLengthStrategy _refLengthStrategy; + ReferenceLengthType m_ref_length_type; // data extracted from reference files refcounts_t _refcounts;