diff options
author | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-08-14 22:50:37 -0400 |
---|---|---|
committer | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-08-14 22:50:37 -0400 |
commit | 9c9213239263e8e8de2f154068cc3ad44e0c2100 (patch) | |
tree | a9ee2f722e4dc5705ae9f90f6fb3b67a278c5fd9 /python/src/hypergraph.pxi | |
parent | 0823824b5fa1504b6b2c48328aa8fc8468017cba (diff) |
[cdec.sa] Explicit feature names in grammar extractor output
+ sparse features in extractor
+ hg.intersect(string)
+ basestring = str|unicode
Diffstat (limited to 'python/src/hypergraph.pxi')
-rw-r--r-- | python/src/hypergraph.pxi | 12 |
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]) |