summaryrefslogtreecommitdiff
path: root/fast/hypergraph.hh
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-07-19 08:30:43 +0200
committerPatrick Simianer <p@simianer.de>2014-07-19 08:30:43 +0200
commitf219bab21c07d02e7e54d557e23387bd93c9ce5f (patch)
tree14a6e2b647a3b1ab11391c154fbcf7c63841f8db /fast/hypergraph.hh
parent6208c48407c359819945730006edf4c402b7ff77 (diff)
hg io
Diffstat (limited to 'fast/hypergraph.hh')
-rw-r--r--fast/hypergraph.hh110
1 files changed, 64 insertions, 46 deletions
diff --git a/fast/hypergraph.hh b/fast/hypergraph.hh
index 68cca19..2e30911 100644
--- a/fast/hypergraph.hh
+++ b/fast/hypergraph.hh
@@ -1,5 +1,4 @@
-#ifndef HYPERGRAPH_HH
-#define HYPERGRAPH_HH
+#pragma once
#include "grammar.hh"
#include "semiring.hh"
@@ -12,8 +11,10 @@
#include <functional>
#include <algorithm>
#include <iterator>
+#include <fstream>
-#include "msgpack-c/include/msgpack.hpp"
+#include "dummyvector.h"
+#include <msgpack.hpp>
using namespace std;
@@ -23,61 +24,78 @@ typedef double weight_t;
namespace Hg {
-class Node;
+struct Node;
-class Edge {
- public:
- Node* head;
- vector<Node*> tails;
- score_t score;
- //Grammar::Rule rule; FIXME
- vector<weight_t> f;
- unsigned int arity;
- unsigned int mark;
+struct Edge {
+ Node* head;
+ vector<Node*> tails;
+ score_t score;
+ string rule; //FIXME
+ DummyVector f; //FIXME
+ unsigned int arity;
+ unsigned int mark;
- bool is_marked();
- friend std::ostream& operator<<(std::ostream& os, const Edge& s);
+ bool is_marked();
+ friend std::ostream& operator<<(std::ostream& os, const Edge& s);
- size_t head_id_;
- vector<size_t> tails_ids_; // node ids
- MSGPACK_DEFINE(head_id_, tails_ids_, score, f, arity);
+ size_t head_id_;
+ vector<size_t> tails_ids_; // node ids
+
+ MSGPACK_DEFINE(head_id_, tails_ids_, score, f, arity);
};
-class Node {
- public:
- size_t id;
- string symbol;
- unsigned short left;
- unsigned short right;
- score_t score;
- vector<Edge*> incoming;
- vector<Edge*> outgoing;
- unsigned int mark;
-
- bool is_marked();
- friend std::ostream& operator<<(std::ostream& os, const Node& n);
-
- vector<size_t> incoming_ids_; // edge ids
- vector<size_t> outgoing_ids_; // edge ids
- MSGPACK_DEFINE(id, symbol, left, right, score, incoming_ids_, outgoing_ids_);
+struct Node {
+ size_t id;
+ string symbol;
+ unsigned short left;
+ unsigned short right;
+ score_t score;
+ vector<Edge*> incoming;
+ vector<Edge*> outgoing;
+ unsigned int mark;
+
+ bool is_marked();
+ friend std::ostream& operator<<(std::ostream& os, const Node& n);
+
+ vector<size_t> incoming_ids_; // edge ids
+ vector<size_t> outgoing_ids_; // edge ids
+ MSGPACK_DEFINE(id, symbol, left, right, score, incoming_ids_, outgoing_ids_);
};
-class Hypergraph {
- public:
- list<Node*> nodes;
- vector<Edge*> edges;
- unordered_map<size_t, Node*> nodes_by_id;
- unsigned int arity;
+struct Hypergraph {
+ list<Node*> nodes;
+ vector<Edge*> edges;
+ unordered_map<size_t, Node*> nodes_by_id;
+ unsigned int arity;
- void reset();
- void add_node(Node* n) { nodes.push_back(n); nodes_by_id[n->id] = n; }
+ void add_node(Node* n) { nodes.push_back(n); nodes_by_id[n->id] = n; }
};
-void topological_sort(list<Node*>& nodes, list<Node*>::iterator root);
-void viterbi(Hypergraph& hg);
+void
+reset();
+
+template<typename Semiring> void
+init(list<Node*>& nodes, list<Node*>::iterator root, Semiring& semiring);
+
+void
+topological_sort(list<Node*>& nodes, list<Node*>::iterator root);
+
+void
+viterbi(Hypergraph& hg);
+
+namespace io {
+void
+read(Hypergraph& hg, string fn);
+
+void
+write(Hypergraph& hg, string fn);
+
+void
+manual(Hypergraph& hg);
} // namespace
-#endif
+
+} // namespace