From 6c43d8b7788e7c334d98fc937c2754fc946e3cc4 Mon Sep 17 00:00:00 2001
From: Patrick Simianer
Date: Mon, 16 Nov 2015 17:22:39 +0100
Subject: sv_path
---
src/fast_weaver.cc | 3 ++-
src/hypergraph.cc | 25 +++++++++++++++++++++++++
src/hypergraph.hh | 3 +++
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/src/fast_weaver.cc b/src/fast_weaver.cc
index bdf21f8..a520d0b 100644
--- a/src/fast_weaver.cc
+++ b/src/fast_weaver.cc
@@ -20,7 +20,8 @@ main(int argc, char** argv)
// viterbi
clock_t begin_viterbi = clock();
Hg::Path p;
- Hg::viterbi_path(hg, p);
+ Hg::sv_path(hg, p);
+ exit(1);
vector s;
Hg::derive(p, p.back()->head, s);
for (auto it: s)
diff --git a/src/hypergraph.cc b/src/hypergraph.cc
index 0a965d0..6ec8441 100644
--- a/src/hypergraph.cc
+++ b/src/hypergraph.cc
@@ -97,6 +97,31 @@ viterbi_path(Hypergraph& hg, Path& p)
}
}
+void
+sv_path(Hypergraph& hg, Path& p)
+{
+ list::iterator root = \
+ find_if(hg.nodes.begin(), hg.nodes.end(), \
+ [](Node* n) { return n->incoming.size() == 0; });
+ //list::iterator root = hg.nodes.begin();
+
+ Hg::topological_sort(hg.nodes, root);
+ // ^^^ FIXME do I need to do this when reading from file?
+
+ for (const auto it: hg.nodes)
+ it->score = 0;
+ (**root).score = 1.0;
+
+ for (auto n: hg.nodes) {
+ Edge* best_edge;
+ bool best = false;
+ for (auto e: n->incoming) {
+ e->rule->f->repr(cout);
+ cout << endl;
+ }
+ }
+}
+
void
derive(const Path& p, const Node* cur, vector& carry)
diff --git a/src/hypergraph.hh b/src/hypergraph.hh
index d1217a5..7a268c3 100644
--- a/src/hypergraph.hh
+++ b/src/hypergraph.hh
@@ -83,6 +83,9 @@ typedef vector Path;
void
viterbi_path(Hypergraph& hg, Path& p);
+void
+sv_path(Hypergraph& hg, Path& p);
+
void
derive(const Path& p, const Node* cur, vector& carry);
--
cgit v1.2.3