cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

create graph from json file with relation

Hi I have one problem with my json file (with tokens = nodes and relations)

i need to import token and relation from json file to create graphe thankyou

{
"text": "CVE-2021-34481",
"start": 0,
"end": 14,
"token_start": 0,
"token_end": 2,
"entityLabel": "CVE"
},
{
"text": "Windows Print Spooler",
"start": 15,
"end": 36,
"token_start": 3,
"token_end": 5,
"entityLabel": "SOFTWARE"
},
{
"text": "CVE-2018-0599",
"start": 75,
"end": 88,
"token_start": 12,
"token_end": 14,
"entityLabel": "CVE"
},

"relations": [
{
"child": 3,
"head": 0,
"relationLabel": "CONCERNED_BY",
"propertiesList": [

]
},
{
"child": 23,
"head": 12,
"relationLabel": "CONCERNED_BY",
"propertiesList": [

]
},

1 ACCEPTED SOLUTION

I found it easier to create the graph with two queries, one for the nodes and one for the relationships. Run the nodes first. 

Node Creation:

call apoc.load.json("file:///kg4.json")
yield value
unwind value.tokens as token
call apoc.create.node(["Node", token.entityLabel], {token_start: token.token_start, text: token.text}) 
yield node
return node

Relationship Creation:

call apoc.load.json("file:///kg4.json")
yield value
unwind value.relations as relation
match(n:Node{token_start: relation.head})
match(m:Node{token_start: relation.child})
CALL apoc.create.relationship(n, relation.relationLabel, {}, m) 
yield rel
return rel

 Hope this helps.

View solution in original post

11 REPLIES 11

What does this represent?  How is the data in the json related?  Do you have data model it is to map too?

1 this json file was create with NER annotator for vulnerablity information (cve)

2 the tokens will be the nodes and the end of file you find relations between  tokens.

3 i need create graph with this 2 informations (tokens and relationlabel)

4 every relation between head and child

5  head & child ="token_start" and i need show "entityLabel" in graphe

thank you

 

As I understand it:

  • each token node is represented by its 'token_start' property
  • each relationship defines its two nodes by its 'head' and 'child' properties, which correspond to the 'start_token' for each
  • each token's 'entityLabel' property represents its label
  • each relationship's 'relationLabel' property represents its type

Is this correct? 

hi 

yes that's correct thank you

The json seams to be incomplete. In particular, are the nodes  organized in a list like the relationships? Can you provide the full file?   

I found it easier to create the graph with two queries, one for the nodes and one for the relationships. Run the nodes first. 

Node Creation:

call apoc.load.json("file:///kg4.json")
yield value
unwind value.tokens as token
call apoc.create.node(["Node", token.entityLabel], {token_start: token.token_start, text: token.text}) 
yield node
return node

Relationship Creation:

call apoc.load.json("file:///kg4.json")
yield value
unwind value.relations as relation
match(n:Node{token_start: relation.head})
match(m:Node{token_start: relation.child})
CALL apoc.create.relationship(n, relation.relationLabel, {}, m) 
yield rel
return rel

 Hope this helps.

Hello, i have try 2 queries, first one is ok i can create nodes but second i have just table do you know why? please check my result.

Thank you

https://drive.google.com/file/d/1eNEFgUlLsgaLAHzG-NwC__LJhPvWEk5i/view?usp=sharing

https://drive.google.com/file/d/1W_DeOcCQLKM3ar1KMy4XQVVo-rsJ3_Nn/view?usp=sharing

That is just the output of the query, which returns each created relationship. You need to query the database to see the created data. 

try:

match(n:Node) return n

Thank you all is good