Search code examples
rdfowlontologyshaclshex

SHACL/ShEX constraint to make a property to build a hierarchy (i.e. a tree)


I have very little knowledge of SHACL and ShEx.

I've been reading about them and to figure out whether I could create constraints over a property to make it define a hierarchy (i.e. a tree-like structure).

I guess what I'm looking for is a way to specify that, for a given property p,

a) this can happen (o1 != o2):

   s p o1 .
   s p o2 .
   ...
   s p oN

b) but this cannot (s1 != s2):

   s1 p o .
   s2 p o

I guess for a) I should use some kind of constraint on the cardinality of p, right?

No idea on how to specify b) or even if it is possible at all using either SHACL or ShEX. Should I be using OWL?


Solution

  • In OWL

    Assuming DifferentIndividuals: :s1, :s2 etc.:

    ObjectProperty: :p
      Characteristics: InverseFunctional
    

    In ShEx

    With shape map like {_ :p FOCUS} @ :Shape:

    :Shape { 
      ^:p IRI ?
    }
    

    Example

    In SHACL

    :Shape a sh:NodeShape ;
      sh:targetObjectsOf :p ;
      sh:property [
        sh:path [ sh:inversePath :p ] ;
        sh:maxCount 1 
      ] .
    

    Example

    In pure SPARQL

    ASK { ?o ^:p ?s1, ?s2 . FILTER (?s1 != ?s2) }
    

    In general

    Read "Validating RDF Data".