summaryrefslogtreecommitdiff
path: root/decoder
diff options
context:
space:
mode:
Diffstat (limited to 'decoder')
-rw-r--r--decoder/ff_spans.cc29
-rw-r--r--decoder/ff_spans.h1
2 files changed, 28 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());
+ }
+ }
}
diff --git a/decoder/ff_spans.h b/decoder/ff_spans.h
index 588956c9..0446d062 100644
--- a/decoder/ff_spans.h
+++ b/decoder/ff_spans.h
@@ -21,6 +21,7 @@ class SpanFeatures : public FeatureFunction {
const int kX;
Array2D<int> span_feats_;
std::vector<int> end_span_ids_;
+ std::vector<int> beg_span_ids_;
};
#endif