summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-11-10 19:02:56 -0500
committerChris Dyer <cdyer@cs.cmu.edu>2012-11-10 19:02:56 -0500
commit8d084476522ff267a25b8faa58e48879b5d0cdb6 (patch)
treeda67e70976bf337a7b37f82972f028b7aa6ed6ea
parenteb03a413713c070edf07e466575e0f58085aa258 (diff)
support multi-reference references
-rw-r--r--mteval/ns_docscorer.cc22
-rw-r--r--mteval/ns_docscorer.h10
2 files changed, 23 insertions, 9 deletions
diff --git a/mteval/ns_docscorer.cc b/mteval/ns_docscorer.cc
index f72ad115..83bd1a29 100644
--- a/mteval/ns_docscorer.cc
+++ b/mteval/ns_docscorer.cc
@@ -11,11 +11,14 @@ using namespace std;
DocumentScorer::~DocumentScorer() {}
+DocumentScorer::DocumentScorer() {}
+
void DocumentScorer::Init(const EvaluationMetric* metric,
const vector<string>& ref_files,
const string& src_file,
bool verbose) {
scorers_.clear();
+ static const WordID kDIV = TD::Convert("|||");
if (verbose) cerr << "Loading references (" << ref_files.size() << " files)\n";
assert(src_file.empty());
std::vector<ReadFile> ifs(ref_files.begin(),ref_files.end());
@@ -23,13 +26,14 @@ void DocumentScorer::Init(const EvaluationMetric* metric,
char buf[64000];
bool expect_eof = false;
int line=0;
+ vector<WordID> tmp;
+ vector<vector<WordID> > refs;
while (ifs[0].get()) {
- vector<vector<WordID> > refs(ref_files.size());
+ refs.clear();
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) {
@@ -38,9 +42,17 @@ void DocumentScorer::Init(const EvaluationMetric* metric,
}
break;
}
- } else {
- TD::ConvertSentence(buf, &refs[i]);
- assert(!refs[i].empty());
+ } else { // read a line from a reference file
+ tmp.clear();
+ TD::ConvertSentence(buf, &tmp);
+ unsigned last = 0;
+ for (unsigned j = 0; j < tmp.size(); ++j) {
+ if (tmp[j] == kDIV) {
+ refs.push_back(vector<WordID>(tmp.begin() + last, tmp.begin() + j));
+ last = j + 1;
+ }
+ }
+ refs.push_back(vector<WordID>(tmp.begin() + last, tmp.end()));
}
assert(!expect_eof);
}
diff --git a/mteval/ns_docscorer.h b/mteval/ns_docscorer.h
index a5757258..b3c28fc9 100644
--- a/mteval/ns_docscorer.h
+++ b/mteval/ns_docscorer.h
@@ -10,21 +10,23 @@ struct SegmentEvaluator;
class DocumentScorer {
public:
~DocumentScorer();
- DocumentScorer() { }
+ DocumentScorer();
DocumentScorer(const EvaluationMetric* metric,
const std::vector<std::string>& ref_files,
const std::string& src_file = "",
bool verbose=false) {
Init(metric,ref_files,src_file,verbose);
}
+ DocumentScorer(const EvaluationMetric* metric,
+ const std::string& src_ref_composite_file);
+ int size() const { return scorers_.size(); }
+ const SegmentEvaluator* operator[](size_t i) const { return scorers_[i].get(); }
+ private:
void Init(const EvaluationMetric* metric,
const std::vector<std::string>& ref_files,
const std::string& src_file = "",
bool verbose=false);
- int size() const { return scorers_.size(); }
- const SegmentEvaluator* operator[](size_t i) const { return scorers_[i].get(); }
- private:
std::vector<boost::shared_ptr<SegmentEvaluator> > scorers_;
};