diff options
Diffstat (limited to 'python/src/hypergraph.pxd')
-rw-r--r-- | python/src/hypergraph.pxd | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/python/src/hypergraph.pxd b/python/src/hypergraph.pxd index 656b1d47..886660bf 100644 --- a/python/src/hypergraph.pxd +++ b/python/src/hypergraph.pxd @@ -1,6 +1,7 @@ from libcpp.string cimport string from libcpp.vector cimport vector from utils cimport * +from grammar cimport TRule from lattice cimport Lattice cdef extern from "decoder/hg.h": @@ -8,27 +9,33 @@ cdef extern from "decoder/hg.h": EdgeMask(int size) bint& operator[](int) + cdef cppclass HypergraphEdge "Hypergraph::Edge": + int id_ + int head_node_ # position in hg.nodes_ + SmallVector[unsigned] tail_nodes_ # positions in hg.nodes_ + shared_ptr[TRule] rule_ + FastSparseVector[weight_t] feature_values_ + prob_t edge_prob_ # weights.dot(feature_values_) + # typically source span: + short int i_ + short int j_ + + ctypedef HypergraphEdge const_HypergraphEdge "const Hypergraph::Edge" + + cdef cppclass HypergraphNode "Hypergraph::Node": + int id_ + WordID cat_ # non-terminal category if <0, 0 if not set + vector[int] in_edges_ # positions in hg.edge_prob_ + vector[int] out_edges_ # positions in hg.edge_prob_ + + ctypedef HypergraphNode const_HypergraphNode "const Hypergraph::Node" + cdef cppclass Hypergraph: - cppclass Edge: - int id_ - int head_node_ # position in hg.nodes_ - SmallVector[unsigned] tail_nodes_ # positions in hg.nodes_ - #TRulePtr rule_ - FastSparseVector[weight_t] feature_values_ - LogVal[double] edge_prob_ - short int i_ - short int j_ - short int prev_i_ - short int prev_j_ - cppclass Node: - int id_ - WordID cat_ - WordID NT() - vector[Edge] in_edges_ - vector[Edge] out_edges_ Hypergraph(Hypergraph) - vector[Node] nodes_ - vector[Edge] edges_ + vector[HypergraphNode] nodes_ + vector[HypergraphEdge] edges_ + int GoalNode() + double NumberOfPaths() void Reweight(vector[weight_t]& weights) void Reweight(FastSparseVector& weights) bint PruneInsideOutside(double beam_alpha, @@ -39,14 +46,15 @@ cdef extern from "decoder/hg.h": bint safe_inside) cdef extern from "decoder/viterbi.h": - LogVal[double] ViterbiESentence(Hypergraph& hg, vector[WordID]* trans) + prob_t ViterbiESentence(Hypergraph& hg, vector[WordID]* trans) string ViterbiETree(Hypergraph& hg) - LogVal[double] ViterbiFSentence(Hypergraph& hg, vector[WordID]* trans) + prob_t ViterbiFSentence(Hypergraph& hg, vector[WordID]* trans) string ViterbiFTree(Hypergraph& hg) FastSparseVector[weight_t] ViterbiFeatures(Hypergraph& hg) FastSparseVector[weight_t] ViterbiFeatures(Hypergraph& hg, FastSparseVector[weight_t]* weights, bint fatal_dotprod_disagreement) + string JoshuaVisualizationString(Hypergraph& hg) cdef extern from "decoder/hg_io.h" namespace "HypergraphIO": bint ReadFromJSON(istream* inp, Hypergraph* out) @@ -62,8 +70,8 @@ cdef extern from "decoder/hg_intersect.h" namespace "HG": cdef extern from "decoder/hg_sampler.h" namespace "HypergraphSampler": cdef cppclass Hypothesis: vector[WordID] words - FastSparseVector[double] fmap - LogVal[double] model_score + FastSparseVector[weight_t] fmap + prob_t model_score void sample_hypotheses(Hypergraph& hg, unsigned n, MT19937* rng, @@ -71,3 +79,6 @@ cdef extern from "decoder/hg_sampler.h" namespace "HypergraphSampler": cdef extern from "decoder/csplit.h" namespace "CompoundSplit": int GetFullWordEdgeIndex(Hypergraph& forest) + +cdef extern from "decoder/inside_outside.h": + prob_t InsideOutside "InsideOutside<prob_t, EdgeProb, SparseVector<prob_t>, EdgeFeaturesAndProbWeightFunction>" (Hypergraph& hg, FastSparseVector[prob_t]* result) |