mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
adding a simple command-line utility for computing sentence-level BLEU (+1)
This commit is contained in:
parent
ed2d191821
commit
598d65bcfd
@ -57,11 +57,13 @@ exe extractor : extractor.cpp mert_lib ;
|
||||
|
||||
exe evaluator : evaluator.cpp mert_lib ;
|
||||
|
||||
exe sentence-bleu : sentence-bleu.cpp mert_lib ;
|
||||
|
||||
exe pro : pro.cpp mert_lib ..//boost_program_options ;
|
||||
|
||||
exe kbmira : kbmira.cpp mert_lib ..//boost_program_options ;
|
||||
|
||||
alias programs : mert extractor evaluator pro kbmira ;
|
||||
alias programs : mert extractor evaluator pro kbmira sentence-bleu ;
|
||||
|
||||
unit-test bleu_scorer_test : BleuScorerTest.cpp mert_lib ..//boost_unit_test_framework ;
|
||||
unit-test feature_data_test : FeatureDataTest.cpp mert_lib ..//boost_unit_test_framework ;
|
||||
|
43
mert/sentence-bleu.cpp
Normal file
43
mert/sentence-bleu.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "BleuScorer.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace MosesTuning;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 1) {
|
||||
cerr << "Usage: ./sentence-bleu ref1 [ref2 ...] < candidate > bleu-scores" << endl;
|
||||
return 1;
|
||||
}
|
||||
vector<string> refFiles(argv + 1, argv + argc);
|
||||
|
||||
// TODO all of these are empty for now
|
||||
string config;
|
||||
string factors;
|
||||
string filter;
|
||||
|
||||
BleuScorer *scorer = new BleuScorer(config);
|
||||
scorer->setFactors(factors);
|
||||
scorer->setFilter(filter);
|
||||
scorer->setReferenceFiles(refFiles);
|
||||
|
||||
vector<ScoreStats> entries;
|
||||
|
||||
// Loading sentences and preparing statistics
|
||||
ScoreStats scoreentry;
|
||||
string line;
|
||||
while (getline(cin, line)) {
|
||||
scorer->prepareStats(entries.size(), line, scoreentry);
|
||||
entries.push_back(scoreentry);
|
||||
}
|
||||
|
||||
vector<ScoreStats>::const_iterator sentIt;
|
||||
for (sentIt = entries.begin(); sentIt != entries.end(); sentIt++) {
|
||||
vector<float> stats(sentIt->getArray(), sentIt->getArray() + sentIt->size());
|
||||
cout << BleuScorer::sentenceLevelBleuPlusOne(stats) << "\n";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user