diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-02-01 13:13:00 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-02-01 13:13:00 +0400 |
commit | 3ef03a77c4960d2de2695f29c5f16834427ae54c (patch) | |
tree | d83fe9ff3b80e7d58891cddfb3b16bccbe4f0f92 /mert/BleuScorer.cpp | |
parent | 142342f8be02648e101fd53441b5d43cdfbb0826 (diff) |
Change casts to C++ style casts.
Diffstat (limited to 'mert/BleuScorer.cpp')
-rw-r--r-- | mert/BleuScorer.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/mert/BleuScorer.cpp b/mert/BleuScorer.cpp index 45bd635bb..68c1c1e26 100644 --- a/mert/BleuScorer.cpp +++ b/mert/BleuScorer.cpp @@ -142,18 +142,21 @@ void BleuScorer::prepareStats(size_t sid, const string& text, ScoreStats& entry) for (size_t i = 0; i < _reflengths[sid].size(); ++i) { total += _reflengths[sid][i]; } - float mean = static_cast<float>(total) /_reflengths[sid].size(); + const float mean = static_cast<float>(total) /_reflengths[sid].size(); stats.push_back(mean); } else if (_refLengthStrategy == BLEU_CLOSEST) { int min_diff = INT_MAX; int min_idx = 0; for (size_t i = 0; i < _reflengths[sid].size(); ++i) { - int reflength = _reflengths[sid][i]; - if (abs(reflength-(int)length) < abs(min_diff)) { //look for the closest reference - min_diff = reflength-length; + const int reflength = _reflengths[sid][i]; + const int diff = reflength - static_cast<int>(length); + const int absolute_diff = abs(diff) - abs(min_diff); + + if (absolute_diff < 0) { //look for the closest reference + min_diff = diff; min_idx = i; - } else if (abs(reflength-(int)length) == abs(min_diff)) { // if two references has the same closest length, take the shortest - if (reflength < (int)_reflengths[sid][min_idx]) { + } else if (absolute_diff == 0) { // if two references has the same closest length, take the shortest + if (reflength < static_cast<int>(_reflengths[sid][min_idx])) { min_idx = i; } } |