<s> """<STR_LIT>""" <EOL> class NeoDB ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , uri = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . graph_db = neo4j . GraphDatabaseService ( uri ) <EOL> version = self . graph_db . neo4j_version <EOL> print '<STR_LIT>' % ( str ( uri ) , version ) <EOL> except packages . httpstream . http . SocketError : <EOL> print '<STR_LIT>' <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> def add_node ( self , node_id , name , labels ) : <EOL> """<STR_LIT>""" <EOL> node = self . graph_db . get_or_create_indexed_node ( '<STR_LIT>' , '<STR_LIT>' , node_id , { '<STR_LIT>' : node_id , '<STR_LIT:name>' : name } ) <EOL> try : <EOL> node . add_labels ( * labels ) <EOL> except NotImplementedError : <EOL> pass <EOL> def has_node ( self , node_id ) : <EOL> """<STR_LIT>""" <EOL> return True if self . graph_db . get_indexed_node ( '<STR_LIT>' , '<STR_LIT>' , node_id ) else False <EOL> def add_rel ( self , source_node_id , target_node_id , rel ) : <EOL> """<STR_LIT>""" <EOL> n1_ref = self . graph_db . get_indexed_node ( '<STR_LIT>' , '<STR_LIT>' , source_node_id ) <EOL> n2_ref = self . graph_db . get_indexed_node ( '<STR_LIT>' , '<STR_LIT>' , target_node_id ) <EOL> if not n1_ref or not n2_ref : <EOL> print '<STR_LIT>' % ( source_node_id , target_node_id ) <EOL> return <EOL> path = neo4j . Path ( n1_ref , rel , n2_ref ) <EOL> path . get_or_create ( self . graph_db ) <EOL> def clear_db ( self ) : <EOL> """<STR_LIT>""" <EOL> self . graph_db . clear ( ) <EOL> class NeoDBStub ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , uri = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> print '<STR_LIT>' % ( str ( uri ) ) <EOL> print '<STR_LIT>' <EOL> def add_node ( self , node_id , name , labels ) : <EOL> """<STR_LIT>""" <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' % ( self , node_id , name , labels ) <EOL> def has_node ( self , node_id ) : <EOL> """<STR_LIT>""" <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' % ( self , node_id ) <EOL> def add_rel ( self , source_node_id , target_node_id , rel ) : <EOL> """<STR_LIT>""" <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' % ( self , source_node_id , target_node_id , rel ) <EOL> def clear_db ( self ) : <EOL> """<STR_LIT>""" <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT:%s>' % ( self ) <EOL> try : <EOL> from py2neo import neo4j <EOL> from py2neo import packages <EOL> NeoDB = NeoDB <EOL> except ( ImportError , RuntimeError ) : <EOL> NeoDB = NeoDBStub </s>
