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.pxi12
1 files changed, 12 insertions, 0 deletions
diff --git a/python/src/lattice.pxi b/python/src/lattice.pxi
index 493c6dcd..f8341e29 100644
--- a/python/src/lattice.pxi
+++ b/python/src/lattice.pxi
@@ -54,3 +54,15 @@ cdef class Lattice:
def __dealloc__(self):
del self.lattice
+
+ def todot(self):
+ def lines():
+ yield 'digraph lattice {'
+ yield 'rankdir = LR;'
+ yield 'node [shape=circle];'
+ for i in range(len(self)):
+ for label, weight, delta in self[i]:
+ yield '%d -> %d [label="%s"];' % (i, i+delta, label.replace('"', '\\"'))
+ yield '%d [shape=doublecircle]' % len(self)
+ yield '}'
+ return '\n'.join(lines()).encode('utf8')