我可以递归评估neo4j密码语言的树吗? [英] Can I recursively evaluate a tree in neo4j cypher language?

查看:77
本文介绍了我可以递归评估neo4j密码语言的树吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我基本上拥有数学表达式的语法树,如neo4j图……图片可能会有所帮助:

In my application, I have what is essentially the syntax tree of a mathematical expression as neo4j graph... a picture is probably helpful:

我想知道是否有可能编写一个Cypher查询来完全评估顶级节点的树,例如:

I'm wondering if it's possible to write a Cypher query that fully evaluates a tree like this for the top node, i.e.:

  • 获取节点1.2的已连接输入的平均值,
  • 1.1.2的最大值
  • 节点1.1的平均值1.1.2和3
  • 最后返回最大值1.2和1.1作为节点1的值

该值存储在输入节点的属性 status 中,在max和avg节点中,该值不存在,应进行计算.

The value is stored in the property status for the input nodes, in the max and avg nodes the value is not present and should be calculated.

这是neo4j控制台中的全部内容: http://console.neo4j.org/?id = gopwjn

Here's the whole thing in neo4j console: http://console.neo4j.org/?id=gopwjn

我觉得使用某些WITH和REDUCE以及类似的伏都教具是可能的,但是我不能将它们拼凑在一起.

I have a feeling that it might be possible with some WITH and REDUCE and similar voodoo, but I can't piece it quite together.

推荐答案

这是一个简单的解决方案,似乎可以解决问题. 我尝试了类似FOREACH(范围(0,2)中的n ........但是您不能在foreach中使用match:/,所以在这里我更新了所有avg节点,然后更新了所有最大节点,然后重复导致第一个传递不会填充avg的子最大节点.

here is a flat solution that seems to do the trick. I tried something like FOREACH (n in range(0,2)....... but you cannot use match within a foreach :/ so here i update all avg nodes, then update all max nodes and then repeat cause the first pass would not populated child max nodes of avg.

我希望这至少可以为您指明一个有用的方向:)

i hope this st least points you in a helpful direction :)

MATCH (n1:AVG)-[]-(p1)
WITH AVG(p1.status) AS NEWSTATUS1, n1 AS ND1
MERGE (n1:AVG { name:ND1.name })
ON MATCH SET n1.status=NEWSTATUS1
with 1 as A
MATCH (n2:MAX)-[]-(p2)
WITH MAX(p2.status) AS NEWSTATUS2, n2 AS ND2
MERGE (n2:MAX { name:ND2.name })
ON MATCH SET n2.status=NEWSTATUS2
with 2 as B
MATCH (n3:AVG)-[]-(p3)
WITH AVG(p3.status) AS NEWSTATUS3, n3 AS ND3
MERGE (n3:AVG { name:ND3.name })
ON MATCH SET n3.status=NEWSTATUS3
with 3 as C
MATCH (n4:MAX)-[]-(p4)
WITH MAX(p4.status) AS NEWSTATUS4, n4 AS ND4
MERGE (n4:MAX { name:ND4.name })
ON MATCH SET n4.status=NEWSTATUS4

这篇关于我可以递归评估neo4j密码语言的树吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆