diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2012-08-07 23:22:44 -0400 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2012-08-07 23:22:44 -0400 |
commit | 6ba464f6d78e38970d5467b10ce1114f4d7feaa4 (patch) | |
tree | 15614a9ee68a2f0b5d05025752b0dd2bc94ae67d /python/src/hypergraph.pxi | |
parent | c6f5711203782e2677ad95da3ffa7a79fc0fbf3a (diff) |
sample trees from hypergraphs
Diffstat (limited to 'python/src/hypergraph.pxi')
-rw-r--r-- | python/src/hypergraph.pxi | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi index b210f440..62dd5bb1 100644 --- a/python/src/hypergraph.pxi +++ b/python/src/hypergraph.pxi @@ -85,6 +85,18 @@ cdef class Hypergraph: finally: del hypos + def sample_trees(self, unsigned n): + cdef vector[string]* trees = new vector[string]() + if self.rng == NULL: + self.rng = new MT19937() + hypergraph.sample_trees(self.hg[0], n, self.rng, trees) + cdef unsigned k + try: + for k in range(trees.size()): + yield unicode(trees[0][k].c_str(), 'utf8') + finally: + del trees + def intersect(self, Lattice lat): return hypergraph.Intersect(lat.lattice[0], self.hg) |