summaryrefslogtreecommitdiff
path: root/python/src/lattice.pxi
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/lattice.pxi')
-rw-r--r--python/src/lattice.pxi13
1 files changed, 6 insertions, 7 deletions
diff --git a/python/src/lattice.pxi b/python/src/lattice.pxi
index f8341e29..14864549 100644
--- a/python/src/lattice.pxi
+++ b/python/src/lattice.pxi
@@ -3,7 +3,7 @@ cimport lattice
cdef class Lattice:
cdef lattice.Lattice* lattice
- def __init__(self, inp):
+ def __cinit__(self, inp):
if isinstance(inp, tuple):
self.lattice = new lattice.Lattice(len(inp))
for i, arcs in enumerate(inp):
@@ -16,18 +16,20 @@ cdef class Lattice:
self.lattice = new lattice.Lattice()
lattice.ConvertTextToLattice(string(<char *>inp), self.lattice)
+ def __dealloc__(self):
+ del self.lattice
+
def __getitem__(self, int index):
if not 0 <= index < len(self):
raise IndexError('lattice index out of range')
arcs = []
cdef vector[lattice.LatticeArc] arc_vector = self.lattice[0][index]
cdef lattice.LatticeArc* arc
- cdef str label
cdef unsigned i
for i in range(arc_vector.size()):
arc = &arc_vector[i]
- label = TDConvert(arc.label)
- arcs.append((label.decode('utf8'), arc.cost, arc.dist2next))
+ label = unicode(TDConvert(arc.label), 'utf8')
+ arcs.append((label, arc.cost, arc.dist2next))
return tuple(arcs)
def __setitem__(self, int index, tuple arcs):
@@ -52,9 +54,6 @@ cdef class Lattice:
for i in range(len(self)):
yield self[i]
- def __dealloc__(self):
- del self.lattice
-
def todot(self):
def lines():
yield 'digraph lattice {'