2008-05-15 12:35:56 +04:00
|
|
|
/*
|
|
|
|
* Data.cpp
|
|
|
|
* met - Minimum Error Training
|
|
|
|
*
|
|
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include "Scorer.h"
|
|
|
|
#include "Data.h"
|
|
|
|
#include "Util.h"
|
|
|
|
|
|
|
|
|
|
|
|
Data::Data(Scorer& ptr):
|
|
|
|
bufLen_(0), theScorer(&ptr)
|
|
|
|
{
|
2008-05-15 18:13:32 +04:00
|
|
|
score_type = (*theScorer).getName();
|
|
|
|
featdata=new FeatureData;
|
|
|
|
scoredata=new ScoreData(*theScorer);
|
2008-05-15 12:35:56 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void Data::loadnbest(const std::string &file)
|
|
|
|
{
|
|
|
|
TRACE_ERR("loading nbest from " << file << std::endl);
|
|
|
|
|
|
|
|
FeatureStats featentry;
|
|
|
|
ScoreStats scoreentry;
|
|
|
|
int sentence_index;
|
|
|
|
int nextPound;
|
|
|
|
|
|
|
|
std::ifstream inFile(file.c_str(), std::ios::in); // matches a stream with a file. Opens the file
|
|
|
|
|
2008-05-15 18:13:32 +04:00
|
|
|
if (!inFile) {
|
|
|
|
throw runtime_error("Unable to open: " + file);
|
|
|
|
}
|
2008-05-15 12:35:56 +04:00
|
|
|
|
|
|
|
while (!inFile.eof()){
|
|
|
|
|
|
|
|
std::string substring, subsubstring, stringBuf;
|
|
|
|
std::string theSentence;
|
|
|
|
std::string::size_type loc;
|
|
|
|
|
|
|
|
std::getline(inFile, stringBuf);
|
|
|
|
if (stringBuf.empty()) continue;
|
|
|
|
|
|
|
|
// TRACE_ERR("Reading: " << stringBuf << std::endl);
|
|
|
|
|
|
|
|
nextPound = getNextPound(stringBuf, substring, "|||"); //first field
|
|
|
|
sentence_index = atoi(substring.c_str());
|
|
|
|
|
|
|
|
nextPound = getNextPound(stringBuf, substring, "|||"); //second field
|
|
|
|
theSentence = substring;
|
|
|
|
|
|
|
|
// adding statistics for error measures
|
|
|
|
scoreentry.clear();
|
|
|
|
theScorer->prepareStats(sentence_index, theSentence,scoreentry);
|
|
|
|
scoredata->add(scoreentry,sentence_index);
|
|
|
|
|
|
|
|
|
|
|
|
nextPound = getNextPound(stringBuf, substring, "|||"); //third field
|
|
|
|
|
|
|
|
// adding features
|
|
|
|
featentry.clear();
|
|
|
|
scoreentry.clear();
|
|
|
|
while (!substring.empty()){
|
|
|
|
// TRACE_ERR("Decompounding: " << substring << std::endl);
|
|
|
|
nextPound = getNextPound(substring, subsubstring);
|
|
|
|
if ((loc = subsubstring.find(":")) != subsubstring.length()-1){
|
|
|
|
featentry.add(ATOFST(subsubstring.c_str()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
featdata->add(featentry,sentence_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
inFile.close();
|
|
|
|
}
|