summaryrefslogtreecommitdiff
path: root/decoder/hg_io.cc
diff options
context:
space:
mode:
Diffstat (limited to 'decoder/hg_io.cc')
-rw-r--r--decoder/hg_io.cc17
1 files changed, 11 insertions, 6 deletions
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 <fstream>
#include <sstream>
#include <iostream>
@@ -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<std::string>(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<WordID> &e = edge.rule_->e();
for (std::vector<WordID>::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';
}
}
}