#NEWLINE# def expression_to_sparql( e , full = False ) : #NEWLINE# #INDENT# template = ( ( ( '{preamble}\n' + 'SELECT DISTINCT {select} WHERE {{\n' ) + '{expression}\n' ) + '}}\n' ) #NEWLINE# head = adapt ( e . get_head ( ) ) #NEWLINE# if full : #NEWLINE# #INDENT# select = '*' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# select = head #NEWLINE# #UNINDENT# y = 0 #NEWLINE# xs = [ ] #NEWLINE# for node in e . iter_nodes ( ) : #NEWLINE# #INDENT# for ( relation , dest ) in e . iter_edges ( node ) : #NEWLINE# #INDENT# if ( relation is IsRelatedTo ) : #NEWLINE# #INDENT# relation = '?y{}' . format ( y ) #NEWLINE# y += 1 #NEWLINE# #UNINDENT# xs . append ( triple ( adapt ( sparql ) , relation , adapt ( dest ) , indentation = 1 ) ) #NEWLINE# #UNINDENT# #UNINDENT# sparql = template . format ( preamble = settings . SPARQL_PREAMBLE , select = select , expression = '\n' . join ( xs ) ) #NEWLINE# return ( select , sparql )