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

View File

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