Uniqueness constraint across multiple concepts

30 views
Skip to first unread message

cbur...@healthwise.org

unread,
Jan 23, 2020, 7:59:52 PM1/23/20
to TopBraid Suite Users
What if I wanted to create a constraint (in SHACL, perhaps) specifying that two concepts may not share the same object for a particular property? I would want a warning to be raised when a user attempts to save a concept containing the triple

ex:ConceptX ex:property ex:ConceptY

if somewhere else in the vocabulary there already exists the triple

ex:ConceptZ ex:property ex:ConceptY 

It occurs to me that such a rule is already enforced for the skos:prefLabel property in EDG, but I don't know how this is being done "under the hood." Can anyone advise how to create a similar constraint? Thanks.

Jack Hodges

unread,
Jan 24, 2020, 9:50:21 AM1/24/20
to TopBraid Suite Users
Did you try writing a SPARQL constraint?

Holger Knublauch

unread,
Jan 25, 2020, 6:44:03 PM1/25/20
to topbrai...@googlegroups.com

Hi Carl,

here is a design pattern for this:

    ex:UniqueValueShape
      a sh:PropertyShape ;
      sh:targetObjectsOf ex:property ;
      sh:path [ sh:inversePath ex:property ] ;
      sh:maxCount 1 .

The above applies to all values of ex:property, i.e. the distinct objects of triples that have ex:property as predicate. It reports a violation if for any of those target nodes, when you walk ex:property in the inverse direction, there are more than one value nodes (i.e. the subjects of the inverse triples).

(Above the property shape itself carries the target statement, but it would of course also work via a NodeShape that has the property shape via sh:property).

HTH
Holger

--
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/7a0925ed-ea55-405a-8e10-9f45677bfdcb%40googlegroups.com.

cbur...@healthwise.org

unread,
Feb 3, 2020, 3:02:20 PM2/3/20
to TopBraid Suite Users
Holger,

Thanks for your advice here. I've tried out what you suggested, but I'm having trouble getting the desired results. I'm sure that I am doing something wrong.

To get more specific about my use case: I want to say that each instance of ex:Code can be the object of ex:exact_code for at most one instance of ex:HwcvConcept, but there should be no restrictions on the number of objects that ex:exact_code may have for any given instance of ex:HwcvConcept.

Both ex:Code and ex:HwcvConcept are already NodeShapes, and a property shape called ex:HwcvConcept-exact_code has already been defined as well. To which of these shapes would I need to add the constraints you suggest -- or would they need to be added to an entirely new shape?

I could also add sh:severity and a sh:message to this shape, right?

thanks,
Carl


On Saturday, January 25, 2020 at 3:44:03 PM UTC-8, Holger Knublauch wrote:

Hi Carl,

here is a design pattern for this:

    ex:UniqueValueShape
      a sh:PropertyShape ;
      sh:targetObjectsOf ex:property ;
      sh:path [ sh:inversePath ex:property ] ;
      sh:maxCount 1 .

The above applies to all values of ex:property, i.e. the distinct objects of triples that have ex:property as predicate. It reports a violation if for any of those target nodes, when you walk ex:property in the inverse direction, there are more than one value nodes (i.e. the subjects of the inverse triples).

(Above the property shape itself carries the target statement, but it would of course also work via a NodeShape that has the property shape via sh:property).

HTH
Holger


On 24/01/2020 10:59, cbur...@healthwise.org wrote:
What if I wanted to create a constraint (in SHACL, perhaps) specifying that two concepts may not share the same object for a particular property? I would want a warning to be raised when a user attempts to save a concept containing the triple

ex:ConceptX ex:property ex:ConceptY

if somewhere else in the vocabulary there already exists the triple

ex:ConceptZ ex:property ex:ConceptY 

It occurs to me that such a rule is already enforced for the skos:prefLabel property in EDG, but I don't know how this is being done "under the hood." Can anyone advise how to create a similar constraint? Thanks.
--
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbrai...@googlegroups.com.

Irene Polikoff

unread,
Feb 3, 2020, 3:19:42 PM2/3/20
to topbrai...@googlegroups.com
It would need to be a new property shape since it is on the inverse path. The one you have right now is for ex:exact_code itself.

If this property always has instances of ex:HwcvConcept as values, then the simplest approach is to attach the new property shape to the ex:HwcvConcept e.g.,

ex:HwcvConcept
      sh:property ex:HwcvConcept-inv-exact_code.

ex:HwcvConcept-inv-exact_code a sh:PropertyShape;
      sh:path [ sh:inversePath ex:exact_code ] ;
      sh:maxCount 1 .

Alternatively, you could also do a property shape that is not attached to a node shape and carries its own target which is what the e-mail suggested.

    ex:UniqueExactCodeShape
      a sh:PropertyShape ;
      sh:targetObjectsOf ex:exact_code ;
      sh:path [ sh:inversePath ex:exact_code ] ;
      sh:maxCount 1 .

To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/f9c26431-d16f-4893-9d05-17a7f10663b0%40googlegroups.com.

Holger Knublauch

unread,
Feb 3, 2020, 6:38:29 PM2/3/20
to topbrai...@googlegroups.com

On 4/02/2020 06:02, cbur...@healthwise.org wrote:
> Holger,
> [...]
>
> I could also add sh:severity and a sh:message to this shape, right?

Yes. These will apply to all constraint violations produced by that shape.

Holger


Reply all
Reply to author
Forward
0 new messages