summaryrefslogtreecommitdiff
path: root/decoder/hg_io.cc
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2012-03-13 09:24:47 +0100
committerPatrick Simianer <p@simianer.de>2012-03-13 09:24:47 +0100
commitef6085e558e26c8819f1735425761103021b6470 (patch)
tree5cf70e4c48c64d838e1326b5a505c8c4061bff4a /decoder/hg_io.cc
parent10a232656a0c882b3b955d2bcfac138ce11e8a2e (diff)
parentdfbc278c1057555fda9312291c8024049e00b7d8 (diff)
merge with upstream
Diffstat (limited to 'decoder/hg_io.cc')
-rw-r--r--decoder/hg_io.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/decoder/hg_io.cc b/decoder/hg_io.cc
index c1c93933..9f0f50fa 100644
--- a/decoder/hg_io.cc
+++ b/decoder/hg_io.cc
@@ -624,3 +624,30 @@ void HypergraphIO::WriteAsCFG(const Hypergraph& hg) {
}
}
+/* Output format:
+ * #vertices
+ * for each vertex in bottom-up topological order:
+ * #downward_edges
+ * 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';
+ for (unsigned int i = 0; i < hg.nodes_.size(); ++i) {
+ const Hypergraph::EdgesVector &edges = hg.nodes_[i].in_edges_;
+ cout << 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] << "] ";
+ } else {
+ cout << TD::Convert(*word) << ' ';
+ }
+ }
+ cout << "||| " << edge.rule_->scores_ << '\n';
+ }
+ }
+}
+