“gds.graph.project” 在 Neo4j 中实际上是如何工作的?

huangapple go评论54阅读模式
英文:

How does "gds.graph.project" actually work in Neo4j?

问题

我是neo4j的初学者。

在参加neo4j在线课程-Neo4j图数据科学基础时,我对以下**"课程示例"**感到困惑。

课程示例

首先,创建图投影。

CALL gds.graph.project('proj',
    ['Person','Movie'],
    {
        ACTED_IN:{orientation:'UNDIRECTED'},
        DIRECTED:{orientation:'UNDIRECTED'}
    }
);

然后我们可以运行Dijkstra的最短路径算法。

MATCH (a:Actor)
WHERE a.name IN ['Kevin Bacon', 'Denzel Washington']
WITH collect(id(a)) AS nodeIds
CALL gds.shortestPath.dijkstra.stream('proj', {sourceNode:nodeIds[0], TargetNode:nodeIds[1]})
YIELD sourceNode, targetNode, path
RETURN gds.util.asNode(sourceNode).name AS sourceNodeName,
    gds.util.asNode(targetNode).name AS targetNodeName,
    nodes(path) as path;

问题

关于gds.graph.project,我理解它创建了原始图的子图(子集)

然而,在创建这个子图时,没有带有Actor标签的节点。那么为什么在执行Dijkstra算法时可以执行MATCH (a:Actor)呢?

英文:

I'm a neo4j beginner.

While praticing in neo4j online course-Neo4j Graph Data Science Fundamentals, I'm confused about the following "Course Example".

Course Example

First, create the graph projection.

CALL gds.graph.project('proj',
    ['Person','Movie'],
    {
        ACTED_IN:{orientation:'UNDIRECTED'},
        DIRECTED:{orientation:'UNDIRECTED'}
    }
);

Then we can run Dijkstra’s shortest path.

MATCH (a:Actor)
WHERE a.name IN ['Kevin Bacon', 'Denzel Washington']
WITH collect(id(a)) AS nodeIds
CALL gds.shortestPath.dijkstra.stream('proj', {sourceNode:nodeIds[0], TargetNode:nodeIds[1]})
YIELD sourceNode, targetNode, path
RETURN gds.util.asNode(sourceNode).name AS sourceNodeName,
    gds.util.asNode(targetNode).name AS targetNodeName,
    nodes(path) as path;

Question

Regarding gds.graph.project my understanding is that it creates a subgraph (subset) from the original graph.

However, in the creation of this subgraph, there are no nodes with the Actor label. So why is it possible to execute MATCH (a:Actor) when performing the Dijkstra algorithm?

答案1

得分: 2

MATCH (a:Actor) 子句正在查询整个数据库,而不是 GDS 投影 ('proj')。只有以 gds. 开头的存储过程才能访问 GDS。

此外,一个节点可以有任意数量的标签。因此,一个 'Person' 节点也可以有 'Actor' 标签、'Director' 标签或者这三者的组合。

英文:

The MATCH (a:Actor) clause is querying the full database, not the GDS projection ('proj'). Only the procedures whose names start with gds. access the GDS.

Also, a node can have any number of labels. So, a Person node can also have the Actor label, or Director, or all 3.

huangapple
  • 本文由 发表于 2023年5月25日 14:58:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76329627.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定