#NEWLINE# def malt_demo( nx = False ) : #NEWLINE# #INDENT# '\n    A demonstration of the result of reading a dependency\n    version of the first sentence of the Penn Treebank.\n    ' #NEWLINE# dg = DependencyGraph ( 'Pierre  NNP     2       NMOD\nVinken  NNP     8       SUB\n,       ,       2       P\n61      CD      5       NMOD\nyears   NNS     6       AMOD\nold     JJ      2       NMOD\n,       ,       2       P\nwill    MD      0       ROOT\njoin    VB      8       VC\nthe     DT      11      NMOD\nboard   NN      9       OBJ\nas      IN      9       VMOD\na       DT      15      NMOD\nnonexecutive    JJ      15      NMOD\ndirector        NN      12      PMOD\nNov.    NNP     9       VMOD\n29      CD      16      NMOD\n.       .       9       VMOD\n' ) #NEWLINE# tree = dg . tree ( ) #NEWLINE# tree . pprint ( ) #NEWLINE# if nx : #NEWLINE# #INDENT# import networkx #NEWLINE# from matplotlib import pylab #NEWLINE# g = dg . nx_graph ( ) #NEWLINE# g . info ( ) #NEWLINE# pos = networkx . spring_layout ( g , dim = 1 ) #NEWLINE# networkx . draw_networkx_nodes ( g , pos , node_size = 50 ) #NEWLINE# networkx . draw_networkx_labels ( g , pos , dg . nx_labels ) #NEWLINE# pylab . xticks ( [ ] ) #NEWLINE# pylab . yticks ( [ ] ) #NEWLINE# pylab . savefig ( 'tree.png' ) #NEWLINE# pylab . show ( )