使用py2neo创建多个关系

时间:2016-08-22 07:39:04

标签: neo4j py2neo

我想使用py2neo库在同一节点之间创建多个关系。如果关系不存在,我使用create,并且当它存在时合并。以下是我的代码示例:

def create_route(graph, sourcefile, airport_nodes):
    with open(sourcefile, encoding="utf8") as csvfile:
        reader = csv.DictReader(csvfile)
        fieldnames = reader.fieldnames

        for row in reader:
            source_airport = row['origin']
            destination_airport = row['destination']
            source_airport_node = airport_nodes[source_airport]
            destination_airport_node = airport_nodes[destination_airport]
            node_properties = {'distance':row['distance']}
            node_properties1 = {'duration': row['duration']}
            graph.create(Relationship(source_airport_node, destination_airport_node,**node_properties1))
            graph.merge(Relationship(source_airport_node, destination_airport_node, **node_properties))

它与最后一个属性只有一个关系的问题是距离。

谢谢

0 个答案:

没有答案