summaryrefslogtreecommitdiff
path: root/decoder/ff_fsa_dynamic.h
diff options
context:
space:
mode:
authorgraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-02 07:57:23 +0000
committergraehl@gmail.com <graehl@gmail.com@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-02 07:57:23 +0000
commit1fc4b6a45c18b52ab2c27eb9a825ad14f31d803b (patch)
tree33eddab63ea60d0b252dc842ebd0c2a8408af40d /decoder/ff_fsa_dynamic.h
parent526efd6515eb9efdcc1fe756c3cec4981ca10186 (diff)
fake tdict names for non-ids, push viterbi cost to root in hg, store as feature. type erased fsa feature via virtual interface. made lexical_cast assume C locale for speed.
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@465 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/ff_fsa_dynamic.h')
-rwxr-xr-xdecoder/ff_fsa_dynamic.h77
1 files changed, 70 insertions, 7 deletions
diff --git a/decoder/ff_fsa_dynamic.h b/decoder/ff_fsa_dynamic.h
index 79672bdc..2703b305 100755
--- a/decoder/ff_fsa_dynamic.h
+++ b/decoder/ff_fsa_dynamic.h
@@ -1,29 +1,92 @@
#ifndef FF_FSA_DYNAMIC_H
#define FF_FSA_DYNAMIC_H
-#include "ff_fsa.h"
+struct SentenceMetadata;
+#include "ff_fsa_data.h"
+#include "hg.h" // can't forward declare nested Hypergraph::Edge class
+#include <sstream>
+
// the type-erased interface
-/*
-struct FsaFeatureFunction {
+
+struct FsaFeatureFunction : public FsaFeatureFunctionData {
+ static const bool simple_phrase_score=false;
virtual int markov_order() const = 0;
- virtual ~FsaFeatureFunction();
+ // see ff_fsa.h - FsaFeatureFunctionBase<Impl> gives you reasonable impls of these if you override just ScanAccum
+ virtual void ScanAccum(SentenceMetadata const& smeta,Hypergraph::Edge const& edge,
+ WordID w,void const* state,void *next_state,Accum *a) const = 0;
+ virtual void ScanPhraseAccum(SentenceMetadata const& smeta,Hypergraph::Edge const & edge,
+ WordID const* i, WordID const* end,
+ void const* state,void *next_state,Accum *accum) const = 0;
+ virtual void ScanPhraseAccumOnly(SentenceMetadata const& smeta,Hypergraph::Edge const& edge,
+ WordID const* i, WordID const* end,
+ void const* state,Accum *accum) const = 0;
+ virtual void *ScanPhraseAccumBounce(SentenceMetadata const& smeta,Hypergraph::Edge const& edge,WordID const* i, WordID const* end,void *cs,void *ns,Accum *accum) const = 0;
+
+ virtual int early_score_words(SentenceMetadata const& smeta,Hypergraph::Edge const& edge,WordID const* i, WordID const* end,Accum *accum) const { return 0; }
+ virtual std::string usage(bool param,bool verbose) const {
+ return FeatureFunction::usage_helper("unnamed_dynamic_fsa_feature","","",param,verbose);
+ }
+
+ virtual void print_state(std::ostream &o,void const*state) const {
+ FsaFeatureFunctionData::print_state(o,state);
+ }
+ //end_phrase()
+ virtual ~FsaFeatureFunction() {}
+
+ // no need to override:
+ std::string describe_state(void const* state) const {
+ std::ostringstream o;
+ print_state(o,state);
+ return o.str();
+ }
};
// conforming to above interface, type erases FsaImpl
// you might be wondering: why do this? answer: it's cool, and it means that the bottom-up ff over ff_fsa wrapper doesn't go through multiple layers of dynamic dispatch
+// usage: struct My : public FsaFeatureFunctionDynamic<My>
template <class Impl>
struct FsaFeatureFunctionDynamic : public FsaFeatureFunction {
+ static const bool simple_phrase_score=Impl::simple_phrase_score;
Impl& d() { return static_cast<Impl&>(*this); }
Impl const& d() { return static_cast<Impl const&>(*this); }
int markov_order() const { return d().markov_order(); }
+
+ virtual void ScanAccum(SentenceMetadata const& smeta,Hypergraph::Edge const& edge,
+ WordID w,void const* state,void *next_state,Accum *a) const {
+ return d().ScanAccum(smeta,edge,w,state,next_state,a);
+ }
+
+ virtual void ScanPhraseAccum(SentenceMetadata const& smeta,Hypergraph::Edge const & edge,
+ WordID const* i, WordID const* end,
+ void const* state,void *next_state,Accum *a) const {
+ return d().ScanPhraseAccum(smeta,edge,i,end,state,next_state,a);
+ }
+
+ virtual void ScanPhraseAccumOnly(SentenceMetadata const& smeta,Hypergraph::Edge const& edge,
+ WordID const* i, WordID const* end,
+ void const* state,Accum *a) const {
+ return d().ScanPhraseAccumOnly(smeta,edge,i,end,state,a);
+
+ virtual void *ScanPhraseAccumBounce(SentenceMetadata const& smeta,Hypergraph::Edge const& edge,WordID const* i, WordID const* end,void *cs,void *ns,Accum *a) const {
+ return d().ScanPhraseAccumBounce(smeta,edge,i,end,cs,ns,a);
+ }
+
+ virtual int early_score_words(SentenceMetadata const& smeta,Hypergraph::Edge const& edge,WordID const* i, WordID const* end,Accum *accum) const {
+ return d().early_score_words(smeta,edge,i,end,accum);
+ }
+
+ virtual std::string usage(bool param,bool verbose) const {
+ return Impl::usage(param,verbose);
+ }
+
+ virtual void print_state(std::ostream &o,void const*state) const {
+ return d().print_state(o,state);
+ }
};
-//TODO: wrap every method in concrete fsaff and declare in interface above.
//TODO: combine 2 (or N) FsaFeatureFunction (type erased)
-*/
-
#endif