diff options
author | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-07-05 16:53:26 -0400 |
---|---|---|
committer | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-07-05 16:53:26 -0400 |
commit | 757f56e391bd2e1d7442ab38fc98aff00d064d38 (patch) | |
tree | db07405a8e182655fe182757ff76859b4008dba1 /python/src/lattice.pxi | |
parent | 32a8d92affae91094f2348b73dd26be800e10abd (diff) |
[python] Add convenience methods
Diffstat (limited to 'python/src/lattice.pxi')
-rw-r--r-- | python/src/lattice.pxi | 12 |
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') |