Clean up.

This commit is contained in:
Tetsuo Kiso 2012-02-26 13:04:27 +09:00
parent c26e83fd09
commit c913effe13
2 changed files with 15 additions and 20 deletions

View File

@ -55,9 +55,11 @@ void CderScorer::prepareStatsVector(size_t sid, const string& text, vector<int>&
TokenizeAndEncode(text, cand); TokenizeAndEncode(text, cand);
float max = -2; float max = -2;
vector<int> tmp;
for (size_t rid = 0; rid < m_ref_sentences.size(); ++rid) { for (size_t rid = 0; rid < m_ref_sentences.size(); ++rid) {
sent_t& ref = m_ref_sentences[rid][sid]; const sent_t& ref = m_ref_sentences[rid][sid];
vector<int> tmp = computeCD(cand, ref); tmp.clear();
computeCD(cand, ref, tmp);
if (calculateScore(tmp) > max) { if (calculateScore(tmp) > max) {
stats = tmp; stats = tmp;
} }
@ -66,16 +68,14 @@ void CderScorer::prepareStatsVector(size_t sid, const string& text, vector<int>&
float CderScorer::calculateScore(const vector<int>& comps) const float CderScorer::calculateScore(const vector<int>& comps) const
{ {
if (comps.size() != 2) if (comps.size() != 2) {
{
throw runtime_error("Size of stat vector for CDER is not 2"); throw runtime_error("Size of stat vector for CDER is not 2");
} }
return 1.0f - (comps[0] / static_cast<float>(comps[1]));
return 1 - (comps[0] / static_cast<float>(comps[1]));
} }
vector<int> CderScorer::computeCD(const sent_t& cand, const sent_t& ref) const void CderScorer::computeCD(const sent_t& cand, const sent_t& ref,
{ vector<int>& stats) const {
int I = cand.size() + 1; // Number of inter-words positions in candidate sentence int I = cand.size() + 1; // Number of inter-words positions in candidate sentence
int L = ref.size() + 1; // Number of inter-words positions in reference sentence int L = ref.size() + 1; // Number of inter-words positions in reference sentence
@ -113,10 +113,9 @@ vector<int> CderScorer::computeCD(const sent_t& cand, const sent_t& ref) const
row = nextRow; row = nextRow;
} }
vector<int> stats(2); stats.resize(2);
stats[0] = *(row->rbegin()); // CD distance is the cost of path from (0,0) to (I,L) stats[0] = *(row->rbegin()); // CD distance is the cost of path from (0,0) to (I,L)
stats[1] = ref.size(); stats[1] = ref.size();
delete row; delete row;
return stats;
} }

View File

@ -1,8 +1,6 @@
#ifndef MERT_CDER_SCORER_H_ #ifndef MERT_CDER_SCORER_H_
#define MERT_CDER_SCORER_H_ #define MERT_CDER_SCORER_H_
#include <algorithm>
#include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
#include "Types.h" #include "Types.h"
@ -10,8 +8,7 @@
using namespace std; using namespace std;
class CderScorer: public StatisticsBasedScorer class CderScorer: public StatisticsBasedScorer {
{
public: public:
explicit CderScorer(const string& config); explicit CderScorer(const string& config);
~CderScorer(); ~CderScorer();
@ -22,9 +19,7 @@ public:
virtual void prepareStatsVector(size_t sid, const string& text, vector<int>& stats); virtual void prepareStatsVector(size_t sid, const string& text, vector<int>& stats);
virtual size_t NumberOfScores() const { virtual size_t NumberOfScores() const { return 2; }
return 2;
}
virtual float calculateScore(const vector<int>& comps) const; virtual float calculateScore(const vector<int>& comps) const;
@ -32,7 +27,8 @@ private:
typedef vector<int> sent_t; typedef vector<int> sent_t;
vector<vector<sent_t> > m_ref_sentences; vector<vector<sent_t> > m_ref_sentences;
vector<int> computeCD(const sent_t& cand, const sent_t& ref) const; void computeCD(const sent_t& cand, const sent_t& ref,
vector<int>& stats) const;
// no copying allowed // no copying allowed
CderScorer(const CderScorer&); CderScorer(const CderScorer&);