summaryrefslogtreecommitdiff
path: root/python/src/hypergraph.pxi
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/hypergraph.pxi')
-rw-r--r--python/src/hypergraph.pxi12
1 files changed, 11 insertions, 1 deletions
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 = <Lattice> 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((<SparseVector> weights).vector[0])