【问题标题】:Print critical path IDs using both Python and py2neo使用 Python 和 py2neo 打印关键路径 ID
【发布时间】:2017-09-28 19:33:10
【问题描述】:

我使用 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)

非常感谢

【问题讨论】:

    标签: neo4j py2neo


    【解决方案1】:

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

    无论如何...

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

    希望这会有所帮助。

    问候, 汤姆

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-05
      • 2018-03-12
      • 1970-01-01
      • 2017-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多