summaryrefslogtreecommitdiff
path: root/fast/hypergraph.hh
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-07-09 15:26:00 +0200
committerPatrick Simianer <p@simianer.de>2014-07-09 15:26:00 +0200
commit567f2bd17c05d31cd8a9b9d351f9030cddf53cb7 (patch)
tree390d1c28de381849ae9331b433695f5fb389d440 /fast/hypergraph.hh
parenta3f9fb73ffe4f942851ff496a72ca2445ffd9e0a (diff)
c++ implementation
Diffstat (limited to 'fast/hypergraph.hh')
-rw-r--r--fast/hypergraph.hh76
1 files changed, 76 insertions, 0 deletions
diff --git a/fast/hypergraph.hh b/fast/hypergraph.hh
new file mode 100644
index 0000000..6e53045
--- /dev/null
+++ b/fast/hypergraph.hh
@@ -0,0 +1,76 @@
+#ifndef HYPERGRAPH_HH
+#define HYPERGRAPH_HH
+
+#include "grammar.hh"
+#include "semiring.hh"
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <vector>
+#include <map>
+#include <functional>
+#include <algorithm>
+
+using namespace std;
+
+typedef double score_t;
+typedef double weight_t;
+
+namespace Hg {
+
+
+class Node;
+
+class Hyperedge {
+ public:
+ Node* head;
+ vector<Node*> tails;
+ score_t score;
+ vector<weight_t> f;
+ unsigned int mark;
+ //Grammar::Rule rule; FIXME
+ unsigned int arity_;
+
+ unsigned int arity();
+ bool is_marked();
+ string s();
+
+};
+
+
+class Node {
+ public:
+ unsigned int id;
+ string symbol;
+ unsigned int left;
+ unsigned int right;
+ score_t score;
+ vector<Hyperedge*> outgoing;
+ vector<Hyperedge*> incoming;
+
+ string s();
+};
+
+
+
+class Hypergraph {
+ public:
+ vector<Node*> nodes;
+ vector<Hyperedge*> edges;
+ unsigned int arity_;
+ map<unsigned int, Node*> nodes_by_id;
+
+ unsigned int arity();
+ void reset();
+ string s();
+ string json_s();
+};
+
+vector<Node*> topological_sort(vector<Node*>& nodes);
+void viterbi(vector<Node*>& nodes, map<unsigned int, Hg::Node*> nodes_by_id, Node* root);
+
+
+} // namespace
+
+#endif
+