blob: 28a2fd09cb83752a75ac61e23530c64a0a31efb3 (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include "ns_docscorer.h"
#include <iostream>
#include <cstring>
#include "tdict.h"
#include "filelib.h"
#include "ns.h"
using namespace std;
DocumentScorer::~DocumentScorer() {}
void DocumentScorer::Init(const EvaluationMetric* metric,
const vector<string>& ref_files,
const string& src_file,
bool verbose) {
scorers_.clear();
cerr << "Loading references (" << ref_files.size() << " files)\n";
assert(src_file.empty());
std::vector<ReadFile> ifs(ref_files.begin(),ref_files.end());
for (int i=0; i < ref_files.size(); ++i) ifs[i].Init(ref_files[i]);
char buf[64000];
bool expect_eof = false;
int line=0;
while (ifs[0].get()) {
vector<vector<WordID> > refs(ref_files.size());
for (int i=0; i < ref_files.size(); ++i) {
istream &in=ifs[i].get();
if (in.eof()) break;
in.getline(buf, 64000);
refs[i].clear();
if (strlen(buf) == 0) {
if (in.eof()) {
if (!expect_eof) {
assert(i == 0);
expect_eof = true;
}
break;
}
} else {
TD::ConvertSentence(buf, &refs[i]);
assert(!refs[i].empty());
}
assert(!expect_eof);
}
if (!expect_eof) {
string src_line;
//if (srcrf) {
// getline(srcrf.get(), src_line);
// map<string,string> dummy;
// ProcessAndStripSGML(&src_line, &dummy);
//}
scorers_.push_back(metric->CreateSegmentEvaluator(refs));
++line;
}
}
cerr << "Loaded reference translations for " << scorers_.size() << " sentences.\n";
}
|