summaryrefslogtreecommitdiff
path: root/decoder/scfg_translator.cc
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-15 03:50:05 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-15 03:50:05 +0000
commit27ed3c0fecde089a761ccf718748413bb572a3a4 (patch)
tree69e84990a9c4842ccbb7783f76e73b2dc1e3a7fa /decoder/scfg_translator.cc
parent12b09cc1069ee4401074e0e0f6d8f9c120318aa0 (diff)
oracle bleu refactor
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@259 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'decoder/scfg_translator.cc')
-rw-r--r--decoder/scfg_translator.cc42
1 files changed, 21 insertions, 21 deletions
diff --git a/decoder/scfg_translator.cc b/decoder/scfg_translator.cc
index 32acfd65..bfbe44ee 100644
--- a/decoder/scfg_translator.cc
+++ b/decoder/scfg_translator.cc
@@ -27,7 +27,7 @@ struct SCFGTranslatorImpl {
max_span_limit(conf["scfg_max_span_limit"].as<int>()),
add_pass_through_rules(conf.count("add_pass_through_rules")),
goal(conf["goal"].as<string>()),
- default_nt(conf["scfg_default_nt"].as<string>()),
+ default_nt(conf["scfg_default_nt"].as<string>()),
use_ctf_(conf.count("coarse_to_fine_beam_prune"))
{
if(conf.count("grammar")){
@@ -43,7 +43,7 @@ struct SCFGTranslatorImpl {
cerr << std::endl;
if (conf.count("scfg_extra_glue_grammar")) {
GlueGrammar* g = new GlueGrammar(conf["scfg_extra_glue_grammar"].as<string>());
- g->SetGrammarName("ExtraGlueGrammar");
+ g->SetGrammarName("ExtraGlueGrammar");
grammars.push_back(GrammarPtr(g));
cerr << "Adding glue grammar from file " << conf["scfg_extra_glue_grammar"].as<string>() << endl;
}
@@ -69,11 +69,11 @@ struct SCFGTranslatorImpl {
cerr << "Using coarse-to-fine pruning with " << ctf_iterations_ << " grammar projection(s) and alpha=" << ctf_alpha_ << endl;
cerr << " Coarse beam will be widened " << ctf_num_widenings_ << " times by a factor of " << ctf_wide_alpha_ << " if fine parse fails" << endl;
}
- if (!conf.count("scfg_no_hiero_glue_grammar")){
+ if (!conf.count("scfg_no_hiero_glue_grammar")){
GlueGrammar* g = new GlueGrammar(goal, default_nt, ctf_iterations_);
g->SetGrammarName("GlueGrammar");
grammars.push_back(GrammarPtr(g));
- cerr << "Adding glue grammar for default nonterminal " << default_nt <<
+ cerr << "Adding glue grammar for default nonterminal " << default_nt <<
" and goal nonterminal " << goal << endl;
}
}
@@ -123,9 +123,9 @@ struct SCFGTranslatorImpl {
foreach(int edge_id, goal_node.in_edges_)
RefineRule(forest->edges_[edge_id].rule_, ctf_iterations_);
double alpha = ctf_alpha_;
- bool found_parse;
+ bool found_parse=false;
for (int i=-1; i < ctf_num_widenings_; ++i) {
- cerr << "Coarse-to-fine source parse, alpha=" << alpha << endl;
+ cerr << "Coarse-to-fine source parse, alpha=" << alpha << endl;
found_parse = true;
Hypergraph refined_forest = *forest;
for (int j=0; j < ctf_iterations_; ++j) {
@@ -136,7 +136,7 @@ struct SCFGTranslatorImpl {
if (RefineForest(&refined_forest)) {
cerr << " Refinement succeeded." << endl;
refined_forest.Reweight(weights);
- } else {
+ } else {
cerr << " Refinement failed. Widening beam." << endl;
found_parse = false;
break;
@@ -152,21 +152,21 @@ struct SCFGTranslatorImpl {
if (ctf_exhaustive_){
cerr << "Last resort: refining coarse forest without pruning...";
for (int j=0; j < ctf_iterations_; ++j) {
- if (RefineForest(forest)){
+ if (RefineForest(forest)){
cerr << " Refinement succeeded." << endl;
forest->Reweight(weights);
} else {
cerr << " Refinement failed. No parse found for this sentence." << endl;
return false;
}
- }
- } else
+ }
+ } else
return false;
}
}
return true;
}
-
+
typedef std::pair<int, WordID> StateSplit;
typedef std::pair<StateSplit, int> StateSplitPair;
typedef std::tr1::unordered_map<StateSplit, int, boost::hash<StateSplit> > Split2Node;
@@ -179,17 +179,17 @@ struct SCFGTranslatorImpl {
Hypergraph::Node& coarse_goal_node = *(forest->nodes_.end()-1);
bool refined_goal_node = false;
foreach(Hypergraph::Node& node, forest->nodes_){
- cerr << ".";
+ cerr << ".";
foreach(int edge_id, node.in_edges_) {
Hypergraph::Edge& edge = forest->edges_[edge_id];
std::vector<int> nt_positions;
TRulePtr& coarse_rule_ptr = edge.rule_;
for(int i=0; i< coarse_rule_ptr->f_.size(); ++i){
- if (coarse_rule_ptr->f_[i] < 0)
- nt_positions.push_back(i);
+ if (coarse_rule_ptr->f_[i] < 0)
+ nt_positions.push_back(i);
}
if (coarse_rule_ptr->fine_rules_ == 0) {
- cerr << "Parsing with mixed levels of coarse-to-fine granularity is currently unsupported." <<
+ cerr << "Parsing with mixed levels of coarse-to-fine granularity is currently unsupported." <<
endl << "Could not find refinement for: " << coarse_rule_ptr->AsString() << " on edge " << edge_id << " spanning " << edge.i_ << "," << edge.j_ << endl;
abort();
}
@@ -198,20 +198,20 @@ struct SCFGTranslatorImpl {
Hypergraph::TailNodeVector tail;
for (int pos_i=0; pos_i<nt_positions.size(); ++pos_i){
WordID fine_cat = fine_rule_ptr->f_[nt_positions[pos_i]];
- Split2Node::iterator it =
+ Split2Node::iterator it =
s2n.find(StateSplit(edge.tail_nodes_[pos_i], fine_cat));
- if (it == s2n.end())
+ if (it == s2n.end())
break;
- else
+ else
tail.push_back(it->second);
}
if (tail.size() == nt_positions.size()) {
WordID cat = fine_rule_ptr->lhs_;
- Hypergraph::Edge* new_edge = refined_forest.AddEdge(fine_rule_ptr, tail);
+ Hypergraph::Edge* new_edge = refined_forest.AddEdge(fine_rule_ptr, tail);
new_edge->i_ = edge.i_;
new_edge->j_ = edge.j_;
new_edge->feature_values_ = fine_rule_ptr->GetFeatureValues();
- new_edge->feature_values_.set_value(FD::Convert("LatticeCost"),
+ new_edge->feature_values_.set_value(FD::Convert("LatticeCost"),
edge.feature_values_[FD::Convert("LatticeCost")]);
Hypergraph::Node* head_node;
Split2Node::iterator it = s2n.find(StateSplit(node.id_, cat));
@@ -221,7 +221,7 @@ struct SCFGTranslatorImpl {
splits[node.id_].push_back(cat);
if (&node == &coarse_goal_node)
refined_goal_node = true;
- } else
+ } else
head_node = &(refined_forest.nodes_[it->second]);
refined_forest.ConnectEdgeToHeadNode(new_edge, head_node);
}