From 684db46e977bca456e02e677d22ba5e4a33ae6ce Mon Sep 17 00:00:00 2001 From: graehl Date: Tue, 27 Jul 2010 05:00:07 +0000 Subject: set fsa features() properly git-svn-id: https://ws10smt.googlecode.com/svn/trunk@433 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/ff_fsa.h | 20 ++++++++++---------- decoder/ff_lm.cc | 1 + decoder/ff_lm_fsa.h | 2 ++ 3 files changed, 13 insertions(+), 10 deletions(-) (limited to 'decoder') diff --git a/decoder/ff_fsa.h b/decoder/ff_fsa.h index 45837f2c..a5563511 100755 --- a/decoder/ff_fsa.h +++ b/decoder/ff_fsa.h @@ -66,6 +66,16 @@ usage: see ff_sample_fsa.h or ff_lm_fsa.h template struct FsaFeatureFunctionBase { + // CALL 1 of these MANUALLY (because feature name(s) may depend on param, it's not done in ctor) + void Init(std::string const& fname="") { + fid_=FD::Convert(fname.empty()?name():fname); + InitHaveFid(); + } + Features features_; + void InitHaveFid() { + features_=FeatureFunction::single_feature(fid_); + } + Impl const& d() const { return static_cast(*this); } Impl & d() { return static_cast(*this); } protected: @@ -81,16 +91,6 @@ protected: end_phrase_=singleton_sentence(single); } - // CALL 1 of these MANUALLY (because feature name(s) may depend on param, it's not done in ctor) - void InitFidNamed(std::string const& fname="") { - fid_=FD::Convert(name.empty()?name():fname); - Init(); - } - Features features_; - void Init() { - features_=FeatureFunction::single_feature(fid_); - } - inline void static to_state(void *state,char const* begin,char const* end) { std::memcpy(state,begin,end-begin); } diff --git a/decoder/ff_lm.cc b/decoder/ff_lm.cc index 3d81a599..75778756 100644 --- a/decoder/ff_lm.cc +++ b/decoder/ff_lm.cc @@ -594,6 +594,7 @@ void LanguageModelFsa::set_ngram_order(int i) { LanguageModelFsa::LanguageModelFsa(string const& param) { int lmorder; pimpl_ = make_lm_impl(param,&lmorder,&fid_); + InitHaveFid(); floor_=pimpl_->floor_; set_ngram_order(lmorder); } diff --git a/decoder/ff_lm_fsa.h b/decoder/ff_lm_fsa.h index c2c0972e..c1d875eb 100755 --- a/decoder/ff_lm_fsa.h +++ b/decoder/ff_lm_fsa.h @@ -39,6 +39,7 @@ struct LanguageModelFsa : public FsaFeatureFunctionBase { //post: [left,e] are the seen left words return e; } + template void ScanPhraseAccum(SentenceMetadata const& /* smeta */,const Hypergraph::Edge&edge,WordID const* begin,WordID const* end,void const* old_st,void *new_st,Accum *a) const { if (begin==end) return; // otherwise w/ shortening it's possible to end up with no words at all. @@ -73,6 +74,7 @@ struct LanguageModelFsa : public FsaFeatureFunctionBase { FSALMDBGnl(edge); Add(p,a); } + template void ScanAccum(SentenceMetadata const& /* smeta */,const Hypergraph::Edge& /* edge */,WordID w,void const* old_st,void *new_st,Accum *a) const { if (!ctxlen_) { -- cgit v1.2.3