From 75d0f86f8f949e37c600096accf85d5521940f40 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Wed, 16 May 2012 17:01:21 -0400 Subject: bjam cleanup --- decoder/Jamfile | 7 ++++++- decoder/decoder.cc | 12 ++++++------ decoder/hg.h | 6 +++--- decoder/viterbi.h | 18 +++++++++--------- 4 files changed, 24 insertions(+), 19 deletions(-) (limited to 'decoder') diff --git a/decoder/Jamfile b/decoder/Jamfile index f8112cae..871da4f6 100644 --- a/decoder/Jamfile +++ b/decoder/Jamfile @@ -61,9 +61,14 @@ lib cdec_lib : ../klm/lm//kenlm ..//boost_program_options : . + : : + ..//utils + ..//mteval + ../klm/lm//kenlm + ..//boost_program_options ; -exe cdec : cdec.cc cdec_lib ; +exe cdec : cdec.cc cdec_lib ..//utils ..//mteval ../klm/lm//kenlm ..//boost_program_options ; all_tests [ glob *_test.cc : cfg_test.cc ] : cdec_lib : $(TOP)/decoder/test_data ; diff --git a/decoder/decoder.cc b/decoder/decoder.cc index 4ce2ba86..487c7635 100644 --- a/decoder/decoder.cc +++ b/decoder/decoder.cc @@ -965,14 +965,14 @@ bool DecoderImpl::Decode(const string& input, DecoderObserver* o) { { ReadFile rf(writer.fname_); bool succeeded = HypergraphIO::ReadFromJSON(rf.stream(), &new_hg); - assert(succeeded); + if (!succeeded) abort(); } new_hg.Union(forest); bool succeeded = writer.Write(new_hg, false); - assert(succeeded); + if (!succeeded) abort(); } else { bool succeeded = writer.Write(forest, false); - assert(succeeded); + if (!succeeded) abort(); } } @@ -1052,14 +1052,14 @@ bool DecoderImpl::Decode(const string& input, DecoderObserver* o) { { ReadFile rf(writer.fname_); bool succeeded = HypergraphIO::ReadFromJSON(rf.stream(), &new_hg); - assert(succeeded); + if (!succeeded) abort(); } new_hg.Union(forest); bool succeeded = writer.Write(new_hg, false); - assert(succeeded); + if (!succeeded) abort(); } else { bool succeeded = writer.Write(forest, false); - assert(succeeded); + if (!succeeded) abort(); } } if (aligner_mode && !output_training_vector) diff --git a/decoder/hg.h b/decoder/hg.h index f0ddbb76..dfa4ac6d 100644 --- a/decoder/hg.h +++ b/decoder/hg.h @@ -189,7 +189,7 @@ public: o<<'('; show(o,show_mask); if (indent) o<<'\n'; - for (int i=0;irule_ = rule; edge->tail_nodes_ = tail; edge->id_ = eid; - for (int i = 0; i < edge->tail_nodes_.size(); ++i) + for (unsigned i = 0; i < edge->tail_nodes_.size(); ++i) nodes_[edge->tail_nodes_[i]].out_edges_.push_back(edge->id_); return edge; } diff --git a/decoder/viterbi.h b/decoder/viterbi.h index daee3d7a..3092f6da 100644 --- a/decoder/viterbi.h +++ b/decoder/viterbi.h @@ -32,16 +32,16 @@ typename WeightFunction::Weight Viterbi(const Hypergraph& hg, WeightType* const cur_node_best_weight = &vit_weight[i]; T* const cur_node_best_result = &vit_result[i]; - const int num_in_edges = cur_node.in_edges_.size(); + const unsigned num_in_edges = cur_node.in_edges_.size(); if (num_in_edges == 0) { *cur_node_best_weight = WeightType(1); continue; } Hypergraph::Edge const* edge_best=0; - for (int j = 0; j < num_in_edges; ++j) { + for (unsigned j = 0; j < num_in_edges; ++j) { const Hypergraph::Edge& edge = hg.edges_[cur_node.in_edges_[j]]; WeightType score = weight(edge); - for (int k = 0; k < edge.tail_nodes_.size(); ++k) + for (unsigned k = 0; k < edge.tail_nodes_.size(); ++k) score *= vit_weight[edge.tail_nodes_[k]]; if (!edge_best || *cur_node_best_weight < score) { *cur_node_best_weight = score; @@ -51,7 +51,7 @@ typename WeightFunction::Weight Viterbi(const Hypergraph& hg, assert(edge_best); Hypergraph::Edge const& edgeb=*edge_best; std::vector antsb(edgeb.tail_nodes_.size()); - for (int k = 0; k < edgeb.tail_nodes_.size(); ++k) + for (unsigned k = 0; k < edgeb.tail_nodes_.size(); ++k) antsb[k] = &vit_result[edgeb.tail_nodes_[k]]; traverse(edgeb, antsb, cur_node_best_result); } @@ -101,7 +101,7 @@ struct PathLengthTraversal { int* result) const { (void) edge; *result = 1; - for (int i = 0; i < ants.size(); ++i) *result += *ants[i]; + for (unsigned i = 0; i < ants.size(); ++i) *result += *ants[i]; } }; @@ -120,7 +120,7 @@ struct ELengthTraversal { const std::vector& ants, int* result) const { *result = edge.rule_->ELength() - edge.rule_->Arity(); - for (int i = 0; i < ants.size(); ++i) *result += *ants[i]; + for (unsigned i = 0; i < ants.size(); ++i) *result += *ants[i]; } }; @@ -179,8 +179,8 @@ struct ViterbiPathTraversal { void operator()(const Hypergraph::Edge& edge, std::vector const& ants, Result* result) const { - for (int i = 0; i < ants.size(); ++i) - for (int j = 0; j < ants[i]->size(); ++j) + for (unsigned i = 0; i < ants.size(); ++i) + for (unsigned j = 0; j < ants[i]->size(); ++j) result->push_back((*ants[i])[j]); result->push_back(&edge); } @@ -191,7 +191,7 @@ struct FeatureVectorTraversal { void operator()(Hypergraph::Edge const& edge, std::vector const& ants, Result* result) const { - for (int i = 0; i < ants.size(); ++i) + for (unsigned i = 0; i < ants.size(); ++i) *result+=*ants[i]; *result+=edge.feature_values_; } -- cgit v1.2.3