summaryrefslogtreecommitdiff
path: root/python/cdec/hypergraph.pxi
diff options
context:
space:
mode:
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."""