From e01b534f6e1cd455ccc0ca3adfd3174c55c627ac Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Tue, 8 May 2012 14:57:45 -0400 Subject: Output separate files for target hypergraphs. --- decoder/hg_io.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'decoder/hg_io.cc') diff --git a/decoder/hg_io.cc b/decoder/hg_io.cc index d416dbf6..734c2ce8 100644 --- a/decoder/hg_io.cc +++ b/decoder/hg_io.cc @@ -1,5 +1,6 @@ #include "hg_io.h" +#include #include #include @@ -651,22 +652,26 @@ void HypergraphIO::WriteAsCFG(const Hypergraph& hg) { * for each downward edge: * RHS with [vertex_index] for NTs ||| scores */ -void HypergraphIO::WriteTarget(const Hypergraph& hg) { - cout << hg.nodes_.size() << ' ' << hg.edges_.size() << '\n'; +void HypergraphIO::WriteTarget(const std::string &base, unsigned int id, const Hypergraph& hg) { + std::string name(base); + name += '/'; + name += boost::lexical_cast(id); + std::fstream out(name.c_str(), std::fstream::out); + out << hg.nodes_.size() << ' ' << hg.edges_.size() << '\n'; for (unsigned int i = 0; i < hg.nodes_.size(); ++i) { const Hypergraph::EdgesVector &edges = hg.nodes_[i].in_edges_; - cout << edges.size() << '\n'; + out << edges.size() << '\n'; for (unsigned int j = 0; j < edges.size(); ++j) { const Hypergraph::Edge &edge = hg.edges_[edges[j]]; const std::vector &e = edge.rule_->e(); for (std::vector::const_iterator word = e.begin(); word != e.end(); ++word) { if (*word <= 0) { - cout << '[' << edge.tail_nodes_[-*word] << "] "; + out << '[' << edge.tail_nodes_[-*word] << "] "; } else { - cout << TD::Convert(*word) << ' '; + out << TD::Convert(*word) << ' '; } } - cout << "||| " << edge.rule_->scores_ << '\n'; + out << "||| " << edge.rule_->scores_ << '\n'; } } } -- cgit v1.2.3