在一个项目中,我试图减少变量的数量,以使创建嵌入和检查它们是否有效的东西更容易可视化。 我意识到有一个投影和一个子投影。我绝对可以创建一个新的 neo4j 图表,但这似乎是一个缓慢的解决方案。 所以只要按照教程,他们有
CALL gds.graph.project(
'apps_undir',
['App', 'Genre']
{Genre_Category: {orientation: 'UNDIRECTED'}}
)
然后像
CALL gds.beta.graph.project.subgraph(
'subapps',
'apps_undir',
"n:App OR (n:Genre AND n.name = 'Action' OR n.name = 'RPG')",
'*'
)
我意识到这不是python,但这是我想表达的想法。将字符串查询作为
'n:App OR (n:Genre AND n.name = Action OR n.name = RPG)'
我得到错误:
调用程序失败gds.beta.graph.project.subgraph
:原因:org.neo4j.gds.beta.filter.expression.SemanticErrors:解析表达式时出现语义错误:
Invalid variable `Action`. Only `n` is allowed for nodes
Invalid variable `RPG`. Only `n` is allowed for nodes
Unknown property `name`.
Unknown property `name`.
产生的错误是 “Neo.ClientError.Statement.SyntaxError 无效输入“子图”:预期“ 由于子图仅处于测试阶段,功能不是很好,但所有节点名称显然都需要是 n, 对于实际的子图,并对其进行嵌入
如果有帮助,这是从 2016 年的 Steam 数据库中提取的,下面是几个 csv 值:
appid;Genre
8890;RPG
8890;Strategy
10530;Action
10530;RPG
15540;Indie
15560;Action
15620;Strategy
您的工作流程存在一些问题。当您使用以下命令在 GDS 中投影图形时,默认情况下它不包含任何节点属性。
CALL gds.graph.project(
'apps_undir',
['App', 'Genre']
{Genre_Category: {orientation: 'UNDIRECTED'}}
)
有一些方法可以在图形投影中包含节点属性,但是不支持字符串格式。因此,您不能投影看似字符串的
name
属性。为了实现你想做的事情,你应该使用 Cypher 投影。
CALL gds.graph.project.cypher('subapps',
'MATCH (n) WHERE n:App OR (n:Genre AND n.name IN ["Action", "RPG"]) RETURN id(n) AS id',
'MATCH (s)-[:Genre_Category]-(t) RETURN id(s) AS source, id(t) AS target',
{validateRelationship:false})
Cypher 投影的几个指针。为了定义关系,我使用了
(s)-[:Genre_Category]-(t)
模式。注意缺乏关系方向。通过避免关系方向定义,关系将被投影为“无向”。您需要包含 validateRelationship
参数,因为您在节点投影中执行节点过滤,而不是在关系投影中。
我在尝试基于包含字符串的 CQL 创建命名图时遇到了类似的问题。
这没有用!
call gds.graph.project.cypher(
'calendar',
'match (n) where (n.Attendees_Names contains "[email protected]") return
id(n) as id',
'match (m)-[r:ATTENDS_MEETING]-(n) where (n.Meeting_Start_date.month = 1)
AND (n.Meeting_Start_date.year =2023) return id(n) as source, type(r) as
type,id(m) as target'
)
这有效!
match(source:Person)-[r:ATTENDS_MEETING]->(target:Calendar)
where (target.Attendees_Names contains '[email protected]')
AND (target.Meeting_Start_date.month = 1)
AND (target.Meeting_Start_date.year =2023)
WITH gds.alpha.graph.project('attendees', source, target) AS g
RETURN
g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels