遍历期间的Neo4j节点属性比较 [英] Neo4j node property comparison during traversal

查看:384
本文介绍了遍历期间的Neo4j节点属性比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Neo4j完全陌生。我正在测试图形数据库,并且有以下简单的图形测试结构:带有属性的不同标签节点,这些连接

所有节点都有一个属性,称为访问。它是一个字符串元素的列表,例如:

$ $ p $ $ c $ {access:['http','www']}

我正在寻找一个解决方案,我从一个起始节点获得所有节点的连接(不问题的类型或方向)以及它们在节点访问属性上的交集存在的关系。我将从给定的节点开始,并将访问属性与下一个连接的节点进行比较。然后,获取第二个节点的属性,并将此访问属性与连接到它们的节点进行比较。等等。目标应该是所有节点和它们的连接,其中存在访问属性的区间。例如,在图的具体结构中,我们从ENC 2009节点开始,并遍历所有连接的节点,直到达到访问属性上没有交集的节点。对于这个例子,应该达到以下目标:遍历图



我尝试了以下密码查询,但它在每个节点上都不能正常工作作为起始节点。

  MATCH(n:CONFERENCE_SERIE)WHERE n.full_name =〜'mex。*'
MATCH p = n - [*] - m WHERE FILTER(x IN n.access WHERE x IN m.access)
RETURN p

是否有解决方案,带有java遍历框架或cypher,目标并获得这样一个图表的路径?

感谢您的帮助。

解决方案

java遍历框架在这方面效率更高,您可以使用RelationshipExpander中的当前路径的关系



http://neo4j.com/docs/stable/tutor ial-traversal-java-api.html#_pathexpander_relationshipexpander



在cypher中,您可以执行以下操作:

  MATCH(n:CONFERENCE_SERIE)WHERE n.full_name =〜'mex。*'
MATCH p = n - [*] - m
WHERE FILTER( (rels(p)[idx])。访问
WHERE ANY(访问IN(rels(p)[idx])。 ).access))
RETURN p

即有一个计数器从0到path-len-2
查看每对路径,并检查至少一个(ANY)访问代码是否包含在下一个rel的access-property中。


I am completely new to Neo4j. I am testing the graph database and I have the following simple graph test-structure: different labeled nodes with properties, which are connected.

All the nodes have a property, which is called access. It is a list of string elements such as:

{access: ['http', 'www']}

I'm searching for a solution, where I get all nodes from a starting node which are connected (doesn't matter which type or direction) and their relationship where an intersection on the access property of the nodes exists. I will start at a given node and compare the access property with the next connected node. Then, take the property of the second node and compare this access property with the nodes, which are connected to them. And so on. The goal should be all nodes and their connections, where an interesection on access property exists. On the concrete structure of the graph, for example, we start at the node ENC 2009 and should traverse all connected nodes until a node with no intersection on the access property is reached. For this example, the following goal should be reached: traversed graph

I tried the following cypher query, but it is not working fine on each node as starting node.

MATCH (n:CONFERENCE_SERIE) WHERE n.full_name =~ 'mex.*'
MATCH p = n-[*]-m WHERE FILTER(x IN n.access WHERE x IN m.access)
RETURN p

Is there a solution, with the java traversal framework or with cypher, to reach the goal and to get the path of such an graph?

Thanks in advance for your help.

解决方案

The java traversal framework will be more efficient at this, you would use the relationships of the current Path in your RelationshipExpander

http://neo4j.com/docs/stable/tutorial-traversal-java-api.html#_pathexpander_relationshipexpander

In cypher you could do something like:

MATCH (n:CONFERENCE_SERIE) WHERE n.full_name =~ 'mex.*'
MATCH p = n-[*]-m 
WHERE FILTER(idx IN range(0,length(p)-2) 
      WHERE ANY(access IN (rels(p)[idx]).access 
                WHERE access IN (rels(p)[idx+1]).access))
RETURN p

i.e. have an counter go from 0 to path-len-2 look at each pair of rels of the path and check that at least one (ANY) access code is contained in the next rel's access-property.

这篇关于遍历期间的Neo4j节点属性比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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