我想从我的Json文件中读取关系,而不是对其进行硬编码。例如:代替MERGE(arg1)-[:relation]->(arg2) 我想要类似:MERGE(arg1)-[:v.relation]->(arg2)。 我的Json文件如下:
{
"bacf06771e0f4fc5a8e68c30fc77c9c4": {
"arg1": "the Treasury",
"arg2": "details of the November refunding",
"relation": "will announce",
"id": "bacf06771e0f4fc5a8e68c30fc77c9c4",
"linkedContexts": [
{
"targetID": "948eeebd73564adab7dee5c6f177b3b9",
"classification": "CONTRAST"
}
]
},
"948eeebd73564adab7dee5c6f177b3b9": {
"arg1": "the funding",
"arg2": "",
"relation": "will be delayed",
"id": "948eeebd73564adab7dee5c6f177b3b9",
"linkedContexts": [
{
"targetID": "006a71e51295440fab7a8e8c697d2ba6",
"classification": "CONDITION"
}
]
}
}
我尝试过:
CALL apoc.load.json("files:///example.json") YIELD value
UNWIND [k IN KEYS(value) | value[k]] AS v
MERGE (arg1:Arg1 {subject:v.arg1})
MERGE (arg2:Arg2 {object:v.arg2})
MERGE (arg1)-[:v.relation]->(arg2)
我收到此错误:
Neo.ClientError.Statement.SyntaxError: Invalid input '.': expected an identifier character, whitespace, '|', a length specification, a property map or ']' (line 13, column 17 (offset: 444))
"merge (arg1)-[:v.relation]->(arg2) "
^
答案 0 :(得分:0)
当前,无法使用Cypher动态创建关系。
您可以使用apoc's apoc.merge.relationship procedure动态创建节点/关系。
CALL apoc.load.json("files:///example.json") YIELD value
UNWIND [k IN KEYS(value) | value[k]] AS v
MERGE (arg1:Arg1 {subject:v.arg1})
MERGE (arg2:Arg2 {object:v.arg2})
CALL apoc.merge.relationship(arg1,v.relation,{},{},arg2) YIELD rel
RETURN count(*);