summaryrefslogtreecommitdiff
path: root/decoder
diff options
context:
space:
mode:
authorChris Dyer <redpony@gmail.com>2014-05-08 21:20:46 -0400
committerChris Dyer <redpony@gmail.com>2014-05-08 21:20:46 -0400
commit3b80feb119dc3c42b1d7137943c86f3c0bfd0119 (patch)
tree0da4e2c17555e090afd0b9db48e803c081a8be7a /decoder
parent0f087998860585e157641ce7bcf3c190e3e43d7c (diff)
better features
Diffstat (limited to 'decoder')
-rw-r--r--decoder/tree2string_translator.cc19
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);
}
}