Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python返回neo4j的中间路径_Python_Neo4j - Fatal编程技术网

Python返回neo4j的中间路径

Python返回neo4j的中间路径,python,neo4j,Python,Neo4j,我试图返回neo4j的完整路径,但它只能返回python中的开始节点和结束节点,而这些节点在neo4j中返回完整路径 我的python代码是: from neo4j import GraphDatabase,basic_auth uri = "bolt://localhost:7687" driver = GraphDatabase.driver(uri, auth=("", "")) session = driver.session() paths = session.run('''PR

我试图返回neo4j的完整路径,但它只能返回python中的开始节点和结束节点,而这些节点在neo4j中返回完整路径

我的python代码是:

from neo4j import GraphDatabase,basic_auth

uri = "bolt://localhost:7687"
driver = GraphDatabase.driver(uri, auth=("", ""))

session = driver.session()

paths = session.run('''PROFILE
                   with ['aaa''bbb''ccc''ddd''eee'] as value_list
                   match (n:Node) where n.value in value_list
                       with collect(n) as result
                       unwind result as source
                       unwind result as target
                   match paths = shortestpath((source)-[*0..2]-(target)) where source<>target
                       with paths limit 200
                       return paths''')

for record in paths:
    print(",".join("%s:%s"%(key,record[key]) for key in record.keys()))

session.close()
但在python中返回:

paths:<Path start=<Node id=9650694 labels={'Node'} properties={'value': 'aaa'}> end=<Node id=23038409 labels={'Node'} properties={'value': 'ccc'}> size=2>
paths:<Path start=<Node id=9650694 labels={'Node'} properties={'value': 'aaa'}> end=<Node id=9011159 labels={'Node'} properties={'value': 'eee'}> size=2>
路径:
路径:

如何获得完整路径,而不仅仅是开始节点和结束节点?

这可以返回完整路径

for record in paths:
    #print(record)
    relationships = record["path"].relationships
    nodes = record["path"].nodes
    path = ""
    for i in (range(len(relationships))):
        path += "{0}-[{1}]->".format(nodes[i]["value"], relationships[i]["value"])
    path += nodes[-1]["value"]
    wt.write(path+'\n')
参考:

for record in paths:
    #print(record)
    relationships = record["path"].relationships
    nodes = record["path"].nodes
    path = ""
    for i in (range(len(relationships))):
        path += "{0}-[{1}]->".format(nodes[i]["value"], relationships[i]["value"])
    path += nodes[-1]["value"]
    wt.write(path+'\n')