用于建模传递闭包的 Neo4j 查询 [英] Neo4j query for modeling transitive clousure
问题描述
我正在探索 GraphDB 查询语言,并在 OriendDB 中询问了有关传递闭包支持的问题这里?我想看看 Neo4J 如何支持这个功能:
I am exploring GraphDB query languages, and asked a question about transitive closure support in OriendDB here? I would like to see how Neo4J supports this feature:
简而言之,假设我将所有节点都标记为 PERSON.我有被称为父亲"的边缘将这些人连接在一起.对于给定的节点 p1,我想知道以下查询在 Neo4j 中的样子:
Briefly, suppose I have Nodes all labeled as PERSON. And I have Edges called "father" connecting these persons together. For a given node say p1, I am wondering how the following query looks like in Neo4j:
找到p1的所有祖先?
我不熟悉 Neo4j 语法(但我认为可以定义我在上面解释的这样的结构),所以请原谅我跳过模式定义.
I am not familiar with Neo4j syntax (but I think it is possible to define such an structure I explained above there), so excuse me for skipping the schema definition.
推荐答案
通过这种方式,您可以找到名为Fred Flintstone"的 PERSON
的所有祖先:
This is how you can find all the ancestors of a PERSON
named "Fred Flintstone":
MATCH (p1:PERSON {name: "Fred Flintstone"})-[:father*]->(f)
RETURN f;
这就是你如何找到他所有的后代:
And this is how you can find all his descendants:
MATCH (p1:PERSON {name: "Fred Flintstone"})<-[:father*]-(d)
RETURN d;
这篇关于用于建模传递闭包的 Neo4j 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!