Hi guys,
I am in desperate need of some help. I am trying to add data from a JSON file to model it as a graph. The difficulty I am having is that I have many dynamic labels for properties on nodes, I also need to create relationships depending on whether a particular label is present or not. My code currently looks like this:
call apoc.load.json('file') Yield value as pages
FOREACH (page in pages|
create (n:Article {title: page.title, in_categories: page.in_categories, created_by: '$self'})
foreach (attr in page.attributes|
k = attr.attrName
v = []
foreach(val in attr.attrValues|
v = v+val.value
case
when val.type is 'link' then merge (m: Article {title: val.value})
on create set m.created_by = page.title
foreach (interval in val.timestamps|
call apoc.create.relationship(n, k, {start_time:datetime(interval[0]), end_time: datetime(interval[1])}, m))
end)
call apoc.create.setProperty(n, k, v)))
foreach(obj in page.content|
l = obj.value
merge (m: Article {title: l})
on create set m.created_by = page.title
foreach (interval in obj.timestamps|
call apoc.create.relationship(n, "TEXT_LINK", {start_time:datetime(interval[0]), end_time: datetime(interval[1])}, m))
end)
)
But this does not work. Would anybody have any ideas to help me get this working? It would be much appreciated!
If you are wondering a single page object in the JSON file is structured as follows:
{
'title': atomic
'in_categories': set of atomic
'attributes':
[{attrName: atomic,
attrValues: [
{value: atomic,
type: "atomic"|"link",
timestamps: [[ts1, ts2], [ts3, ts4]]
}, {...}]
'content':
[{value: atomic,
type: link
context_bfr: text
context_aftr: text
timestamps: [[ts1, ts2], [ts3, ts4], ...]}, {...}]
}