diff options
author | graehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-10 10:02:04 +0000 |
---|---|---|
committer | graehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-10 10:02:04 +0000 |
commit | 32154b45828f05add1db7c89752ef4220c0fdf16 (patch) | |
tree | fa99e4d4847a89d41b464e9ae3c9aacf611e5500 /decoder/apply_fsa_models.h | |
parent | 43db0573b15719d48b89b3a1ad2828036d008560 (diff) |
cdec --cfg_output=-
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@499 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/apply_fsa_models.h')
-rwxr-xr-x | decoder/apply_fsa_models.h | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/decoder/apply_fsa_models.h b/decoder/apply_fsa_models.h index 3dce5e82..0227664a 100755 --- a/decoder/apply_fsa_models.h +++ b/decoder/apply_fsa_models.h @@ -1,8 +1,10 @@ #ifndef _APPLY_FSA_MODELS_H_ #define _APPLY_FSA_MODELS_H_ +#include <string> #include <iostream> #include "feature_vector.h" +#include "cfg.h" struct FsaFeatureFunction; struct Hypergraph; @@ -34,12 +36,56 @@ struct ApplyFsaBy { static std::string all_names(); // space separated }; +// in case you might want the CFG whether or not you apply FSA models: +struct HgCFG { + HgCFG(Hypergraph const& ih) : ih(ih) { have_cfg=false; } + Hypergraph const& ih; + CFG cfg; + bool have_cfg; + void InitCFG(CFG &to) { + to.Init(ih,true,false,true); + } + + CFG &GetCFG() + { + if (!have_cfg) { + have_cfg=true; + InitCFG(cfg); + } + return cfg; + } + void GiveCFG(CFG &to) { + if (!have_cfg) + InitCFG(to); + else { + have_cfg=false; + to.Clear(); + to.Swap(cfg); + } + } + CFG const& GetCFG() const { + assert(have_cfg); + return cfg; + } +}; + -void ApplyFsaModels(const Hypergraph& in, +void ApplyFsaModels(HgCFG &hg_or_cfg_in, const SentenceMetadata& smeta, const FsaFeatureFunction& fsa, DenseWeightVector const& weights, // pre: in is weighted by these (except with fsa featval=0 before this) ApplyFsaBy const& cfg, Hypergraph* out); +inline void ApplyFsaModels(Hypergraph const& ih, + const SentenceMetadata& smeta, + const FsaFeatureFunction& fsa, + DenseWeightVector const& weights, // pre: in is weighted by these (except with fsa featval=0 before this) + ApplyFsaBy const& cfg, + Hypergraph* out) { + HgCFG i(ih); + ApplyFsaModels(i,smeta,fsa,weights,cfg,out); +} + + #endif |