-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmoses_scorers.cpp
40 lines (32 loc) · 1.03 KB
/
moses_scorers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "moses_scorers.h"
#include "Scorer.h"
#include "ScorerFactory.h"
#include "Types.h"
#include <fstream>
#include <memory>
float score(const std::string& scorerType,
const std::vector<std::string>& refFiles,
std::istream& candidate,
const std::string& scorerConfig,
const std::string& preproc) {
std::unique_ptr<MosesTuning::Scorer> scorer(
MosesTuning::ScorerFactory::getScorer(scorerType, scorerConfig));
scorer->setFilter(preproc);
scorer->setReferenceFiles(refFiles);
std::string hyp;
MosesTuning::ScoreStats sentStats;
std::vector<float> corpStats;
size_t sid = 0;
while(getline(candidate, hyp)) {
scorer->prepareStats(sid, hyp, sentStats);
if(corpStats.size() == 0) {
corpStats = std::vector<float>(sentStats.getArray(), sentStats.getArray() + sentStats.size());
} else {
for(size_t i = 0; i < sentStats.size(); ++i) {
corpStats[i] += sentStats.get(i);
}
}
++sid;
}
return scorer->calculateScore(corpStats);
}