summaryrefslogtreecommitdiff
path: root/decoder/apply_fsa_models.cc
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-07 03:41:32 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-07 03:41:32 +0000
commit5c40dcfe323dbf95a16a995588a77f393d42749c (patch)
tree025f1c5f0add6b134f4173c475b0a2321288fb14 /decoder/apply_fsa_models.cc
parentaaac9f8ee73ba59b72609af9a78b167312a6dac7 (diff)
apply fsa models (so far only by bottom up) in cdec
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@487 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/apply_fsa_models.cc')
-rwxr-xr-xdecoder/apply_fsa_models.cc102
1 files changed, 102 insertions, 0 deletions
diff --git a/decoder/apply_fsa_models.cc b/decoder/apply_fsa_models.cc
new file mode 100755
index 00000000..27773b0d
--- /dev/null
+++ b/decoder/apply_fsa_models.cc
@@ -0,0 +1,102 @@
+#include "apply_fsa_models.h"
+#include "hg.h"
+#include "ff_fsa_dynamic.h"
+#include "feature_vector.h"
+#include "stringlib.h"
+#include "apply_models.h"
+#include <stdexcept>
+#include <cassert>
+
+using namespace std;
+
+struct ApplyFsa {
+ ApplyFsa(const Hypergraph& ih,
+ const SentenceMetadata& smeta,
+ const FsaFeatureFunction& fsa,
+ DenseWeightVector const& weights,
+ ApplyFsaBy const& cfg,
+ Hypergraph* oh)
+ :ih(ih),smeta(smeta),fsa(fsa),weights(weights),cfg(cfg),oh(oh)
+ {
+// sparse_to_dense(weight_vector,&weights);
+ Init();
+ }
+ void Init() {
+ ApplyBottomUp();
+ //TODO: implement l->r
+ }
+ void ApplyBottomUp() {
+ assert(cfg.IsBottomUp());
+ vector<const FeatureFunction*> ffs;
+ ModelSet models(weights, ffs);
+ IntersectionConfiguration i(cfg.BottomUpAlgorithm(),cfg.pop_limit);
+ ApplyModelSet(ih,smeta,models,i,oh);
+ }
+private:
+ const Hypergraph& ih;
+ const SentenceMetadata& smeta;
+ const FsaFeatureFunction& fsa;
+// WeightVector weight_vector;
+ DenseWeightVector weights;
+ ApplyFsaBy cfg;
+ Hypergraph* oh;
+};
+
+
+void ApplyFsaModels(const Hypergraph& ih,
+ const SentenceMetadata& smeta,
+ const FsaFeatureFunction& fsa,
+ DenseWeightVector const& weight_vector,
+ ApplyFsaBy const& cfg,
+ Hypergraph* oh)
+{
+ ApplyFsa a(ih,smeta,fsa,weight_vector,cfg,oh);
+}
+
+
+namespace {
+char const* anames[]={
+ "BU_CUBE",
+ "BU_FULL",
+ "EARLEY",
+ 0
+};
+}
+
+//TODO: named enum type in boost?
+
+std::string ApplyFsaBy::name() const {
+ return anames[algorithm];
+}
+
+std::string ApplyFsaBy::all_names() {
+ std::ostringstream o;
+ for (int i=0;i<N_ALGORITHMS;++i) {
+ assert(anames[i]);
+ if (i) o<<' ';
+ o<<anames[i];
+ }
+ return o.str();
+}
+
+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;
+ if (!anames[algorithm])
+ throw std::runtime_error("Unknown ApplyFsaBy type: "+n+" - legal types: "+all_names());
+}
+
+ApplyFsaBy::ApplyFsaBy(int i, int pop_limit) : pop_limit(pop_limit) {
+ assert (i>=0);
+ assert (i<N_ALGORITHMS);
+ algorithm=i;
+}
+
+int ApplyFsaBy::BottomUpAlgorithm() const {
+ assert(IsBottomUp());
+ return algorithm==BU_CUBE ?
+ IntersectionConfiguration::CUBE
+ :IntersectionConfiguration::FULL;
+}
+