summaryrefslogtreecommitdiff
path: root/python/cdec/hypergraph.pxi
diff options
context:
space:
mode:
authorChris Dyer <redpony@gmail.com>2014-09-17 12:39:47 -0400
committerChris Dyer <redpony@gmail.com>2014-09-17 12:39:47 -0400
commitc20decbd6b9be8f1a7d567cd72300b4e9582b55c (patch)
tree79c844304f2aa3f42b44236ba755200f4f87b7f6 /python/cdec/hypergraph.pxi
parent3822a2063e36b6ced948e5c22910a373c6c691b2 (diff)
parenta861980460220a31592bdb2e951a55faeebb8c6d (diff)
Merge pull request #51 from wilkeraziz/master
a few minor changes to pycdec
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."""