Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAles Tamchyna <a.tamchyna@gmail.com>2012-12-10 16:12:34 +0400
committerAles Tamchyna <a.tamchyna@gmail.com>2012-12-10 16:12:34 +0400
commit598d65bcfd0ce84d153335c60ed75f5213a5ed54 (patch)
treecb08058fd502973c89b01d79bee79a9808b414aa /mert/sentence-bleu.cpp
parented2d1918217233aec230734aed0bcb6177641f50 (diff)
adding a simple command-line utility for computing sentence-level BLEU (+1)
Diffstat (limited to 'mert/sentence-bleu.cpp')
-rw-r--r--mert/sentence-bleu.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/mert/sentence-bleu.cpp b/mert/sentence-bleu.cpp
new file mode 100644
index 000000000..4fd980546
--- /dev/null
+++ b/mert/sentence-bleu.cpp
@@ -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";
+ }
+}