#NEWLINE# def to_dot( self ) : #NEWLINE# #INDENT# 'Return a dot representation suitable for using with Graphviz.\n\n        >>> dg = DependencyGraph(\n        ...     \'John N 2\\n\'\n        ...     \'loves V 0\\n\'\n        ...     \'Mary N 2\'\n        ... )\n        >>> print(dg.to_dot())\n        digraph G{\n        edge [dir=forward]\n        node [shape=plaintext]\n        <BLANKLINE>\n        0 [label="0 (None)"]\n        0 -> 2 [label="ROOT"]\n        1 [label="1 (John)"]\n        2 [label="2 (loves)"]\n        2 -> 1 [label=""]\n        2 -> 3 [label=""]\n        3 [label="3 (Mary)"]\n        }\n\n        ' #NEWLINE# s = 'digraph G{\n' #NEWLINE# s += 'edge [dir=forward]\n' #NEWLINE# s += 'node [shape=plaintext]\n' #NEWLINE# for node in sorted ( self . nodes . values ( ) , key = ( lambda v : v [ 'address' ] ) ) : #NEWLINE# #INDENT# s += ( '\n%s [label="%s (%s)"]' % ( node [ 'address' ] , node [ 'address' ] , node [ 'word' ] ) ) #NEWLINE# for ( rel , deps ) in node [ 'deps' ] . items ( ) : #NEWLINE# #INDENT# for dep in deps : #NEWLINE# #INDENT# if ( rel is not None ) : #NEWLINE# #INDENT# s += ( '\n%s -> %s [label="%s"]' % ( node [ 'address' ] , dep , rel ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# s += ( '\n%s -> %s ' % ( node [ 'address' ] , dep ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# s += '\n}' #NEWLINE# return s