Neo4j:添加节点并找到关系花费更多时间

时间:2016-07-25 15:19:11

标签: neo4j py2neo

这是我的python代码,我试图插入节点并找到关系,但它需要更多时间,帮助将不胜感激

from xml.dom import minidom
from 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'
for arch in archives:
    arc = graph.create(Node(label_Archive, arc_value=arch.attributes['name'].value))
    topic_nodes = arch.getElementsByTagName('class')
    for clas in topic_nodes:
        cla=graph.create(Node(label,class_value=clas.attributes['name'].value))
       e'].value))

**Adding  relationship**

'此部分添加关系'

 for arch in archives:
        ARCID_=arch.attributes['name'].value
        node = graph.find_one(label_Archive, property_key="arc_value", property_value=ARCID_)
        for 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

0 个答案:

没有答案