mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
Use const Scorer::calculateScore().
This commit is contained in:
parent
1ec58e7edf
commit
00b8c6d768
@ -43,7 +43,7 @@ size_t BleuScorer::countNgrams(const string& line, counts_t& counts, unsigned in
|
||||
ngram.push_back(encoded_tokens[j]);
|
||||
}
|
||||
int count = 1;
|
||||
counts_it oldcount = counts.find(ngram);
|
||||
counts_iterator oldcount = counts.find(ngram);
|
||||
if (oldcount != counts.end()) {
|
||||
count = (oldcount->second) + 1;
|
||||
}
|
||||
@ -87,8 +87,8 @@ void BleuScorer::setReferenceFiles(const vector<string>& referenceFiles)
|
||||
counts_t counts;
|
||||
size_t length = countNgrams(line,counts,kLENGTH);
|
||||
//for any counts larger than those already there, merge them in
|
||||
for (counts_it ci = counts.begin(); ci != counts.end(); ++ci) {
|
||||
counts_it oldcount_it = _refcounts[sid]->find(ci->first);
|
||||
for (counts_iterator ci = counts.begin(); ci != counts.end(); ++ci) {
|
||||
counts_iterator oldcount_it = _refcounts[sid]->find(ci->first);
|
||||
int oldcount = 0;
|
||||
if (oldcount_it != _refcounts[sid]->end()) {
|
||||
oldcount = oldcount_it->second;
|
||||
@ -156,9 +156,9 @@ void BleuScorer::prepareStats(size_t sid, const string& text, ScoreStats& entry)
|
||||
}
|
||||
//cerr << "computed length" << endl;
|
||||
//precision on each ngram type
|
||||
for (counts_it testcounts_it = testcounts.begin();
|
||||
for (counts_iterator testcounts_it = testcounts.begin();
|
||||
testcounts_it != testcounts.end(); ++testcounts_it) {
|
||||
counts_it refcounts_it = _refcounts[sid]->find(testcounts_it->first);
|
||||
counts_iterator refcounts_it = _refcounts[sid]->find(testcounts_it->first);
|
||||
int correct = 0;
|
||||
int guess = testcounts_it->second;
|
||||
if (refcounts_it != _refcounts[sid]->end()) {
|
||||
@ -175,7 +175,7 @@ void BleuScorer::prepareStats(size_t sid, const string& text, ScoreStats& entry)
|
||||
entry.set(stats_str);
|
||||
}
|
||||
|
||||
float BleuScorer::calculateScore(const vector<int>& comps)
|
||||
float BleuScorer::calculateScore(const vector<int>& comps) const
|
||||
{
|
||||
//cerr << "BLEU: ";
|
||||
//copy(comps.begin(),comps.end(), ostream_iterator<int>(cerr," "));
|
||||
@ -196,8 +196,8 @@ float BleuScorer::calculateScore(const vector<int>& comps)
|
||||
return exp(logbleu);
|
||||
}
|
||||
|
||||
void BleuScorer::dump_counts(counts_t& counts) {
|
||||
for (counts_it i = counts.begin(); i != counts.end(); ++i) {
|
||||
void BleuScorer::dump_counts(counts_t& counts) const {
|
||||
for (counts_const_iterator i = counts.begin(); i != counts.end(); ++i) {
|
||||
cerr << "(";
|
||||
copy(i->first.begin(), i->first.end(), ostream_iterator<int>(cerr," "));
|
||||
cerr << ") " << i->second << ", ";
|
||||
|
@ -32,20 +32,19 @@ public:
|
||||
|
||||
virtual void setReferenceFiles(const vector<string>& referenceFiles);
|
||||
virtual void prepareStats(size_t sid, const string& text, ScoreStats& entry);
|
||||
virtual float calculateScore(const vector<int>& comps) const;
|
||||
|
||||
size_t NumberOfScores() {
|
||||
return (2 * kLENGTH + 1);
|
||||
size_t NumberOfScores() const {
|
||||
return 2 * kLENGTH + 1;
|
||||
}
|
||||
|
||||
float calculateScore(const vector<int>& comps);
|
||||
|
||||
private:
|
||||
//Used to construct the ngram map
|
||||
struct CompareNgrams {
|
||||
int operator()(const vector<int>& a, const vector<int>& b) {
|
||||
bool operator()(const vector<int>& a, const vector<int>& b) const {
|
||||
size_t i;
|
||||
size_t as = a.size();
|
||||
size_t bs = b.size();
|
||||
const size_t as = a.size();
|
||||
const size_t bs = b.size();
|
||||
for (i = 0; i < as && i < bs; ++i) {
|
||||
if (a[i] < b[i]) {
|
||||
//cerr << "true" << endl;
|
||||
@ -62,7 +61,8 @@ private:
|
||||
};
|
||||
|
||||
typedef map<vector<int>,int,CompareNgrams> counts_t;
|
||||
typedef map<vector<int>,int,CompareNgrams>::iterator counts_it;
|
||||
typedef map<vector<int>,int,CompareNgrams>::iterator counts_iterator;
|
||||
typedef map<vector<int>,int,CompareNgrams>::iterator counts_const_iterator;
|
||||
typedef ScopedVector<counts_t> refcounts_t;
|
||||
|
||||
/**
|
||||
@ -70,7 +70,7 @@ private:
|
||||
*/
|
||||
size_t countNgrams(const string& line, counts_t& counts, unsigned int n);
|
||||
|
||||
void dump_counts(counts_t& counts);
|
||||
void dump_counts(counts_t& counts) const;
|
||||
|
||||
const int kLENGTH;
|
||||
BleuReferenceLengthStrategy _refLengthStrategy;
|
||||
|
@ -45,7 +45,7 @@ void CderScorer::prepareStatsVector(size_t sid, const string& text, vector<int>&
|
||||
}
|
||||
}
|
||||
|
||||
float CderScorer::calculateScore(const vector<int>& comps)
|
||||
float CderScorer::calculateScore(const vector<int>& comps) const
|
||||
{
|
||||
if (comps.size() != 2)
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
return 2;
|
||||
}
|
||||
|
||||
float calculateScore(const vector<int>& comps);
|
||||
virtual float calculateScore(const vector<int>& comps) const;
|
||||
|
||||
private:
|
||||
typedef vector<int> sent_t;
|
||||
|
@ -29,7 +29,7 @@ float MergeScorer::calculateScore(const vector<int>& comps)
|
||||
}
|
||||
*/
|
||||
|
||||
float MergeScorer::calculateScore(const std::vector< int >& comps)
|
||||
float MergeScorer::calculateScore(const std::vector< int >& comps) const
|
||||
{
|
||||
float result=0.0;
|
||||
float weight=1.0;
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
|
||||
protected:
|
||||
friend class PerScorer;
|
||||
float calculateScore(const vector<int>& comps);
|
||||
virtual float calculateScore(const vector<int>& comps) const;
|
||||
|
||||
private:
|
||||
const int kLENGTH;
|
||||
|
@ -63,7 +63,7 @@ void PerScorer::prepareStats(size_t sid, const string& text, ScoreStats& entry)
|
||||
entry.set(stats_str);
|
||||
}
|
||||
|
||||
float PerScorer::calculateScore(const vector<int>& comps)
|
||||
float PerScorer::calculateScore(const vector<int>& comps) const
|
||||
{
|
||||
float denom = comps[2];
|
||||
float num = comps[0] - max(0,comps[1]-comps[2]);
|
||||
|
@ -41,9 +41,7 @@ public:
|
||||
return 3;
|
||||
}
|
||||
|
||||
//protected:
|
||||
|
||||
virtual float calculateScore(const vector<int>& comps);
|
||||
virtual float calculateScore(const vector<int>& comps) const;
|
||||
|
||||
private:
|
||||
// no copying allowed
|
||||
|
@ -181,7 +181,7 @@ protected:
|
||||
/**
|
||||
* Calculate the actual score.
|
||||
*/
|
||||
virtual statscore_t calculateScore(const vector<int>& totals) = 0;
|
||||
virtual statscore_t calculateScore(const vector<int>& totals) const = 0;
|
||||
|
||||
// regularisation
|
||||
ScorerRegularisationStrategy _regularisationStrategy;
|
||||
|
@ -88,7 +88,7 @@ void TerScorer::prepareStats ( size_t sid, const string& text, ScoreStats& entry
|
||||
entry.set ( stats_str );
|
||||
}
|
||||
|
||||
float TerScorer::calculateScore ( const vector<int>& comps )
|
||||
float TerScorer::calculateScore(const vector<int>& comps) const
|
||||
{
|
||||
float denom = 1.0 * comps[1];
|
||||
float num = -1.0 * comps[0];
|
||||
@ -99,17 +99,3 @@ float TerScorer::calculateScore ( const vector<int>& comps )
|
||||
return (1.0+(num / denom));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
float TerScorer::calculateScore ( const vector<float>& comps )
|
||||
{
|
||||
float denom = 1.0 * comps[1];
|
||||
float num = -1.0 * comps[0];
|
||||
if ( denom == 0 ) {
|
||||
// shouldn't happen!
|
||||
return 1.0;
|
||||
} else {
|
||||
return (1.0+(num / denom));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
@ -43,10 +43,7 @@ public:
|
||||
return (kLENGTH + 1);
|
||||
}
|
||||
|
||||
|
||||
//protected:
|
||||
float calculateScore(const vector<int>& comps);
|
||||
// float calculateScore(const vector<float>& comps);
|
||||
virtual float calculateScore(const vector<int>& comps) const;
|
||||
|
||||
private:
|
||||
const int kLENGTH;
|
||||
|
Loading…
Reference in New Issue
Block a user