From 0bc21f0fbcf5e060c1a9b249527e094436a383d8 Mon Sep 17 00:00:00 2001 From: mjdenkowski Date: Wed, 28 Aug 2013 18:07:42 -0400 Subject: Stream support for MIRA (part of realtime) --- mteval/scorer.cc | 25 +++++++++++++++++++++++++ mteval/scorer.h | 26 ++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) (limited to 'mteval') diff --git a/mteval/scorer.cc b/mteval/scorer.cc index a83b9e2f..ced0cadf 100644 --- a/mteval/scorer.cc +++ b/mteval/scorer.cc @@ -595,6 +595,7 @@ void DocScorer::Init( const vector& ref_files, const string& src_file, bool verbose) { scorers_.clear(); + this->type = type; // TODO stop using valarray, start using ReadFile cerr << "Loading references (" << ref_files.size() << " files)\n"; ReadFile srcrf; @@ -644,3 +645,27 @@ void DocScorer::Init( cerr << "Loaded reference translations for " << scorers_.size() << " sentences.\n"; } +void DocStreamScorer::Init( + const ScoreType type, + const vector& ref_files, + const string& src_file, bool verbose) { + scorers_.clear(); + // AER not supported in stream mode + assert(type != AER); + this->type = type; + vector > refs(1); + string src_line; + // Empty reference 0 + TD::ConvertSentence("", &refs[0]); + scorers_.push_back(ScorerP(SentenceScorer::CreateSentenceScorer(type, refs, src_line))); + // Reference 1 starts empty, updated as needed + scorers_.push_back(ScorerP(SentenceScorer::CreateSentenceScorer(type, refs, src_line))); +} + +void DocStreamScorer::update(const std::string& ref) { + scorers_.pop_back(); + vector > refs(1); + string src_line; + TD::ConvertSentence(ref, &refs[0]); + scorers_.push_back(ScorerP(SentenceScorer::CreateSentenceScorer(this->type, refs, src_line))); +} diff --git a/mteval/scorer.h b/mteval/scorer.h index 8bd76982..56c39a7d 100644 --- a/mteval/scorer.h +++ b/mteval/scorer.h @@ -83,10 +83,11 @@ class SentenceScorer { //TODO: should be able to GetOne GetZero without supplying sentence (just type) class DocScorer { + friend class DocStreamScorer; public: - ~DocScorer(); + virtual ~DocScorer(); DocScorer() { } - void Init(const ScoreType type, + virtual void Init(const ScoreType type, const std::vector& ref_files, const std::string& src_file = "", bool verbose=false @@ -102,9 +103,30 @@ class DocScorer { int size() const { return scorers_.size(); } ScorerP operator[](size_t i) const { return scorers_[i]; } + virtual void update(const std::string& ref) {} private: + ScoreType type; std::vector scorers_; }; +class DocStreamScorer : public DocScorer { + public: + void Init(const ScoreType type, + const std::vector& ref_files, + const std::string& src_file = "", + bool verbose=false + ); + DocStreamScorer(const ScoreType type, + const std::vector& ref_files, + const std::string& src_file = "", + bool verbose=false + ) + { + Init(type,ref_files,src_file,verbose); + } + ScorerP operator[](size_t i); + int size(); + void update(const std::string& ref); +}; #endif -- cgit v1.2.3