py2neo - Neo4j: Adding nodes and finding relationship taking more time -
here python code, trying insert nodes , find relationships taking more time, appreciated
from xml.dom import minidom py2neo import graph, node, relationship, authenticate authenticate("localhost:7474", "neo4j", "neo4j") graph = graph("http://localhost:7474/db/data/") i=0; xml_file = open("sample.xml") xml_doc = minidom.parse(xml_file) archives = xml_doc.getelementsbytagname('archive') class_names=xml_doc.getelementsbytagname('class') label_archive="archive" label="class" 'adding nodes' arch in archives: arc = graph.create(node(label_archive, arc_value=arch.attributes['name'].value)) topic_nodes = arch.getelementsbytagname('class') clas in topic_nodes: cla=graph.create(node(label,class_value=clas.attributes['name'].value)) e'].value)) **adding relationship**
'this section adds relationship'
arch in archives: arcid_=arch.attributes['name'].value node = graph.find_one(label_archive, property_key="arc_value", property_value=arcid_) clas in topic_nodes: classid_=clas.attributes['name'].value node1 = graph.find_one(label, property_key="class_value", property_value=classid_) try: relationship_class=relationship(node, "class", node1) graph.create(relationship_class) indexerror: continue
Comments
Post a Comment