添加节点标签
在创建之后向图中添加节点标签可以用来基于例如算法结果创建标签。与现有标签一样,它们允许在后续操作中过滤图。
语法
CALL gds.graph.nodeLabel.mutate(
graphName: String,
nodeLabel: String,
configuration: Map
)
YIELD
mutateMillis: Integer,
graphName: String,
nodeLabel: String,
nodeLabelsWritten: Integer,
nodeCount: Integer,
configuration: Map
名称 | 类型 | 可选 | 描述 |
---|---|---|---|
graphName |
字符串 |
否 |
图在目录中存储的名称。 |
nodeLabel |
字符串 |
否 |
要写入的节点标签。 |
configuration |
地图 |
是 |
配置 writeNodeProperties 的其他参数。 |
名称 | 类型 | 默认 | 描述 |
---|---|---|---|
nodeFilter |
字符串 |
n/a |
用于过滤输入图中节点的 Cypher 谓词。请参阅 投影子图。 |
concurrency |
整数 |
4 |
用于运行过程的并发线程数。还提供 |
writeConcurrency |
整数 |
'concurrency' |
用于写入节点属性的并发线程数。 |
名称 | 类型 | 描述 |
---|---|---|
mutateMillis |
整数 |
将结果数据写回内存中图所需的时间(毫秒)。 |
nodeLabel |
字符串 |
添加到内存中图的标签的名称。 |
nodeLabelsWritten |
整数 |
写入的节点标签数量。 |
graphName |
字符串 |
存储在目录中的图的名称。 |
nodeCount |
整数 |
图中节点的总数。 |
configuration |
地图 |
用于运行过程的配置。 |
示例
以下所有示例都应该在空数据库中运行。 这些示例使用 Cypher 投影 作为规范。原生投影将在未来版本中弃用。 |
为了演示 GDS 在节点属性上的功能,我们将创建一个小型的社交网络图在 Neo4j 中,并将其投影到图目录中。
CREATE
(florentin:Person { name: 'Florentin', age: 16 }),
(adam:Person { name: 'Adam', age: 18 }),
(veselin:Person { name: 'Veselin', age: 20 }),
(hobbit:Book { name: 'The Hobbit', numberOfPages: 310 }),
(florentin)-[:KNOWS { since: 2010 }]->(adam),
(florentin)-[:KNOWS { since: 2018 }]->(veselin),
(adam)-[:READ]->(hobbit)
MATCH (n:Person)-[r:KNOWS|READ]->(m:Person|Book)
RETURN gds.graph.project('socialGraph', n, m,
{
sourceNodeLabels: labels(n),
targetNodeLabels: labels(m),
sourceNodeProperties: n { .age },
targetNodeProperties: CASE WHEN m:Person THEN m { .age } ELSE {} END,
relationshipType: type(r)
}
)
CALL gds.degree.mutate('socialGraph', {mutateProperty: 'score'})
为了通过添加分数高于 0
的节点的新节点标签来修改内存中图,我们使用以下查询
Reader
节点标签添加到内存中图CALL gds.graph.nodeLabel.mutate('socialGraph', 'Reader', { nodeFilter: 'n.score > 0.0' })
YIELD graphName, nodeLabel, nodeLabelsWritten, nodeCount
graphName | nodeLabel | nodeLabelsWritten | nodeCount |
---|---|---|---|
"socialGraph" |
"Reader" |
2 |
4 |
正如我们从结果中看到的那样,有两个节点匹配了指定的过滤器,并且它们获得了节点标签 Reader
。我们可以通过流式传输 Reader
节点标签的 score
属性来检查结果,我们可以使用以下查询来执行此操作
Reader
节点的 score
属性CALL gds.graph.nodeProperty.stream('socialGraph', 'score', ['Reader'])
YIELD nodeId, propertyValue
RETURN gds.util.asNode(nodeId).name AS name, propertyValue AS score
ORDER BY score DESC
name | score |
---|---|
"Florentin" |
2.0 |
"Adam" |
1.0 |
我们可以看到 Veselin
没有被标记为 Reader
,因为该节点的 score
属性为 0
。