summaryrefslogtreecommitdiff
path: root/decoder
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-07-04 13:32:22 +0200
committerPatrick Simianer <p@simianer.de>2014-07-04 13:32:22 +0200
commit49671a7f685eb364f7735f4bbda0c05a2dbfe76c (patch)
treeac4a20c1e1112ccf8e2f7b61ea66ca31152ac9c0 /decoder
parent48027e9eeebda4f8506c00ff259fb3426149f85b (diff)
parentd124d4aaa78b52b46f7ac8d7306be342d3405124 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'decoder')
-rw-r--r--decoder/tree2string_translator.cc4
-rw-r--r--decoder/tree_fragment.cc17
-rw-r--r--decoder/tree_fragment.h7
3 files changed, 26 insertions, 2 deletions
diff --git a/decoder/tree2string_translator.cc b/decoder/tree2string_translator.cc
index c9c91a37..adc8dc89 100644
--- a/decoder/tree2string_translator.cc
+++ b/decoder/tree2string_translator.cc
@@ -332,7 +332,9 @@ struct Tree2StringTranslatorImpl {
assert(tail.size() == r->Arity());
HG::Edge* new_edge = hg.AddEdge(r, tail);
new_edge->feature_values_ = r->GetFeatureValues();
- // TODO: set i and j
+ auto& inspan = input_tree.nodes[s.task.input_node_idx].span;
+ new_edge->i_ = inspan.first;
+ new_edge->j_ = inspan.second;
hg.ConnectEdgeToHeadNode(new_edge, &hg.nodes_[node_id]);
}
for (const auto& n : s.future_work) {
diff --git a/decoder/tree_fragment.cc b/decoder/tree_fragment.cc
index aad0b2c4..42f7793a 100644
--- a/decoder/tree_fragment.cc
+++ b/decoder/tree_fragment.cc
@@ -28,12 +28,14 @@ TreeFragment::TreeFragment(const StringPiece& tree, bool allow_frontier_sites) {
unsigned cp = 0, symp = 0, np = 0;
ParseRec(tree, allow_frontier_sites, cp, symp, np, &cp, &symp, &np);
root = nodes.back().lhs;
+ if (!allow_frontier_sites) SetupSpansRec(open - 1, 0);
//cerr << "ROOT: " << TD::Convert(root & ALL_MASK) << endl;
//DebugRec(open - 1, &cerr); cerr << "\n";
}
void TreeFragment::DebugRec(unsigned cur, ostream* out) const {
*out << '(' << TD::Convert(nodes[cur].lhs & ALL_MASK);
+ // *out << "_{" << nodes[cur].span.first << ',' << nodes[cur].span.second << '}';
for (auto& x : nodes[cur].rhs) {
*out << ' ';
if (IsFrontier(x)) {
@@ -47,6 +49,21 @@ void TreeFragment::DebugRec(unsigned cur, ostream* out) const {
*out << ')';
}
+// returns left + the number of terminals rooted at NT cur,
+int TreeFragment::SetupSpansRec(unsigned cur, int left) {
+ int right = left;
+ for (auto& x : nodes[cur].rhs) {
+ if (IsRHS(x)) {
+ right = SetupSpansRec(x & ALL_MASK, right);
+ } else {
+ ++right;
+ }
+ }
+ nodes[cur].span.first = left;
+ nodes[cur].span.second = right;
+ return right;
+}
+
// cp is the character index in the tree
// np keeps track of the nodes (nonterminals) that have been built
// symp keeps track of the terminal symbols that have been built
diff --git a/decoder/tree_fragment.h b/decoder/tree_fragment.h
index 8bb7251a..6b4842ee 100644
--- a/decoder/tree_fragment.h
+++ b/decoder/tree_fragment.h
@@ -43,9 +43,10 @@ inline bool IsTerminal(unsigned x) {
struct TreeFragmentProduction {
TreeFragmentProduction() {}
- TreeFragmentProduction(int nttype, const std::vector<unsigned>& r) : lhs(nttype), rhs(r) {}
+ TreeFragmentProduction(int nttype, const std::vector<unsigned>& r) : lhs(nttype), rhs(r), span(std::make_pair<short,short>(-1,-1)) {}
unsigned lhs;
std::vector<unsigned> rhs;
+ std::pair<short, short> span; // the span of the node (in input, or not set for rules)
};
// this data structure represents a tree or forest
@@ -76,6 +77,10 @@ class TreeFragment {
// np keeps track of the nodes (nonterminals) that have been built
// symp keeps track of the terminal symbols that have been built
void ParseRec(const StringPiece& tree, bool afs, unsigned cp, unsigned symp, unsigned np, unsigned* pcp, unsigned* psymp, unsigned* pnp);
+
+ // used by constructor to set up span indices for logging/alignment purposes
+ int SetupSpansRec(unsigned cur, int left);
+
public:
unsigned root;
unsigned char frontier_sites;