我正在尝试通过一次调用 apoc.load.json() 来展开多个数组属性。我拥有的版本不能完全正常工作:一些关系没有被加载。我的猜测是,这是由于通过 WITH 命令进行的输出管道。如果我为每个基于数组的属性分别运行展开,我可以将其全部加载,但我很好奇如何将它们一起完成。
感谢任何见解和指示=)
//LOAD CLASSES AND UNWIND COMMON ITEMS,COMPANIONS,LOCATIONS
CALL apoc.load.json("file:///c://pathToFile//classes.json") YIELD value AS class
MERGE (c:Class {name: class.name})
SET
c.strength = class.strength,
c.intelligence = class.intelligence,
c.dexterity = class.dexterity,
WITH c, class.items AS items, class.companions AS companions, class.locations AS locations
UNWIND items AS item
UNWIND companions AS companion
UNWIND locations AS location
MERGE (i:Item {name: item})
MERGE (i)-[:LIKELY_HAS]->(c)
MERGE (c)-[:LIKELY_BELONGS_TO]->(i)
MERGE (comp:Class {name: companion})
MERGE (comp)-[:LIKELY_COMPANION_OF]->(c)
MERGE (c)-[:LIKELY_ACCOMPANIED_BY]->(comp)
MERGE (l:Location {name: location})
MERGE (l)-[:LIKELY_LOCATION_OF]->(c)
MERGE (c)-[:LIKELY_LOCATED_IN]->(l)
JSON 文件中的示例条目:
{
"name": "KNIGHT",
"strength": [75,100],
"intelligence": [40,80],
"dexterity": [40,85],
"items": [
"SWORD",
"SHIELD"
],
"companions":[
"KNIGHT",
"SERVANT",
"STEED"
],
"locations": [
"CASTLE",
"VILLAGE",
"CITY"
]
}