diff options
Diffstat (limited to 'decoder')
-rw-r--r-- | decoder/cdec_ff.cc | 1 | ||||
-rw-r--r-- | decoder/ff_wordalign.cc | 36 | ||||
-rw-r--r-- | decoder/ff_wordalign.h | 16 |
3 files changed, 53 insertions, 0 deletions
diff --git a/decoder/cdec_ff.cc b/decoder/cdec_ff.cc index 91646253..ca5334e9 100644 --- a/decoder/cdec_ff.cc +++ b/decoder/cdec_ff.cc @@ -55,6 +55,7 @@ void register_feature_functions() { ff_registry.Register("Tagger_BigramIdentity", new FFFactory<Tagger_BigramIdentity>); ff_registry.Register("LexicalPairIdentity", new FFFactory<LexicalPairIdentity>); ff_registry.Register("OutputIdentity", new FFFactory<OutputIdentity>); + ff_registry.Register("InputIdentity", new FFFactory<InputIdentity>); ff_registry.Register("LexicalTranslationTrigger", new FFFactory<LexicalTranslationTrigger>); } diff --git a/decoder/ff_wordalign.cc b/decoder/ff_wordalign.cc index b4981961..f8b8060c 100644 --- a/decoder/ff_wordalign.cc +++ b/decoder/ff_wordalign.cc @@ -574,3 +574,39 @@ void BlunsomSynchronousParseHack::TraversalFeaturesImpl(const SentenceMetadata& SetStateMask(it->second, it->second + yield.size(), state); } +InputIdentity::InputIdentity(const std::string& param) {} + +void InputIdentity::FireFeature(WordID src, + SparseVector<double>* features) const { + int& fid = fmap_[src]; + if (!fid) { + static map<WordID, WordID> escape; + if (escape.empty()) { + escape[TD::Convert("=")] = TD::Convert("__EQ"); + escape[TD::Convert(";")] = TD::Convert("__SC"); + escape[TD::Convert(",")] = TD::Convert("__CO"); + } + if (escape.count(src)) src = escape[src]; + ostringstream os; + os << "S:" << TD::Convert(src); + fid = FD::Convert(os.str()); + } + features->set_value(fid, 1.0); +} + +void InputIdentity::TraversalFeaturesImpl(const SentenceMetadata& smeta, + const Hypergraph::Edge& edge, + const std::vector<const void*>& ant_contexts, + SparseVector<double>* features, + SparseVector<double>* estimated_features, + void* context) const { + const vector<WordID>& fw = edge.rule_->f_; + for (int i = 0; i < fw.size(); ++i) { + const WordID& f = fw[i]; + if (f > 0) FireFeature(f, features); + } +} + + + + diff --git a/decoder/ff_wordalign.h b/decoder/ff_wordalign.h index 0754d70e..30ddf7a1 100644 --- a/decoder/ff_wordalign.h +++ b/decoder/ff_wordalign.h @@ -234,4 +234,20 @@ class BlunsomSynchronousParseHack : public FeatureFunction { mutable std::vector<std::vector<WordID> > refs_; }; +class InputIdentity : public FeatureFunction { + public: + InputIdentity(const std::string& param); + protected: + virtual void TraversalFeaturesImpl(const SentenceMetadata& smeta, + const Hypergraph::Edge& edge, + const std::vector<const void*>& ant_contexts, + SparseVector<double>* features, + SparseVector<double>* estimated_features, + void* context) const; + private: + void FireFeature(WordID src, + SparseVector<double>* features) const; + mutable Class2FID fmap_; +}; + #endif |