1

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?

andrefs
  • 555
  • 4
  • 14
  • 1
    In OWL: https://www.w3.org/TR/owl2-syntax/#Inverse-Functional_Object_Properties – Stanislav Kralin Aug 09 '20 at 15:11
  • 2
    Though OWL axioms are not constraints but used for inference. So, having an inverse functional property axiom just infers `s1 owl:sameAs s2` and a contradiction only occurs if you explicitly make `s1` and `s2` distinct (or it follows from other axioms) – UninformedUser Aug 09 '20 at 16:12
  • @UninformedUser Exactly, OWL seems to less concerned with constraints and more with adding informaton for inference. That's why I was looking into SHACL or ShEx for these kind of constraints... – andrefs Aug 09 '20 at 17:52
  • 1
    Following @StanislavKralin suggestion, I found this: `sh:maxCount 1 on a sh:inversePath` suggested in https://spinrdf.org/shacl-and-owl.html. I'll try and see whether this solves my problem. – andrefs Aug 09 '20 at 17:55

1 Answers1

3

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".

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58