summaryrefslogtreecommitdiff
path: root/decoder/hg_io.cc
diff options
context:
space:
mode:
authorKenneth Heafield <kenlm@kheafield.com>2012-02-12 16:46:46 -0500
committerKenneth Heafield <kenlm@kheafield.com>2012-02-12 16:46:46 -0500
commitfeab7be095f6454f9ce3021190939ca64bf41e62 (patch)
treeea665f86d7d798b19951e4f0a84af4e22cc98ed1 /decoder/hg_io.cc
parent51ddc7d2f2086908ea8a194a68225e0289f930d5 (diff)
Target-side only output format
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..0283ec3c 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() << '\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';
+ }
+ }
+}
+