diff options
author | Chris Dyer <redpony@gmail.com> | 2014-05-08 21:20:46 -0400 |
---|---|---|
committer | Chris Dyer <redpony@gmail.com> | 2014-05-08 21:20:46 -0400 |
commit | 80778dd022150ea4d654cd1952a3f09684a5cfbb (patch) | |
tree | ffcb4279252b4cb841da35b47c84da42d6a57b54 /decoder | |
parent | 6d3490279cace80e202f277f9f3214edd09da8ad (diff) |
better features
Diffstat (limited to 'decoder')
-rw-r--r-- | decoder/tree2string_translator.cc | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/decoder/tree2string_translator.cc b/decoder/tree2string_translator.cc index fafb0d97..38daeeb5 100644 --- a/decoder/tree2string_translator.cc +++ b/decoder/tree2string_translator.cc @@ -158,7 +158,11 @@ struct Tree2StringTranslatorImpl { } void CreatePassThroughRules(const cdec::TreeFragment& tree) { + static const int kFIDlex = FD::Convert("PassThrough_Lexical"); + static const int kFIDabs = FD::Convert("PassThrough_Abstract"); + static const int kFIDmix = FD::Convert("PassThrough_Mix"); static const int kFID = FD::Convert("PassThrough"); + static unordered_map<int, int> pntfid; root.resize(root.size() + 1); root.back().reset(new Tree2StringGrammarNode); ++remove_grammars; @@ -167,14 +171,24 @@ struct Tree2StringTranslatorImpl { vector<int> rhse, rhsf; int ntc = 0; int lhs = -(prod.lhs & cdec::ALL_MASK); + int &ntfid = pntfid[lhs]; + if (!ntfid) { + ostringstream fos; + fos << "PassThrough:" << TD::Convert(-lhs); + ntfid = FD::Convert(fos.str()); + } + bool has_lex = false; + bool has_nt = false; os << '(' << TD::Convert(-lhs); for (auto& sym : prod.rhs) { os << ' '; if (cdec::IsTerminal(sym)) { + has_lex = true; os << TD::Convert(sym); rhse.push_back(sym); rhsf.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); @@ -192,7 +206,12 @@ struct Tree2StringTranslatorImpl { cur = &cur->next[sym]; TRulePtr rule(new TRule(rhse, rhsf, lhs)); rule->ComputeArity(); + rule->scores_.set_value(ntfid, 1.0); rule->scores_.set_value(kFID, 1.0); + if (has_lex && has_nt) + rule->scores_.set_value(kFIDmix, 1.0); + else if (has_lex) rule->scores_.set_value(kFIDlex, 1.0); + else if (has_nt) rule->scores_.set_value(kFIDabs, 1.0); cur->rules.push_back(rule); } } |