summaryrefslogtreecommitdiff
path: root/decoder/ff_spans.cc
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2011-02-07 15:03:39 -0500
committerChris Dyer <cdyer@cs.cmu.edu>2011-02-07 15:03:39 -0500
commit7dfee211a81fdb42f250ba793a469ed8a2dcc3bf (patch)
tree0dedb1b4f7cee9d3063816b7da23403ebd43737d /decoder/ff_spans.cc
parent60daa3601c30c8cc77c93e761a48e5c0a665c3d5 (diff)
more span-level features
Diffstat (limited to 'decoder/ff_spans.cc')
-rw-r--r--decoder/ff_spans.cc29
1 files changed, 27 insertions, 2 deletions
diff --git a/decoder/ff_spans.cc b/decoder/ff_spans.cc
index 6fa49d45..b454c9fd 100644
--- a/decoder/ff_spans.cc
+++ b/decoder/ff_spans.cc
@@ -25,7 +25,10 @@ void SpanFeatures::TraversalFeaturesImpl(const SentenceMetadata& smeta,
assert(edge.j_ < end_span_ids_.size());
assert(edge.j_ >= 0);
features->set_value(end_span_ids_[edge.j_], 1);
-
+ assert(edge.i_ < beg_span_ids_.size());
+ assert(edge.i_ >= 0);
+ features->set_value(beg_span_ids_[edge.i_], 1);
+ features->set_value(span_feats_(edge.i_,edge.j_), 1);
if (edge.Arity() == 2) {
const TRule& rule = *edge.rule_;
if (rule.f_[0] == kS && rule.f_[1] == kX) {
@@ -36,15 +39,37 @@ void SpanFeatures::TraversalFeaturesImpl(const SentenceMetadata& smeta,
void SpanFeatures::PrepareForInput(const SentenceMetadata& smeta) {
const Lattice& lattice = smeta.GetSourceLattice();
- WordID eos = TD::Convert("</s>");
+ const WordID eos = TD::Convert("</s>");
+ const WordID bos = TD::Convert("<s>");
+ beg_span_ids_.resize(lattice.size() + 1);
end_span_ids_.resize(lattice.size() + 1);
for (int i = 0; i <= lattice.size(); ++i) {
WordID word = eos;
+ WordID bword = bos;
+ if (i > 0)
+ bword = lattice[i-1][0].label;
if (i < lattice.size())
word = lattice[i][0].label; // rather arbitrary for lattices
ostringstream sfid;
sfid << "ES:" << TD::Convert(word);
end_span_ids_[i] = FD::Convert(sfid.str());
+ ostringstream bfid;
+ bfid << "BS:" << TD::Convert(bword);
+ beg_span_ids_[i] = FD::Convert(bfid.str());
}
+ span_feats_.resize(lattice.size() + 1, lattice.size() + 1);
+ for (int i = 0; i <= lattice.size(); ++i) {
+ WordID bword = bos;
+ if (i > 0)
+ bword = lattice[i-1][0].label;
+ for (int j = 0; j <= lattice.size(); ++j) {
+ WordID word = eos;
+ if (j < lattice.size())
+ word = lattice[j][0].label;
+ ostringstream pf;
+ pf << "SS:" << TD::Convert(bword) << "_" << TD::Convert(word);
+ span_feats_(i,j) = FD::Convert(pf.str());
+ }
+ }
}