summaryrefslogtreecommitdiff
path: root/decoder/tree2string_translator.cc
diff options
context:
space:
mode:
authorChris Dyer <redpony@gmail.com>2014-03-27 00:07:41 -0400
committerChris Dyer <redpony@gmail.com>2014-03-27 00:07:41 -0400
commit26ad3172c1c5712e877e05c01db3d03f50a5d98b (patch)
tree12a5d7d1bc099a1ca4bf6446b9f9b54d0427d421 /decoder/tree2string_translator.cc
parent8e9652cf595aafa4acc7d67de967afdbca71ac75 (diff)
breadth first iterator for tree fragment
Diffstat (limited to 'decoder/tree2string_translator.cc')
-rw-r--r--decoder/tree2string_translator.cc32
1 files changed, 12 insertions, 20 deletions
diff --git a/decoder/tree2string_translator.cc b/decoder/tree2string_translator.cc
index ac9c0d74..1c249836 100644
--- a/decoder/tree2string_translator.cc
+++ b/decoder/tree2string_translator.cc
@@ -13,25 +13,6 @@
using namespace std;
-// root: S
-// A implication: (S [A] *INCOMPLETE*
-// B implication: (S [A] [B] *INCOMPLETE*
-// *0* implication: (S _[A] [B])
-// a implication: (S (A a *INCOMPLETE* [B])
-// a implication: (S (A a a *INCOMPLETE* [B])
-// *0* implication: (S (A a a) _[B])
-// D implication: (S (A a a) (B [D] *INCOMPLETE*)
-// *0* implication: (S (A a a) (B _[D]))
-// d implication: (S (A a a) (B (D d *INCOMPLETE*))
-// *0* implication: (S (A a a) (B (D d)))
-// --there are no further outgoing links possible--
-
-// root: S
-// A implication: (S [A] *INCOMPLETE*
-// B implication: (S [A] [B] *INCOMPLETE*
-// *0* implication: (S _[A] [B])
-// *0* implication: (S [A] _[B])
-// b implication: (S [A] (B b *INCOMPLETE*))
struct Tree2StringGrammarNode {
map<unsigned, Tree2StringGrammarNode> next;
string rules;
@@ -44,8 +25,19 @@ void ReadTree2StringGrammar(istream* in, unordered_map<unsigned, Tree2StringGram
size_t pos = line.find("|||");
assert(pos != string::npos);
assert(pos > 3);
- if (line[pos - 1] == ' ') --pos;
+ unsigned xc = 0;
+ while (line[pos - 1] == ' ') { --pos; xc++; }
cdec::TreeFragment rule_src(line.substr(0, pos), true);
+ Tree2StringGrammarNode* cur = &roots[rule_src.root];
+ for (auto sym : rule_src)
+ cur = &cur->next[sym];
+ pos += 3 + xc;
+ while(line[pos] == ' ') { ++pos; }
+ size_t pos2 = line.find("|||", pos);
+ assert(pos2 != string::npos);
+ while (line[pos2 - 1] == ' ') { --pos2; }
+ cur->rules = line.substr(pos, pos2 - pos);
+ cerr << "OUTPUT = '" << cur->rules << "'\n";
}
}