summaryrefslogtreecommitdiff
path: root/decoder/hg_io.cc
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-05-13 03:35:30 +0200
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-05-13 03:35:30 +0200
commit670a8f984fc6d8342180c59ae9e96b0b76f34d3d (patch)
tree9f2ce7eec1a77e56b3bb1ad0ad40f212d7a996b0 /decoder/hg_io.cc
parenteb3ee28dc0eb1d3e5ed01ba0df843be329ae450d (diff)
parent2f64af3e06a518b93f7ca2c30a9d0aeb2c947031 (diff)
Merge remote-tracking branch 'upstream/master'
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';
}
}
}