diff options
author | Chris Dyer <cdyer@allegro.clab.cs.cmu.edu> | 2014-01-15 23:33:58 -0500 |
---|---|---|
committer | Chris Dyer <cdyer@allegro.clab.cs.cmu.edu> | 2014-01-15 23:33:58 -0500 |
commit | 7f5aa4fbf1165b769265376269e0b46dfbb8b342 (patch) | |
tree | bf1b3a3a3d1089fe6a1eb09a0d739b478f61eed0 /decoder | |
parent | 7a1db9fe7cb79fdb5544a33ddc2f9f3612adf1ae (diff) | |
parent | aa5520768619eb15e0c1c70addbfaff0f150c345 (diff) |
Merge branch 'master' of github.com:redpony/cdec
Diffstat (limited to 'decoder')
-rw-r--r-- | decoder/cdec_ff.cc | 1 | ||||
-rw-r--r-- | decoder/ff_rules.cc | 23 | ||||
-rw-r--r-- | decoder/ff_rules.h | 13 |
3 files changed, 37 insertions, 0 deletions
diff --git a/decoder/cdec_ff.cc b/decoder/cdec_ff.cc index d586c1d1..b2541722 100644 --- a/decoder/cdec_ff.cc +++ b/decoder/cdec_ff.cc @@ -45,6 +45,7 @@ void register_feature_functions() { ff_registry.Register("NgramFeatures", new FFFactory<NgramDetector>()); ff_registry.Register("RuleContextFeatures", new FFFactory<RuleContextFeatures>()); ff_registry.Register("RuleIdentityFeatures", new FFFactory<RuleIdentityFeatures>()); + ff_registry.Register("RuleWordAlignmentFeatures", new FFFactory<RuleWordAlignmentFeatures>()); ff_registry.Register("ParseMatchFeatures", new FFFactory<ParseMatchFeatures>); ff_registry.Register("SoftSyntaxFeatures", new FFFactory<SoftSyntaxFeatures>); ff_registry.Register("SoftSyntaxFeaturesMindist", new FFFactory<SoftSyntaxFeaturesMindist>); diff --git a/decoder/ff_rules.cc b/decoder/ff_rules.cc index 410e083c..7bccf084 100644 --- a/decoder/ff_rules.cc +++ b/decoder/ff_rules.cc @@ -12,6 +12,7 @@ #include "verbose.h" #include "tdict.h" #include "hg.h" +#include "trule.h" using namespace std; @@ -68,6 +69,28 @@ void RuleIdentityFeatures::TraversalFeaturesImpl(const SentenceMetadata& smeta, features->add_value(it->second, 1); } +RuleWordAlignmentFeatures::RuleWordAlignmentFeatures(const std::string& param) { +} + +void RuleWordAlignmentFeatures::PrepareForInput(const SentenceMetadata& smeta) { +} + +void RuleWordAlignmentFeatures::TraversalFeaturesImpl(const SentenceMetadata& smeta, + const Hypergraph::Edge& edge, + const vector<const void*>& ant_contexts, + SparseVector<double>* features, + SparseVector<double>* estimated_features, + void* context) const { + const TRule& rule = *edge.rule_; + ostringstream os; + vector<AlignmentPoint> als = rule.als(); + std::vector<AlignmentPoint>::const_iterator xx = als.begin(); + for (; xx != als.end(); ++xx) { + os << "WA:" << TD::Convert(rule.f_[xx->s_]) << ":" << TD::Convert(rule.e_[xx->t_]); + } + features->add_value(FD::Convert(Escape(os.str())), 1); +} + RuleSourceBigramFeatures::RuleSourceBigramFeatures(const std::string& param) { } diff --git a/decoder/ff_rules.h b/decoder/ff_rules.h index f210dc65..324d7a39 100644 --- a/decoder/ff_rules.h +++ b/decoder/ff_rules.h @@ -24,6 +24,19 @@ class RuleIdentityFeatures : public FeatureFunction { mutable std::map<const TRule*, int> rule2_fid_; }; +class RuleWordAlignmentFeatures : public FeatureFunction { + public: + RuleWordAlignmentFeatures(const std::string& param); + protected: + virtual void TraversalFeaturesImpl(const SentenceMetadata& smeta, + const HG::Edge& edge, + const std::vector<const void*>& ant_contexts, + SparseVector<double>* features, + SparseVector<double>* estimated_features, + void* context) const; + virtual void PrepareForInput(const SentenceMetadata& smeta); +}; + class RuleSourceBigramFeatures : public FeatureFunction { public: RuleSourceBigramFeatures(const std::string& param); |