diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-21 20:12:44 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-21 20:12:44 +0000 |
commit | d66f09f1348f9805149b9eab4940cb9c00742984 (patch) | |
tree | 3ac00e5359b08d27163a28ed5608953ff6bc589c | |
parent | 59fdf560bfcb324a08971bbd3c0ebbbb39c6409c (diff) |
Score::Clone() via CRTP
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@360 ec762483-ff6d-05da-a07a-a48fb63a330f
-rw-r--r-- | decoder/cdec.cc | 14 | ||||
-rwxr-xr-x | decoder/ff_fsa.h | 3 | ||||
-rw-r--r-- | decoder/sparse_vector.h | 3 | ||||
-rw-r--r-- | vest/aer_scorer.cc | 2 | ||||
-rw-r--r-- | vest/comb_scorer.cc | 2 | ||||
-rw-r--r-- | vest/scorer.cc | 4 | ||||
-rw-r--r-- | vest/scorer.h | 12 | ||||
-rw-r--r-- | vest/ter.cc | 2 |
8 files changed, 31 insertions, 11 deletions
diff --git a/decoder/cdec.cc b/decoder/cdec.cc index cc0b1434..6fb6d5a1 100644 --- a/decoder/cdec.cc +++ b/decoder/cdec.cc @@ -154,7 +154,7 @@ void InitCommandLine(int argc, char** argv, OracleBleu &ob, po::variables_map* c ob.AddOptions(&opts); po::options_description clo("Command line options"); clo.add_options() - ("config,c", po::value<string>(), "Configuration file") + ("config,c", po::value<vector<string> >(), "Configuration file(s) - latest has priority") ("help,h", "Print this help message and exit") ("usage,u", po::value<string>(), "Describe a feature function type") ("compgen", "Print just option names suitable for bash command line completion builtin 'compgen'") @@ -172,10 +172,14 @@ void InitCommandLine(int argc, char** argv, OracleBleu &ob, po::variables_map* c } ShowBanner(); if (conf.count("config")) { - const string cfg = str("config",conf); - cerr << "Configuration file: " << cfg << endl; - ifstream config(cfg.c_str()); - po::store(po::parse_config_file(config, dconfig_options), conf); + typedef vector<string> Cs; + Cs cs=conf["config"].as<Cs>(); + for (int i=0;i<cs.size();++i) { + string cfg=cs[i]; + cerr << "Configuration file: " << cfg << endl; + ifstream config(cfg.c_str()); + po::store(po::parse_config_file(config, dconfig_options), conf); + } } po::notify(conf); diff --git a/decoder/ff_fsa.h b/decoder/ff_fsa.h index 2ffd6ef8..0b60ff81 100755 --- a/decoder/ff_fsa.h +++ b/decoder/ff_fsa.h @@ -32,7 +32,8 @@ struct FsaFeatureFunction { // regular bottom up scorer from Fsa feature template <class Impl> -struct FeatureFunctionFromFsa { +struct FeatureFunctionFromFsa : public FeatureFunction,Impl { + FeatureFunctionFromFsa( }; diff --git a/decoder/sparse_vector.h b/decoder/sparse_vector.h index 5e785210..9894d662 100644 --- a/decoder/sparse_vector.h +++ b/decoder/sparse_vector.h @@ -1,5 +1,8 @@ #ifndef _SPARSE_VECTOR_H_ #define _SPARSE_VECTOR_H_ +/* TODO: use dense_hash_map for sparsevector + use SparseVectorList (pair smallvector) for feat funcs / hypergraphs (you rarely need random access; just append a feature to the list) +*/ /* hack: index 0 never gets printed because cdyer is creative and efficient. features which have no weight got feature dict id 0, see, and the models all clobered that value. nobody wants to see it. except that vlad is also creative and efficient and stored the oracle bleu there. */ diff --git a/vest/aer_scorer.cc b/vest/aer_scorer.cc index 81ffae76..25b58b5e 100644 --- a/vest/aer_scorer.cc +++ b/vest/aer_scorer.cc @@ -9,7 +9,7 @@ using namespace std; -class AERScore : public Score { +class AERScore : public ScoreBase<AERScore> { friend class AERScorer; public: AERScore() : num_matches(), num_predicted(), num_in_ref() {} diff --git a/vest/comb_scorer.cc b/vest/comb_scorer.cc index a921aa4d..9fc37868 100644 --- a/vest/comb_scorer.cc +++ b/vest/comb_scorer.cc @@ -4,7 +4,7 @@ using namespace std; -class BLEUTERCombinationScore : public Score { +class BLEUTERCombinationScore : public ScoreBase<BLEUTERCombinationScore> { friend class BLEUTERCombinationScorer; public: ~BLEUTERCombinationScore(); diff --git a/vest/scorer.cc b/vest/scorer.cc index 05269a3b..5671de38 100644 --- a/vest/scorer.cc +++ b/vest/scorer.cc @@ -87,7 +87,7 @@ float SentenceScorer::ComputeRefLength(const Sentence &hyp) const { const std::string* SentenceScorer::GetSource() const { return NULL; } -class SERScore : public Score { +class SERScore : public ScoreBase<SERScore> { friend class SERScorer; public: SERScore() : correct(0), total(0) {} @@ -151,7 +151,7 @@ class SERScorer : public SentenceScorer { vector<vector<WordID> > refs_; }; -class BLEUScore : public Score { +class BLEUScore : public ScoreBase<BLEUScore> { friend class BLEUScorerBase; public: BLEUScore(int n) : correct_ngram_hit_counts(float(0),n), hyp_ngram_counts(float(0),n) { diff --git a/vest/scorer.h b/vest/scorer.h index 0d90f378..0c8b380f 100644 --- a/vest/scorer.h +++ b/vest/scorer.h @@ -46,6 +46,18 @@ class Score : public boost::intrusive_refcount<Score> { virtual void Encode(std::string* out) const = 0; static ScoreP GetZero(ScoreType type); static ScoreP GetOne(ScoreType type); + virtual ScoreP Clone() const = 0; +protected: + Score() { } // we define these explicitly because refcount is noncopyable + Score(Score const& o) { } +}; + +//TODO: make sure default copy ctors for score types do what we want. +template <class Derived> +struct ScoreBase : public Score { + ScoreP Clone() const { + return ScoreP(new Derived(dynamic_cast<Derived const&>(*this))); + } }; class SentenceScorer { diff --git a/vest/ter.cc b/vest/ter.cc index 8c8494ad..cacc5b00 100644 --- a/vest/ter.cc +++ b/vest/ter.cc @@ -412,7 +412,7 @@ class TERScorerImpl { } }; -class TERScore : public Score { +class TERScore : public ScoreBase<TERScore> { friend class TERScorer; public: |