From a68aaea190197f17f308b91f66ceff222a784460 Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Tue, 14 Aug 2012 22:50:37 -0400 Subject: [cdec.sa] Explicit feature names in grammar extractor output + sparse features in extractor + hg.intersect(string) + basestring = str|unicode --- python/src/hypergraph.pxi | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'python/src/hypergraph.pxi') diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi index 1edff3cb..bb6141df 100644 --- a/python/src/hypergraph.pxi +++ b/python/src/hypergraph.pxi @@ -98,7 +98,14 @@ cdef class Hypergraph: finally: del trees - def intersect(self, Lattice lat): + def intersect(self, inp): + cdef Lattice lat + if isinstance(inp, Lattice): + lat = inp + elif isinstance(inp, basestring): + lat = Lattice(inp) + else: + raise TypeError('cannot intersect hypergraph with %s' % type(inp)) return hypergraph.Intersect(lat.lattice[0], self.hg) def prune(self, beam_alpha=0, density=0, **kwargs): @@ -114,6 +121,9 @@ cdef class Hypergraph: cdef bytes plf = hypergraph.AsPLF(self.hg[0], True).c_str() return Lattice(eval(plf)) + def plf(self): + return bytes(hypergraph.AsPLF(self.hg[0], True).c_str()) + def reweight(self, weights): if isinstance(weights, SparseVector): self.hg.Reweight(( weights).vector[0]) -- cgit v1.2.3