From ddd99766d069c5ce5d41da304d7ba613657ee564 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Sat, 17 May 2014 19:04:31 -0400 Subject: fix unique check --- decoder/tree2string_translator.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'decoder') diff --git a/decoder/tree2string_translator.cc b/decoder/tree2string_translator.cc index 8d624820..7b37887e 100644 --- a/decoder/tree2string_translator.cc +++ b/decoder/tree2string_translator.cc @@ -167,7 +167,7 @@ struct Tree2StringTranslatorImpl { root.resize(root.size() + 1); root.back().reset(new Tree2StringGrammarNode); ++remove_grammars; - unordered_set,boost::hash>> unique_rule_check; + unordered_set,boost::hash>> unique_rule_check; for (auto& prod : tree.nodes) { int ntc = 0; int lhs = -(prod.lhs & cdec::ALL_MASK); @@ -179,9 +179,8 @@ struct Tree2StringTranslatorImpl { } // check for duplicate rule in tree - vector key = prod.rhs; + vector key; key.push_back(prod.lhs); - if (!unique_rule_check.insert(key).second) continue; bool has_lex = false; bool has_nt = false; @@ -195,16 +194,19 @@ struct Tree2StringTranslatorImpl { os << TD::Convert(sym); rhse.push_back(sym); rhsf.push_back(sym); + key.push_back(sym); } else { has_nt = true; unsigned id = tree.nodes[sym & cdec::ALL_MASK].lhs & cdec::ALL_MASK; os << '[' << TD::Convert(id) << ']'; rhsf.push_back(-id); rhse.push_back(-ntc); + key.push_back(-id); ++ntc; } } os << ')'; + if (!unique_rule_check.insert(key).second) continue; cdec::TreeFragment rule_src(os.str(), true); Tree2StringGrammarNode* cur = root.back().get(); // do we need all transducer states here??? a list??? no pass through rules??? -- cgit v1.2.3