From a429a0f0f510751b842b7161f5e1c8feab05fc1b Mon Sep 17 00:00:00 2001 From: graehl Date: Mon, 19 Jul 2010 21:33:17 +0000 Subject: shared_ptr for ReadFile and doc_scorer; init ds to GetOne() in oracle git-svn-id: https://ws10smt.googlecode.com/svn/trunk@322 ec762483-ff6d-05da-a07a-a48fb63a330f --- vest/scorer.h | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'vest/scorer.h') diff --git a/vest/scorer.h b/vest/scorer.h index 9c8aebcc..cc6b7335 100644 --- a/vest/scorer.h +++ b/vest/scorer.h @@ -1,8 +1,8 @@ #ifndef SCORER_H_ #define SCORER_H_ - #include #include +#include #include "wordid.h" @@ -16,6 +16,7 @@ std::string StringFromScoreType(ScoreType st); class Score { public: + typedef boost::shared_ptr ScoreP; virtual ~Score(); virtual float ComputeScore() const = 0; virtual float ComputePartialScore() const =0; @@ -35,13 +36,24 @@ class Score { // to another score results in no score change // under any circumstances virtual void Encode(std::string* out) const = 0; + static Score* GetZero(ScoreType type); + static Score* GetOne(ScoreType type); }; class SentenceScorer { public: + typedef boost::shared_ptr ScoreP; + typedef boost::shared_ptr ScorerP; typedef std::vector Sentence; + typedef std::vector Sentences; + std::string desc; + Sentences refs; + SentenceScorer(std::string desc="SentenceScorer_unknown", Sentences const& refs=Sentences()) : desc(desc),refs(refs) { } + std::string verbose_desc() const; virtual float ComputeRefLength(const Sentence& hyp) const; // default: avg of refs.length virtual ~SentenceScorer(); + virtual Score* GetOne() const; + virtual Score* GetZero() const; void ComputeErrorSurface(const ViterbiEnvelope& ve, ErrorSurface* es, const ScoreType type, const Hypergraph& hg) const; virtual Score* ScoreCandidate(const Sentence& hyp) const = 0; virtual Score* ScoreCCandidate(const Sentence& hyp) const =0; @@ -57,14 +69,21 @@ class DocScorer { public: ~DocScorer(); DocScorer() { } - DocScorer( - const ScoreType type, - const std::vector& ref_files, - const std::string& src_file = ""); + void Init(const ScoreType type, + const std::vector& ref_files, + const std::string& src_file = ""); + DocScorer(const ScoreType type, + const std::vector& ref_files, + const std::string& src_file = "") + { + Init(type,ref_files,src_file); + } + int size() const { return scorers_.size(); } - const SentenceScorer* operator[](size_t i) const { return scorers_[i]; } + typedef boost::shared_ptr ScorerP; + ScorerP operator[](size_t i) const { return scorers_[i]; } private: - std::vector scorers_; + std::vector scorers_; }; #endif -- cgit v1.2.3