diff options
Diffstat (limited to 'decoder/apply_fsa_models.cc')
-rwxr-xr-x | decoder/apply_fsa_models.cc | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/decoder/apply_fsa_models.cc b/decoder/apply_fsa_models.cc index 416b9323..31b2002d 100755 --- a/decoder/apply_fsa_models.cc +++ b/decoder/apply_fsa_models.cc @@ -12,57 +12,66 @@ using namespace std; struct ApplyFsa { - ApplyFsa(const Hypergraph& ih, + ApplyFsa(HgCFG &i, const SentenceMetadata& smeta, const FsaFeatureFunction& fsa, DenseWeightVector const& weights, ApplyFsaBy const& by, - Hypergraph* oh) - :ih(ih),smeta(smeta),fsa(fsa),weights(weights),by(by),oh(oh) + Hypergraph* oh + ) + :hgcfg(i),smeta(smeta),fsa(fsa),weights(weights),by(by),oh(oh) { -// sparse_to_dense(weight_vector,&weights); - Init(); } - void Init() { + void Compute() { if (by.IsBottomUp()) ApplyBottomUp(); else ApplyEarley(); } - void ApplyBottomUp() { - assert(by.IsBottomUp()); - FeatureFunctionFromFsa<FsaFeatureFunctionFwd> buff(&fsa); - buff.Init(); // mandatory to call this (normally factory would do it) - vector<const FeatureFunction*> ffs(1,&buff); - ModelSet models(weights, ffs); - IntersectionConfiguration i(by.BottomUpAlgorithm(),by.pop_limit); - ApplyModelSet(ih,smeta,models,i,oh); - } - void ApplyEarley() { - CFG cfg(ih,true,false,true); - } + void ApplyBottomUp(); + void ApplyEarley(); + CFG const& GetCFG(); private: - const Hypergraph& ih; + CFG cfg; + HgCFG &hgcfg; const SentenceMetadata& smeta; const FsaFeatureFunction& fsa; // WeightVector weight_vector; DenseWeightVector weights; ApplyFsaBy by; Hypergraph* oh; + std::string cfg_out; }; +void ApplyFsa::ApplyBottomUp() +{ + assert(by.IsBottomUp()); + FeatureFunctionFromFsa<FsaFeatureFunctionFwd> buff(&fsa); + buff.Init(); // mandatory to call this (normally factory would do it) + vector<const FeatureFunction*> ffs(1,&buff); + ModelSet models(weights, ffs); + IntersectionConfiguration i(by.BottomUpAlgorithm(),by.pop_limit); + ApplyModelSet(hgcfg.ih,smeta,models,i,oh); +} -void ApplyFsaModels(const Hypergraph& ih, +void ApplyFsa::ApplyEarley() +{ + hgcfg.GiveCFG(cfg); + //TODO: +} + + +void ApplyFsaModels(HgCFG &i, const SentenceMetadata& smeta, const FsaFeatureFunction& fsa, DenseWeightVector const& weight_vector, ApplyFsaBy const& by, Hypergraph* oh) { - ApplyFsa a(ih,smeta,fsa,weight_vector,by,oh); + ApplyFsa a(i,smeta,fsa,weight_vector,by,oh); + a.Compute(); } - namespace { char const* anames[]={ "BU_CUBE", @@ -88,7 +97,7 @@ std::string ApplyFsaBy::all_names() { return o.str(); } -ApplyFsaBy::ApplyFsaBy(std::string const& n, int pop_limit) : pop_limit(pop_limit){ +ApplyFsaBy::ApplyFsaBy(std::string const& n, int pop_limit) : pop_limit(pop_limit) { algorithm=0; std::string uname=toupper(n); while(anames[algorithm] && anames[algorithm] != uname) ++algorithm; |