mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-11-10 10:59:21 +03:00
642e8dce95
evaluator --sctype PER --reference ref.file --candidate cand.file usage: evaluator [options] --reference ref1[,ref2[,ref3...]] --candidate cand1[,cand2[,cand3...]] [--sctype|-s] the scorer type (default BLEU) [--scconfig|-c] configuration string passed to scorer This is of the form NAME1:VAL1,NAME2:VAL2 etc [--reference|-R] comma separated list of reference files [--candidate|-C] comma separated list of candidate files [--bootstrap|-b] number of booststraped samples (default 0 - no bootstraping) [--rseed|-r] the random seed for bootstraping (defaults to system clock) [--help|-h] print this message and exit git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@4153 1f5c12ca-751b-0410-a591-d2e778427230
134 lines
3.0 KiB
C++
134 lines
3.0 KiB
C++
/*
|
|
* ScoreData.cpp
|
|
* met - Minimum Error Training
|
|
*
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
*
|
|
*/
|
|
|
|
#include <fstream>
|
|
#include "ScoreData.h"
|
|
#include "Scorer.h"
|
|
#include "Util.h"
|
|
|
|
|
|
ScoreData::ScoreData(Scorer& ptr):
|
|
theScorer(&ptr)
|
|
{
|
|
score_type = theScorer->getName();
|
|
theScorer->setScoreData(this);//this is not dangerous: we dont use the this pointer in SetScoreData
|
|
number_of_scores = theScorer->NumberOfScores();
|
|
// TRACE_ERR("ScoreData: number_of_scores: " << number_of_scores << std::endl);
|
|
};
|
|
|
|
void ScoreData::save(std::ofstream& outFile, bool bin)
|
|
{
|
|
for (scoredata_t::iterator i = array_.begin(); i !=array_.end(); i++) {
|
|
i->save(outFile, score_type, bin);
|
|
}
|
|
}
|
|
|
|
void ScoreData::save(const std::string &file, bool bin)
|
|
{
|
|
if (file.empty()) return;
|
|
TRACE_ERR("saving the array into " << file << std::endl);
|
|
|
|
std::ofstream outFile(file.c_str(), std::ios::out); // matches a stream with a file. Opens the file
|
|
|
|
ScoreStats entry;
|
|
|
|
save(outFile, bin);
|
|
|
|
outFile.close();
|
|
}
|
|
|
|
void ScoreData::load(ifstream& inFile)
|
|
{
|
|
ScoreArray entry;
|
|
|
|
while (!inFile.eof()) {
|
|
|
|
if (!inFile.good()) {
|
|
std::cerr << "ERROR ScoreData::load inFile.good()" << std::endl;
|
|
}
|
|
|
|
entry.clear();
|
|
entry.load(inFile);
|
|
|
|
if (entry.size() == 0) {
|
|
break;
|
|
}
|
|
add(entry);
|
|
}
|
|
}
|
|
|
|
|
|
void ScoreData::load(const std::string &file)
|
|
{
|
|
TRACE_ERR("loading score data from " << file << std::endl);
|
|
|
|
inputfilestream inFile(file); // matches a stream with a file. Opens the file
|
|
|
|
if (!inFile) {
|
|
throw runtime_error("Unable to open score file: " + file);
|
|
}
|
|
|
|
load((ifstream&) inFile);
|
|
|
|
inFile.close();
|
|
}
|
|
|
|
|
|
void ScoreData::add(ScoreArray& e)
|
|
{
|
|
if (exists(e.getIndex())) { // array at position e.getIndex() already exists
|
|
//enlarge array at position e.getIndex()
|
|
size_t pos = getIndex(e.getIndex());
|
|
array_.at(pos).merge(e);
|
|
} else {
|
|
array_.push_back(e);
|
|
setIndex();
|
|
}
|
|
}
|
|
|
|
void ScoreData::add(const ScoreStats& e, const std::string& sent_idx)
|
|
{
|
|
if (exists(sent_idx)) { // array at position e.getIndex() already exists
|
|
//enlarge array at position e.getIndex()
|
|
size_t pos = getIndex(sent_idx);
|
|
// TRACE_ERR("Inserting in array " << sent_idx << std::endl);
|
|
array_.at(pos).add(e);
|
|
// TRACE_ERR("size: " << size() << " -> " << a.size() << std::endl);
|
|
} else {
|
|
// TRACE_ERR("Creating a new entry in the array" << std::endl);
|
|
ScoreArray a;
|
|
a.NumberOfScores(number_of_scores);
|
|
a.add(e);
|
|
a.setIndex(sent_idx);
|
|
add(a);
|
|
// TRACE_ERR("size: " << size() << " -> " << a.size() << std::endl);
|
|
}
|
|
}
|
|
|
|
|
|
bool ScoreData::check_consistency()
|
|
{
|
|
if (array_.size() == 0)
|
|
return true;
|
|
|
|
for (scoredata_t::iterator i = array_.begin(); i !=array_.end(); i++)
|
|
if (!i->check_consistency()) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
void ScoreData::setIndex()
|
|
{
|
|
size_t j=0;
|
|
for (scoredata_t::iterator i = array_.begin(); i !=array_.end(); i++) {
|
|
idx2arrayname_[j]=i->getIndex();
|
|
arrayname2idx_[i->getIndex()]=j;
|
|
j++;
|
|
}
|
|
}
|