我想使用每个节点和根(主要主题分类)之间返回的最短路径来构建图形。我使用以下查询
MATCH ()-[:SUBJECT]->(c:Category)
UNWIND NODES(c) AS nd // to get all the nodes on which I want to iterate
FOREACH(n in nd|
WITH n as start
path = allShortestPaths((start)-[:SUBCAT_OF*]-> (p1:Category {catName: "Main_topic_classifications"}))
UNWIND RELATIONSHIPS(path) AS rel
WITH STARTNODE(rel) AS s, ENDNODE(rel) AS e
MERGE (s)-[:NEW_SUBCAT]->(e)
)
对于每个节点c,我尝试计算所有到达根的最短路径,然后使用返回的路径结果创建一个新的关系(NEW_SUBCAT)。但是,当我运行上一个查询时,出现以下错误:
Neo.ClientError.Statement.SyntaxError: Invalid input '(': expected an identifier character, whitespace, NodeLabel, a property map or ')' (line 5, ...)
答案 0 :(得分:0)
这个更简单的查询可以满足您的要求(FOREACH
完全没有必要):
MATCH (start:Category)
WHERE ()-[:SUBJECT]->(start)
MATCH path = allShortestPaths((start)-[:SUBCAT_OF*]-> (p1:Category {catName: "Main_topic_classifications"}))
UNWIND RELATIONSHIPS(path) AS rel
WITH STARTNODE(rel) AS s, ENDNODE(rel) AS e
MERGE (s)-[:NEW_SUBCAT]->(e)