mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 13:23:25 +03:00
Clean up.
This commit is contained in:
parent
c26e83fd09
commit
c913effe13
@ -55,9 +55,11 @@ void CderScorer::prepareStatsVector(size_t sid, const string& text, vector<int>&
|
||||
TokenizeAndEncode(text, cand);
|
||||
|
||||
float max = -2;
|
||||
vector<int> tmp;
|
||||
for (size_t rid = 0; rid < m_ref_sentences.size(); ++rid) {
|
||||
sent_t& ref = m_ref_sentences[rid][sid];
|
||||
vector<int> tmp = computeCD(cand, ref);
|
||||
const sent_t& ref = m_ref_sentences[rid][sid];
|
||||
tmp.clear();
|
||||
computeCD(cand, ref, tmp);
|
||||
if (calculateScore(tmp) > max) {
|
||||
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
|
||||
{
|
||||
if (comps.size() != 2)
|
||||
{
|
||||
if (comps.size() != 2) {
|
||||
throw runtime_error("Size of stat vector for CDER is not 2");
|
||||
}
|
||||
|
||||
return 1 - (comps[0] / static_cast<float>(comps[1]));
|
||||
return 1.0f - (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 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;
|
||||
}
|
||||
|
||||
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[1] = ref.size();
|
||||
|
||||
delete row;
|
||||
return stats;
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#ifndef MERT_CDER_SCORER_H_
|
||||
#define MERT_CDER_SCORER_H_
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Types.h"
|
||||
@ -10,9 +8,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CderScorer: public StatisticsBasedScorer
|
||||
{
|
||||
public:
|
||||
class CderScorer: public StatisticsBasedScorer {
|
||||
public:
|
||||
explicit CderScorer(const string& config);
|
||||
~CderScorer();
|
||||
|
||||
@ -22,17 +19,16 @@ public:
|
||||
|
||||
virtual void prepareStatsVector(size_t sid, const string& text, vector<int>& stats);
|
||||
|
||||
virtual size_t NumberOfScores() const {
|
||||
return 2;
|
||||
}
|
||||
virtual size_t NumberOfScores() const { return 2; }
|
||||
|
||||
virtual float calculateScore(const vector<int>& comps) const;
|
||||
|
||||
private:
|
||||
private:
|
||||
typedef vector<int> sent_t;
|
||||
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
|
||||
CderScorer(const CderScorer&);
|
||||
|
Loading…
Reference in New Issue
Block a user