diff options
author | Chris Dyer <redpony@gmail.com> | 2014-05-17 17:53:53 -0400 |
---|---|---|
committer | Chris Dyer <redpony@gmail.com> | 2014-05-17 17:53:53 -0400 |
commit | d1de1bb3fe271ce2f90a5885d70eddb859dd2354 (patch) | |
tree | f73310cfff98f83091d540925f99bd1a1a597c31 | |
parent | 7df4ea789cdb4ec3948d4d133389ba2300f99fa8 (diff) |
check for duplicates when creating pass through rules
-rw-r--r-- | decoder/tree2string_translator.cc | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/decoder/tree2string_translator.cc b/decoder/tree2string_translator.cc index 101ed21c..8d624820 100644 --- a/decoder/tree2string_translator.cc +++ b/decoder/tree2string_translator.cc @@ -167,9 +167,8 @@ struct Tree2StringTranslatorImpl { root.resize(root.size() + 1); root.back().reset(new Tree2StringGrammarNode); ++remove_grammars; + unordered_set<vector<unsigned>,boost::hash<vector<unsigned>>> unique_rule_check; for (auto& prod : tree.nodes) { - ostringstream os; - vector<int> rhse, rhsf; int ntc = 0; int lhs = -(prod.lhs & cdec::ALL_MASK); int &ntfid = pntfid[lhs]; @@ -178,8 +177,16 @@ struct Tree2StringTranslatorImpl { fos << "PassThrough:" << TD::Convert(-lhs); ntfid = FD::Convert(fos.str()); } + + // check for duplicate rule in tree + vector<unsigned> key = prod.rhs; + key.push_back(prod.lhs); + if (!unique_rule_check.insert(key).second) continue; + bool has_lex = false; bool has_nt = false; + vector<int> rhse, rhsf; + ostringstream os; os << '(' << TD::Convert(-lhs); for (auto& sym : prod.rhs) { os << ' '; |