RDF vs Property GRAPH (NoSQL) database

RDF Graph example (Query language: SPARQL)

As a framework for representing the Web, Resource Description Framework (RDF) captures structure using a triple, the basic unit in RDF. A triple is a statement with three elements: two nodes connected by an edge (also known as a relationship). Each triple is identified by a Uniform Resource Identifier (URI) as subject-predicate-object:

– The subject is a resource (node) in the graph;
– The predicate represents an edge (relationship)
– The object is another node or a literal value.

More information:
https://rdf4j.org/documentation/tutorials/getting-started/

Property Graph example (Query Language: Cypher)

Information is organized as nodes, relationships, and properties in a property graph. Nodes are tagged with one or more labels, identifying their role in the network. Nodes can also store any number of properties as key-value pairs. Relationships provide directed, named connections between two nodes. Relationships always have a direction, a type, a start node, and an end node, and they can have properties, just like nodes. Although relationships are always directed, they can be navigated efficiently in either direction.


What is the difference between SPARQL and Cypher Query Language?
– SPARQL is the query language for accessing data in the Resource  description Framework (RDF) GRAPH database.
– Cypher is the corresponding language for the data represented in property GRAPH database

More information:
https://neo4j.com/blog/rdf-vs-property-graphs-knowledge-graphs/

Cypher queries examples

INSERT
CREATE (diana:Person {name: “Diana”})
CREATE (melissa:Person {name: “Melissa”, twitter: “@melissa”})
CREATE (xyz:Company {name: “XYZ”})
CREATE (diana)-[:WORKS_FOR]->(xyz)
CREATE (diana)-[:IS_FRIENDS_WITH]->(melissa)

UPDATE
MATCH (p:Person {name: ‘Diana’}) SET p.birthdate = date(‘1980-01-01’)
MATCH (:Person {name: ‘Diana’})-[rel:WORKS_FOR]-(:Company {name: ‘XYZ’}) SET rel.startYear = date({year: 2018})

DELETE
MATCH (j:Person {name: ‘Diana’})-[r:IS_FRIENDS_WITH]->(m:Person{name: ‘Melissa’}) DELETE j,r,m

SELECT
MATCH (p:Product) RETURN p.productName, p.unitPrice ORDER BY p.unitPrice DESC LIMIT 10;

SPARQL examples

INSERT

PREFIX plaat: <http://www.plaatsoft.nl/>
INSERT DATA {
<http://leerling/1> plaat:firstName “Kees”.
<http://leerling/2> plaat:firstName “Jan”.
<http://leerling/3> plaat:firstName “Piet”.
<http://leerling/4> plaat:firstName “Klaas”.
<http://school/1> plaat:name “Bospark”.
<http://school/1> plaat:level “LTS”.
<http://school/1> plaat:city “Alphen aan den Rijn”.
<http://school/2> plaat:name “Lammerschans”.
<http://school/2> plaat:level “MTS”.
<http://school/2> plaat:city “Leiden”.
<http://school/3> plaat:name “Hogeschool van Utrecht”.
<http://school/3> plaat:level “HTS”.
<http://school/3> plaat:city “Utrecht”.
<http://leerling/1> plaat:school <http://school/1>.
<http://leerling/1> plaat:school <http://school/2>.
<http://leerling/1> plaat:school <http://school/3>.
<http://leerling/2> plaat:school <http://school/1>.
<http://leerling/3> plaat:school <http://school/2>.
}

QUERY
# Show all leerlingen of school1
PREFIX plaat: <http://www.plaatsoft.nl/>
SELECT ?x ?firstName
WHERE
{
?x plaat:firstName ?firstName.
?x plaat:school <http://school/1>
}

DELETE
PREFIX plaat: <http://www.plaatsoft.nl/>
DELETE { ?x plaat:firstName ‘Kees’ }
WHERE { ?x plaat:firstName ‘Kees’ }

UPDATE (SPARQL use delete / insert pattern)
PREFIX plaat: <http://www.plaatsoft.nl/>
DELETE { ?x plaat:firstName ‘Kees’ }
INSERT { ?x plaat:firstName ‘William’ }
WHERE { ?x plaat:firstName ‘Kees’ }