#NEWLINE# def nx_graph( self ) : #NEWLINE# #INDENT# 'Convert the data in a ``nodelist`` into a networkx labeled directed graph.' #NEWLINE# import networkx #NEWLINE# nx_nodelist = list ( range ( 1 , len ( self . nodes ) ) ) #NEWLINE# nx_edgelist = [ ( n , self . _hd ( n ) , self . _rel ( n ) ) for n in nx_nodelist if self . _hd ( n ) ] #NEWLINE# self . nx_labels = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for n in nx_nodelist : #NEWLINE# #INDENT# self . nx_labels [ n ] = self . nodes [ n ] [ 'word' ] #NEWLINE# #UNINDENT# g = networkx . MultiDiGraph ( ) #NEWLINE# g . add_nodes_from ( nx_nodelist ) #NEWLINE# g . add_edges_from ( nx_edgelist ) #NEWLINE# return g