summaryrefslogtreecommitdiff
path: root/python/cdec/hypergraph.pxi
diff options
context:
space:
mode:
authorWilker Aziz <will.aziz@gmail.com>2014-09-17 15:54:42 +0100
committerWilker Aziz <will.aziz@gmail.com>2014-09-17 15:54:42 +0100
commita861980460220a31592bdb2e951a55faeebb8c6d (patch)
tree79c844304f2aa3f42b44236ba755200f4f87b7f6 /python/cdec/hypergraph.pxi
parent3822a2063e36b6ced948e5c22910a373c6c691b2 (diff)
scaling weights, return dot and fmap from sampling, iterate over the
terminal spans in a rule
Diffstat (limited to 'python/cdec/hypergraph.pxi')
-rw-r--r--python/cdec/hypergraph.pxi15
1 files changed, 15 insertions, 0 deletions
diff --git a/python/cdec/hypergraph.pxi b/python/cdec/hypergraph.pxi
index 1e0a1903..16a68a00 100644
--- a/python/cdec/hypergraph.pxi
+++ b/python/cdec/hypergraph.pxi
@@ -152,6 +152,21 @@ cdef class Hypergraph:
yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8')
finally:
del hypos
+
+ def sample_hypotheses(self, unsigned n):
+ """hg.sample_string(n) -> Sample of n hypotheses from the hypergraph.
+ Generates (sample_string, dot, fmap)"""
+ cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]()
+ cdef SparseVector fmap = None
+ hypergraph.sample_hypotheses(self.hg[0], n, self._rng(), hypos)
+ cdef unsigned k
+ try:
+ for k in range(hypos.size()):
+ fmap = SparseVector.__new__(SparseVector)
+ fmap.vector = new FastSparseVector[weight_t](hypos[0][k].fmap)
+ yield unicode(GetString(hypos[0][k].words).c_str(), 'utf8'), hypos[0][k].model_score.as_float(), fmap
+ finally:
+ del hypos
def sample_trees(self, unsigned n):
"""hg.sample_trees(n) -> Sample of n trees from the hypergraph."""