Minor change the logging utility for n-gram counts.

Use std::ostream instead of directly using std::cerr.
This commit is contained in:
Tetsuo Kiso 2012-02-26 02:01:03 +09:00
parent 4a63846f82
commit 37c19feebd
2 changed files with 17 additions and 10 deletions

View File

@ -4,7 +4,7 @@
#include <cmath>
#include <climits>
#include <fstream>
#include <iterator>
#include <iostream>
#include <stdexcept>
#include "Util.h"
@ -236,14 +236,21 @@ float BleuScorer::calculateScore(const vector<int>& comps) const
return exp(logbleu);
}
void BleuScorer::dump_counts(const NgramCounts& counts) const {
for (NgramCounts::const_iterator i = counts.begin();
i != counts.end(); ++i) {
cerr << "(";
copy(i->first.begin(), i->first.end(), ostream_iterator<int>(cerr," "));
cerr << ") " << i->second << ", ";
void BleuScorer::dump_counts(ostream* os,
const NgramCounts& counts) const {
for (NgramCounts::const_iterator it = counts.begin();
it != counts.end(); ++it) {
*os << "(";
const NgramCounts::Key& keys = it->first;
for (size_t i = 0; i < keys.size(); ++i) {
if (i != 0) {
*os << " ";
}
*os << keys[i];
}
*os << ") : " << it->second << ", ";
}
cerr << endl;
*os << endl;
}
void BleuScorer::CalcAverage(size_t sentence_id,

View File

@ -1,7 +1,7 @@
#ifndef MERT_BLEU_SCORER_H_
#define MERT_BLEU_SCORER_H_
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
@ -45,7 +45,7 @@ private:
*/
size_t countNgrams(const string& line, NgramCounts& counts, unsigned int n);
void dump_counts(const NgramCounts& counts) const;
void dump_counts(std::ostream* os, const NgramCounts& counts) const;
// For calculating effective reference length.
void CalcAverage(size_t sentence_id,