Neo4J - 统计最外层节点 [英] Neo4J - count outermost nodes

查看:420
本文介绍了Neo4J - 统计最外层节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个图(或子图),在这种情况下,根Neo ...

如何获得离根最远的节点(即没有直接连接到更深的节点),它有一个特定的属性。



例如...当我不是我时,如何获得绿色的Get Me节点对其他绿色产品感兴趣(它们不是最外层)或橙色产品(最远的是分支,但不是绿色)。我不在乎深度....





感谢您的帮助

Chris

解决方案

Franks的另一种方法是首先找到符合条件的所有叶节点,然后使用这些节点筛选到那些具有到Neo节点的路径的元素。

  //找到所有的绿色节点(您可以将过滤器/ WHERE子句添加到
//只匹配具有特定属性的节点)
MATCH(g:Green) - (o)
//对于每个匹配,计算节点的度数(
//关系的数量 - 在本例中是无向的)
WITH g,count(*)为deg
//将结果过滤到叶节点(deg 1)
WHERE deg = 1
with g
//最后只返回那些有通往的路径蓝色(neo)节点
MATCH(g) - [*] - (b:蓝色)
//只返回绿色节点
RETURN g;


Given a graph (or subgraph), in this case root Neo...

How do I get the nodes which are the furthest depth from the root (i.e not directly connected to nodes of greater depth) which have a specific attribute.

eg ... how do I get the green "Get Me" nodes when I'm not interested in the other green ones (they're not the outermost layers) or the orange ones (furthest out on their branch but not green). I don't care about depth ....

Thanks for your help

Chris

解决方案

Another approach to Franks would be to find all the leaf nodes first that match your criteria, and then using those nodes, filter down to those that have a path to the Neo node

// find all Green nodes (you can add in a filter / WHERE clause to 
// just match the ones with specific properties)
MATCH (g:Green)--(o) 
// for each match, calculate the degree of the node (the number of 
// relationships - undirected in this example)
WITH g, count(*) as deg 
// filter down the results to just the leaf nodes (deg 1)
WHERE deg = 1
WITH g 
// finally only return those that have a path to the Blue (neo) node
MATCH (g)-[*]-(b:Blue) 
// just return the green nodes
RETURN g;

这篇关于Neo4J - 统计最外层节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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