计算neo4j中的节点深度 [英] Count node depth in neo4j

查看:139
本文介绍了计算neo4j中的节点深度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Neo4j 中有这个查询:

I have this query in Neo4j:

MATCH (sentence:Sentence)-[r*]->(n:Word )
WITH n, COUNT(r) AS c
RETURN n, c

我的图是一个语言数据库,包含单词和它们之间的依赖关系.此查询应返回节点深度,但 COUNT(r) 始终返回 1.当我省略 COUNT 函数并只写

My graph is a linguistic database containing words and dependency relations between them. This query should return depth of nodes, however the COUNT(r) always returns 1. When I ommit the COUNT function and write just

WITH n, r AS c

相反(在网络浏览器 Neo4j 界面中尝试),neo4j 按预期为每个单词节点n"返回多个关系.你能帮我我做错了什么,如何计算句子节点和单词节点之间的路径长度?谢谢.

instead (trying in web browser neo4j interface), neo4j returns multiple relations for each word node "n" as expected. Can you please help me what am I doing wrong, how to count the length of path between sentence node and word node? thanks.

推荐答案

我认为它查询 return n 和 c 并且有多个记录 n 所以 count(r) return 1.

I think it query return n and c and there are multiple record of n so count(r) return 1.

试试这个 -

MATCH (sentence:Sentence)-[r*]->(n:Word )
WITH n, LENGTH(r) AS depth
RETURN n, depth

你会得到这样的深度.

或者试试这个

   MATCH p= (sentence:Sentence)-->(n:Word)    
   RETURN n, length(p) as depth

http://docs.neo4j.org/chunked/stable/query-functions-scalar.html#functions-length

这篇关于计算neo4j中的节点深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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