Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the semantically correct way to insert JSON-LD into Neo4j?

For example, here are two linked nodes I want to insert:

{
  "@context": "http://schema.org",
  "@id": "some_organization_id",
  "@type": "Organization",
  "name": "Some Awesome Company",
  "image": [
     "http://someawesomecompany.com/logo.jpg",
     { "@id": "some_image_id" }
  ]
}

{
  "@context": "http://schema.org",
  "@id": "some_image_id",
  "@type": "ImageObject",
  "contentUrl": "http://instagram.com/blahblah",
  "thumbnail: "...",
  "caption: "..."
}

Note how the property "image" can contain multiple objects, which can be either text OR point to other nodes.

Neo4j seems to differentiate between "properties" and "relationships". Is there a way in Neo4j or similar graph database where relationships and properties are one and the same thing, and the value of a property can just point to another node?

like image 524
wuxiekeji Avatar asked Mar 17 '15 12:03

wuxiekeji


2 Answers

In Neo4j relationships are themselves objects and can contain their own properties.

There is nothing preventing you from keeping a reference to another node in a property but it is not advisable as the database keeps track of that for you.

Using Neo4j for your example, you could create other nodes with the images and simply create a relationship between organization node and the image nodes.

If you need information about the relationship for a particular node there is lots of detail available via the ReST interface though there are multiple properties returned in the JSON object that comes back that describe the relationships for that node.

"outgoing_relationships": "http://localhost:7474/db/data/node/1/relationships/out"
"all_typed_relationships": "http://localhost:7474/db/data/node/1/relationships/all/{-list|&|types}"
"outgoing_typed_relationships": "http://localhost:7474/db/data/node/1/relationships/out/{-list|&|types}"
"incoming_relationships": "http://localhost:7474/db/data/node/1/relationships/in"
"create_relationship": "http://localhost:7474/db/data/node/1/relationships"
"all_relationships": "http://localhost:7474/db/data/node/1/relationships/all"
"incoming_typed_relationships": "http://localhost:7474/db/data/node/1/relationships/in/{-list|&|types}   

Likewise for relationships there are properties in the JSON doc that comes back that describe the start node and end node that are connected to the relationship.

"start": "http://localhost:7474/db/data/node/2"
"end": "http://localhost:7474/db/data/node/22"
like image 120
Dave Bennett Avatar answered Nov 01 '22 10:11

Dave Bennett


Graph Databases like Neo4j are quite close to the object oriented model that also represents real world information pretty well.

There are properties that inherently belong to an entity, like a name, size, age, description.

And then there are semantic relationships like knows, owns, works-at, lives-in, contains that capture the connections between entities.

This kind of model is much easier to understand and handle for most people than the totally normalized model of RDF and (perhaps) JSON-LD.

But depending on the domain (ontology) it should be pretty straightforward (with common sense, knowledge of the domain and use-case) to decide what should become a real relationship and what is just an attribute or property on the node.

like image 28
Michael Hunger Avatar answered Nov 01 '22 09:11

Michael Hunger