#pragma once #include "grammar.hh" #include "semiring.hh" #include #include #include #include #include #include #include #include #include #include #include "dummyvector.h" #include using namespace std; typedef double score_t; typedef double weight_t; namespace Hg { struct Node; struct Edge { Node* head; vector 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); size_t head_id_; vector tails_ids_; // node ids MSGPACK_DEFINE(head_id_, tails_ids_, score, f, arity); }; struct Node { size_t id; string symbol; unsigned short left; unsigned short right; score_t score; vector incoming; vector outgoing; unsigned int mark; bool is_marked(); friend std::ostream& operator<<(std::ostream& os, const Node& n); vector incoming_ids_; // edge ids vector outgoing_ids_; // edge ids MSGPACK_DEFINE(id, symbol, left, right, score, incoming_ids_, outgoing_ids_); }; struct Hypergraph { list nodes; vector edges; unordered_map nodes_by_id; unsigned int arity; void add_node(Node* n) { nodes.push_back(n); nodes_by_id[n->id] = n; } }; void reset(); template void init(list& nodes, list::iterator root, Semiring& semiring); void topological_sort(list& nodes, list::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 } // namespace