使用Python和py2neo打印关键路径ID

时间:2017-09-28 19:33:10

标签: neo4j py2neo

我使用py2neo

运行此查询
 myQuery = "MATCH p=(:Task {activity: 'Start'})-[:RELATIONSHIP*]->(:Task {activity: 'Finish'}) "\
       "WITH p, REDUCE(x=0, a IN NODES(p) | x + a.duration) AS cum_duration ORDER BY cum_duration DESC "\
       "LIMIT 1 RETURN p AS CritPath WITH p, REDUCE(x=0, a IN NODES(p) | x + a.durata) AS cum_duration ORDER BY cum_duration DESC LIMIT 1 "\
       "RETURN p AS CritPath"


myGraph.run(myQuery).dump()

但它打印

(cd885ed)-[:RELATIONSHIP]->(a94c38f)

如果我想打印"活动的名称"而不是内存地址" cd885ed" (比如上面的例子),我该怎么做?

例如:

(start)-[:RELATIONSHIP]->(finish)

非常感谢

1 个答案:

答案 0 :(得分:0)

任何myGraph.run()命令都会返回一个光标,其中包含您可以处理的结果。由于您返回的路径是您必须处理的,如果您只需要活动属性,为什么不返回那些?

无论如何......

theCursor = myGraph.run(myQuery)
for theRecord in theCursor:
    # do something with the theRecord

希望这有帮助。

此致 汤姆