Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can RDF model a labeled property graph with edge properties?

I wanted to model partner relationship like the following, which I expressed in the format of labeled property graph.

enter image description here

I wanted to use RDF language to express the above graph, particularly I wanted to understand if I can express the label of the "loves" edge (which is an URI to an article/letter).

I am new to RDF, and I know the RDF can easily express the node properties in the LPG, but is it possible to conveniently express the edge properties?

A bit more context of this question: the reason I wanted use RDF (rather than Gremlin) is that I wanted to add some reasoning capability in the long run.

Further added question: if we choose an RDF model to represent the above LPG, in plain English, I wanted to answer the following questions with SPARQL query:

  1. Is Bob in love with any one?
  2. If so, who is he in love with and why?

How complex would the SPARQL statement be to query out the loveletters.com/123?

like image 549
chen Avatar asked Apr 28 '19 00:04

chen


People also ask

What is graph in RDF?

This linking structure forms a directed, labeled graph, where the edges represent the named link between two resources, represented by the graph nodes. This graph view is the easiest possible mental model for RDF and is often used in easy-to-understand visual explanations.

What is a labeled property graph?

A labeled property graph (LPG) is a type of graph database. In LPG-style databases the graph is comprised of nodes and relationships. Each node or relationship has an ID tag, one or more “labels” describing its type or class, and a set of “properties” that present values and a corresponding key to allow referencing.

Does Neo4j support RDF?

neosemantics (n10s) is a plugin that enables the use of RDF and its associated vocabularies like (OWL,RDFS,SKOS and others) in Neo4j. RDF is a W3C standard model for data interchange. You can use n10s to build integrations with RDF-generating / RDF-consuming components.


1 Answers

RDF doesn't support edge properties, so the brief answer is no. But of course there are ways to model this kind of thing in RDF.

Plain RDF triple without edge properties

If we didn't want to annotate the edge, the relationship between Bob and Mary would simply be a triple with Bob as Subject, Mary as object, and “loves” as predicate:

PREFIX : <http://example.org/ontology#>
PREFIX person: <http://example.org/data/person/>

person:Bob :loves person:Mary.

So how can we add annotations?

Option 1: Using RDF Reification

RDF has a built-in solution called “RDF reification”. It allows making statements about statements:

PREFIX : <http://example.org/ontology#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX person: <http://example.org/data/person/>
PREFIX statement: <http://example.org/data/statement/>

person:Bob :loves person:Mary.

statement:1 a rdf:Statement;
    rdf:subject person:Bob;
    rdf:predicate :loves;
    rdf:object person:Mary;
    :reason <http://loveletters.com/123>.

So we say that there is a statement with Bob as subject, Mary as object, and “loves” as predicate. Then we can add properties to that statement. The downside is that it is kind of redundant. First we add the “loves” triple, then we add four more triples to replicate the “loves” triple.

Option 2: Modelling relationships as entities

Another approach is to change the model. Instead of considering “loves” an edge between people, we consider it a node in itself. A node that represents the relationship, and is connected to the two parties involved.

PREFIX relationship: <http://example.org/data/relationship/>

relationship:1 a :LovesRelationship;
    :who person:Bob;
    :whom person:Mary;
    :reason <http://loveletters.com/123>.

So in our model we created a class :LovesRelationship that represents “loves”, and properties :who and :whom to indicate the two parties. The downside of this approach is that the graph structure no longer directly represents our social network. So when querying how two people are related, we always have to go through those relationship entities instead of just dealing with edges connecting people.

Option 3: Using RDF*

There is a proposal called RDF* that addresses this problem quite nicely. (Sometimes it's called RDR or Reification Done Right.) RDF*/RDR adds new syntax that allows triples to be the subject of other triples:

<<person:Bob :loves person:Mary>>
    :reason <http://loveletters.com/123>.

The downside is that it is non-standard and so far supported only by a few systems (Blazegraph, AnzoGraph, and an extension for Jena). As of April 2019, Neptune is not among them.

Query: Is Bob in love with anyone?

This is easy to do in the basic RDF version as well as in Option 1 and Option 3:

ASK { person:Bob :loves ?anyone }

Option 2 requires a different query, because of the changed model:

ASK {
   ?rel a :LovesRelationship;
       :who person:Bob.
}

This would match any :LovesRelationship where the :who property is Bob, regardless of the :whom and :reason properties.

Query: Who is Bob in love with and why?

Option 1, RDF Reification:

SELECT ?whom ?why {
    ?statement a rdf:Statement;
        rdf:subject person:Bob;
        rdf:predicate :loves;
        rdf:object ?whom;
        :reason ?why.
}

I find this query not very intuitive, because it talks about RDF statements, while we are really interested in people and relationships.

Option 2, relationship modelled as entity:

SELECT ?whom ?why {
    ?rel a :LovesRelationship;
        :who person:Bob;
        :whom ?whom;
        :reason ?why.
}

This is better in my eyes; once you have accepted that relationships are entities in this model, it becomes fairly intuitive.

Option 3, RDF*, using SPARQL*:

SELECT ?whom ?why {
    <<person:Bob :loves ?whom>>
        :reason ?why.
}

This is concise and intuitive, so it's a shame we can't currently use it in most SPARQL systems!

like image 189
cygri Avatar answered Nov 02 '22 17:11

cygri