summaryrefslogtreecommitdiff
path: root/decoder/ff_fsa_dynamic.h
diff options
context:
space:
mode:
Diffstat (limited to 'decoder/ff_fsa_dynamic.h')
-rwxr-xr-xdecoder/ff_fsa_dynamic.h26
1 files changed, 20 insertions, 6 deletions
diff --git a/decoder/ff_fsa_dynamic.h b/decoder/ff_fsa_dynamic.h
index 2703b305..2a26676d 100755
--- a/decoder/ff_fsa_dynamic.h
+++ b/decoder/ff_fsa_dynamic.h
@@ -2,13 +2,14 @@
#define FF_FSA_DYNAMIC_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
+//FIXME: diamond inheritance problem. make a copy of the fixed data? or else make the dynamic version not wrap but rather be templated CRTP base (yuck)
struct FsaFeatureFunction : public FsaFeatureFunctionData {
static const bool simple_phrase_score=false;
virtual int markov_order() const = 0;
@@ -25,10 +26,11 @@ struct FsaFeatureFunction : public FsaFeatureFunctionData {
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 {
+ virtual std::string usage_v(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);
}
@@ -45,12 +47,12 @@ struct FsaFeatureFunction : public FsaFeatureFunctionData {
// 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>
+// usage: typedef FsaFeatureFunctionDynamic<MyFsa> MyFsaDyn;
template <class Impl>
-struct FsaFeatureFunctionDynamic : public FsaFeatureFunction {
+struct FsaFeatureFunctionDynamic : public FsaFeatureFunction,Impl {
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); }
+ Impl const& d() const { return static_cast<Impl const&>(*this); }
int markov_order() const { return d().markov_order(); }
virtual void ScanAccum(SentenceMetadata const& smeta,Hypergraph::Edge const& edge,
@@ -68,6 +70,7 @@ struct FsaFeatureFunctionDynamic : public FsaFeatureFunction {
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);
@@ -77,15 +80,26 @@ struct FsaFeatureFunctionDynamic : public FsaFeatureFunction {
return d().early_score_words(smeta,edge,i,end,accum);
}
- virtual std::string usage(bool param,bool verbose) const {
+ static std::string usage(bool param,bool verbose) {
+ return Impl::usage(param,verbose);
+ }
+
+ std::string usage_v(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);
}
+
+ FsaFeatureFunctionDynamic(std::string const& param) : Impl(param) {
+ d().sync_to_=(FsaFeatureFunction*)this;
+ d().sync();
+ }
+
};
+
//TODO: combine 2 (or N) FsaFeatureFunction (type erased)