#NEWLINE# def roget_graph( ) : #NEWLINE# #INDENT# ' Return the thesaurus graph from the roget.dat example in\n    the Stanford Graph Base.\n    ' #NEWLINE# import gzip #NEWLINE# fh = gzip . open ( 'roget_dat.txt.gz' , 'r' ) #NEWLINE# G = DiGraph ( ) #NEWLINE# for line in fh . readlines ( ) : #NEWLINE# #INDENT# line = line . decode ( ) #NEWLINE# if line . startswith ( '*' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if line . startswith ( ' ' ) : #NEWLINE# #INDENT# line = ( G + line ) #NEWLINE# #UNINDENT# if line . endswith ( '\\\n' ) : #NEWLINE# #INDENT# oldline = line . strip ( '\\\n' ) #NEWLINE# continue #NEWLINE# #UNINDENT# ( headname , tails ) = line . split ( ':' ) #NEWLINE# numfind = re . compile ( '^\\d+' ) #NEWLINE# head = numfind . findall ( headname ) [ 0 ] #NEWLINE# G . add_node ( head ) #NEWLINE# for tail in tails . split ( ) : #NEWLINE# #INDENT# if ( head == tail ) : #NEWLINE# #INDENT# print ( 'skipping self loop' , head , tail , file = sys . stderr ) #NEWLINE# #UNINDENT# G . add_edge ( head , tail ) #NEWLINE# #UNINDENT# #UNINDENT# return G