diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-02-01 16:44:37 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-02-01 16:44:37 +0400 |
commit | 905f959d83b573094ce9d675683efeeb9b47958d (patch) | |
tree | 9f7c348b00ef58555c8f06e6b70cb4fafcd998e6 /mert/CderScorer.cpp | |
parent | b2987337d87115a6858113b6a6ad2cc6d2e2db40 (diff) |
Move funcions defined in a header into .cpp file.
Diffstat (limited to 'mert/CderScorer.cpp')
-rw-r--r-- | mert/CderScorer.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/mert/CderScorer.cpp b/mert/CderScorer.cpp index fdccdcfe7..ef1f6195f 100644 --- a/mert/CderScorer.cpp +++ b/mert/CderScorer.cpp @@ -1,7 +1,17 @@ #include "CderScorer.h" + +#include <iterator> #include <fstream> #include <stdexcept> +namespace { + +inline int CalcDistance(int word1, int word2) { + return word1 == word2 ? 0 : 1; +} + +} // namespace + CderScorer::CderScorer(const string& config) : StatisticsBasedScorer("CDER",config) {} @@ -28,6 +38,17 @@ void CderScorer::setReferenceFiles(const vector<string>& referenceFiles) } } +void CderScorer::prepareStats(size_t sid, const string& text, ScoreStats& entry) +{ + vector<int> stats; + prepareStatsVector(sid, text, stats); + + stringstream sout; + copy(stats.begin(), stats.end(), ostream_iterator<float>(sout," ")); + string stats_str = sout.str(); + entry.set(stats_str); +} + void CderScorer::prepareStatsVector(size_t sid, const string& text, vector<int>& stats) { sent_t cand; @@ -75,7 +96,7 @@ vector<int> CderScorer::computeCD(const sent_t& cand, const sent_t& ref) const vector<int> possibleCosts; if (i > 0) { possibleCosts.push_back((*nextRow)[i-1] + 1); // Deletion - possibleCosts.push_back((*row)[i-1] + distance(ref[l-1], cand[i-1])); // Substitution/Identity + possibleCosts.push_back((*row)[i-1] + CalcDistance(ref[l-1], cand[i-1])); // Substitution/Identity } possibleCosts.push_back((*row)[i] + 1); // Insertion (*nextRow)[i] = *min_element(possibleCosts.begin(), possibleCosts.end()); |