Search code examples
graphnodesrdfedges

Is it possible to define multiple predicates between a subject and object in RDF?


I want to persist a RDF Graph, where the predicates are the property edges and the subjects/predicates are the nodes. Now I want to know if multiple edges between two nodes are possible and legal in the rdf semantic.

As example:

Tom -loves->julia Tom -liveswith->julia

Is this in this form possible? Or would I model this in a different way?


Solution

  • Yes, it's quite possible. It's just two triples. E.g., in Turtle, it might look like:

    @prefix : <urn:ex:>.
    
    :Tom :loves :Julia .
    :Tom :livesWith :Julia .
    

    or even more concisely:

    @prefix : <urn:ex:>.
    
    :Tom :loves :Julia ;
         :livesWith :Julia .
    

    A RDF graph is just a set of triples. There's no constraint on how many of those triples happen to have the same subject and object.

    In fact, since RDFS has a subPropertyOf relationship, having multiple relationships between the same resources is pretty much required. E.g., you might have:

    :hasSon rdfs:subPropertyOf :hasChild .
    

    That means that when you have

    :X :hasSon :Y
    

    you can infer

    :X :hasChild :Y
    

    which is another triple that relates the same subject and object.