00001 #include <fstream>
00002 #include <iostream>
00003 #include <vector>
00004 #include <string>
00005
00006 #include <boost/shared_ptr.hpp>
00007
00008 #include "BleuScorer.h"
00009 #include "Reference.h"
00010 #include "moses/Util.h"
00011 #include "util/exception.hh"
00012
00013 using namespace std;
00014 using namespace MosesTuning;
00015
00016
00017 int main(int argc, char **argv)
00018 {
00019 if (argc == 1) {
00020 cerr << "Usage: ./sentence-bleu ref1 [ref2 ...] < candidate > bleu-scores" << endl;
00021 return 1;
00022 }
00023
00024 vector<string> refFiles(argv + 1, argv + argc);
00025
00026
00027 string config;
00028 string factors;
00029 string filter;
00030
00031 BleuScorer scorer(config);
00032 scorer.setFactors(factors);
00033 scorer.setFilter(filter);
00034
00035
00036 vector<boost::shared_ptr<ifstream> > refStreams;
00037 for (vector<string>::const_iterator refFile=refFiles.begin(); refFile!=refFiles.end(); ++refFile) {
00038 TRACE_ERR("Loading reference from " << *refFile << endl);
00039 boost::shared_ptr<ifstream> ifs(new ifstream(refFile->c_str()));
00040 UTIL_THROW_IF2(!ifs, "Cannot open " << *refFile);
00041 refStreams.push_back(ifs);
00042 }
00043
00044
00045 string hypothesisLine;
00046 size_t sid = 0;
00047 while (getline(std::cin, hypothesisLine)) {
00048 Reference ref;
00049 if (!scorer.GetNextReferenceFromStreams(refStreams, ref)) {
00050 UTIL_THROW2("Missing references");
00051 }
00052 ScoreStats scoreStats;
00053 scorer.CalcBleuStats(ref, hypothesisLine, scoreStats);
00054 vector<float> stats(scoreStats.getArray(), scoreStats.getArray() + scoreStats.size());
00055 std::cout << smoothedSentenceBleu(stats) << std::endl;
00056 ++sid;
00057 }
00058
00059 return 0;
00060 }
00061