Using namespace std in a header file pollutes the global namespace.

Using directives should be put into the implementation files.
This commit is contained in:
Tetsuo Kiso 2012-11-05 00:43:36 +09:00
parent 62fa6d6f28
commit cccfb9a0c9
2 changed files with 13 additions and 15 deletions

View File

@ -30,7 +30,7 @@ const char REFLEN_CLOSEST[] = "closest";
namespace MosesTuning
{
BleuScorer::BleuScorer(const string& config)
: StatisticsBasedScorer("BLEU", config),
@ -245,7 +245,7 @@ float sentenceLevelBackgroundBleu(const std::vector<float>& sent, const std::vec
std::vector<float> stats;
CHECK(sent.size()==bg.size());
CHECK(sent.size()==kBleuNgramOrder*2+1);
for(size_t i=0;i<sent.size();i++)
for(size_t i=0;i<sent.size();i++)
stats.push_back(sent[i]+bg[i]);
// Calculate BLEU
@ -255,7 +255,7 @@ float sentenceLevelBackgroundBleu(const std::vector<float>& sent, const std::vec
}
logbleu /= kBleuNgramOrder;
const float brevity = 1.0 - stats[(kBleuNgramOrder * 2)] / stats[1];
if (brevity < 0.0) {
logbleu += brevity;
}
@ -280,19 +280,19 @@ float unsmoothedBleu(const std::vector<float>& stats) {
return exp(logbleu);
}
vector<float> BleuScorer::ScoreNbestList(string scoreFile, string featureFile) {
vector<float> BleuScorer::ScoreNbestList(const string& scoreFile, const string& featureFile) {
vector<string> scoreFiles;
vector<string> featureFiles;
scoreFiles.push_back(scoreFile);
featureFiles.push_back(featureFile);
vector<FeatureDataIterator> featureDataIters;
vector<ScoreDataIterator> scoreDataIters;
for (size_t i = 0; i < featureFiles.size(); ++i) {
featureDataIters.push_back(FeatureDataIterator(featureFiles[i]));
scoreDataIters.push_back(ScoreDataIterator(scoreFiles[i]));
}
vector<pair<size_t,size_t> > hypotheses;
if (featureDataIters[0] == FeatureDataIterator::end()) {
cerr << "Error: at the end of feature data iterator" << endl;
@ -315,16 +315,16 @@ vector<float> BleuScorer::ScoreNbestList(string scoreFile, string featureFile) {
hypotheses.push_back(pair<size_t,size_t>(i,j));
}
}
// score the nbest list
vector<float> bleuScores;
for (size_t i=0; i < hypotheses.size(); ++i) {
pair<size_t,size_t> translation = hypotheses[i];
float bleu = sentenceLevelBleuPlusOne(scoreDataIters[translation.first]->operator[](translation.second));
bleuScores.push_back(bleu);
}
}
return bleuScores;
}
}
float BleuScorer::sentenceLevelBleuPlusOne(const vector<float>& stats) {
float logbleu = 0.0;

View File

@ -16,9 +16,7 @@ namespace MosesTuning
const int kBleuNgramOrder = 4;
class NgramCounts;
class Reference;
using namespace std;
class Reference;
/**
* Bleu scoring
@ -34,9 +32,9 @@ public:
explicit BleuScorer(const std::string& config = "");
~BleuScorer();
static vector<float> ScoreNbestList(string scoreFile, string featureFile);
static float sentenceLevelBleuPlusOne(const vector<float>& stats);
static std::vector<float> ScoreNbestList(const std::string& scoreFile, const std::string& featureFile);
static float sentenceLevelBleuPlusOne(const std::vector<float>& stats);
virtual void setReferenceFiles(const std::vector<std::string>& referenceFiles);
virtual void prepareStats(std::size_t sid, const std::string& text, ScoreStats& entry);