diff options
author | Chris Dyer <prguest11@taipan.cs> | 2012-04-16 19:39:36 +0100 |
---|---|---|
committer | Chris Dyer <prguest11@taipan.cs> | 2012-04-16 19:39:36 +0100 |
commit | b0d1a4f0c9718412691f279b9092f18073cf5094 (patch) | |
tree | 9aa2dd9c44b89e77d305dd1aeeb580a98fdb6984 /rst_parser | |
parent | cb0523471caff98a2ec89a3657c1385b53529c8d (diff) |
feature extraction helper
Diffstat (limited to 'rst_parser')
-rw-r--r-- | rst_parser/arc_factored.cc | 21 | ||||
-rw-r--r-- | rst_parser/arc_factored.h | 5 |
2 files changed, 25 insertions, 1 deletions
diff --git a/rst_parser/arc_factored.cc b/rst_parser/arc_factored.cc index 44e769b8..34c689f4 100644 --- a/rst_parser/arc_factored.cc +++ b/rst_parser/arc_factored.cc @@ -12,6 +12,27 @@ using namespace std; using namespace std::tr1; using namespace boost; +void EdgeSubset::ExtractFeatures(const TaggedSentence& sentence, + const std::vector<boost::shared_ptr<ArcFeatureFunction> >& ffs, + SparseVector<double>* features) const { + SparseVector<weight_t> efmap; + for (int i = 0; i < ffs.size(); ++i) { + const ArcFeatureFunction& ff= *ffs[i]; + for (int j = 0; j < h_m_pairs.size(); ++j) { + efmap.clear(); + ff.EgdeFeatures(sentence, h_m_pairs[j].first, + h_m_pairs[j].second, + &efmap); + (*features) += efmap; + } + for (int j = 0; j < roots.size(); ++j) { + efmap.clear(); + ff.EgdeFeatures(sentence, -1, roots[j], &efmap); + (*features) += efmap; + } + } +} + void ArcFactoredForest::ExtractFeatures(const TaggedSentence& sentence, const std::vector<boost::shared_ptr<ArcFeatureFunction> >& ffs) { for (int i = 0; i < ffs.size(); ++i) { diff --git a/rst_parser/arc_factored.h b/rst_parser/arc_factored.h index 4de38b66..a271c8d4 100644 --- a/rst_parser/arc_factored.h +++ b/rst_parser/arc_factored.h @@ -17,14 +17,17 @@ struct TaggedSentence { std::vector<WordID> pos; }; +struct ArcFeatureFunction; struct EdgeSubset { EdgeSubset() {} std::vector<short> roots; // unless multiroot trees are supported, this // will have a single member std::vector<std::pair<short, short> > h_m_pairs; // h,m start at 0 + void ExtractFeatures(const TaggedSentence& sentence, + const std::vector<boost::shared_ptr<ArcFeatureFunction> >& ffs, + SparseVector<double>* features) const; }; -struct ArcFeatureFunction; class ArcFactoredForest { public: ArcFactoredForest() : num_words_() {} |