SHACL help

63 views
Skip to first unread message

cbur...@healthwise.org

unread,
Sep 11, 2020, 6:02:48 PM9/11/20
to TopBraid Suite Users
These questions are more about SHACL than about EDG per se, but I think you experts will be able to help me.

1. sh:disjoint: I have used sh:disjoint to declare that the sh:path of a property shape is disjoint with another another property, like this:

ex:Concept-property
   a sh:PropertyShape ;
   sh:path ex:property ;
   sh:disjoint ex:property2 .

Testing this out in EDG 6.4.1 yields no constraint violations when I assign values to a certain instance of ex:Concept for both ex:property and ex:property2. Have I set this up incorrectly, or do I need to do something else to make EDG raise warnings in this situation?

2. Inferring data: Suppose ex:property and ex:property2 are disjoint for a given shape, as specified above. If an instance of ex:Concept has exactly one value for either ex:property or ex:property2, I would like to infer that this is the value of ex:property3. How could this be modeled? 
 
2. A different property pair constraint: This case is nearly the opposite of the above. Suppose I wish to specify that any value of ex:property4 (which has sh:maxCount 1) must be one of the values of ex:property5 (which has no sh:maxCount). How would I express that? (I don't see a way to do it using sh:equals.)

Thanks for any insight you can provide.

Irene Polikoff

unread,
Sep 11, 2020, 7:21:49 PM9/11/20
to topbrai...@googlegroups.com

On Sep 11, 2020, at 6:02 PM, cbur...@healthwise.org <cbur...@healthwise.org> wrote:

These questions are more about SHACL than about EDG per se, but I think you experts will be able to help me.

1. sh:disjoint: I have used sh:disjoint to declare that the sh:path of a property shape is disjoint with another another property, like this:

ex:Concept-property
   a sh:PropertyShape ;
   sh:path ex:property ;
   sh:disjoint ex:property2 .

Testing this out in EDG 6.4.1 yields no constraint violations when I assign values to a certain instance of ex:Concept for both ex:property and ex:property2. Have I set this up incorrectly, or do I need to do something else to make EDG raise warnings in this situation?

Disjoint means that a given resource cannot have the same value for ex; property as for ex:property2.  E.g., a pref label for resource X can’t be the same as alLabel for resource X. Is this what you meant?

Or do you mean something else i.e., it either have a value for ex:property or a value for ex:property2 e.g., either foaf:givenName or foaf:firstName, but not both. If so, then use xone: https://www.w3.org/TR/shacl/#XoneConstraintComponent

2. Inferring data: Suppose ex:property and ex:property2 are disjoint for a given shape, as specified above. If an instance of ex:Concept has exactly one value for either ex:property or ex:property2, I would like to infer that this is the value of ex:property3. How could this be modeled? 

The exact expression depends on your answer to the first question.
 
2. A different property pair constraint: This case is nearly the opposite of the above. Suppose I wish to specify that any value of ex:property4 (which has sh:maxCount 1) must be one of the values of ex:property5 (which has no sh:maxCount). How would I express that? (I don't see a way to do it using sh:equals.)

SPARQL-based constraint

Thanks for any insight you can provide.


--
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/edfc34b2-9f78-42f3-a186-44bde1dd23cdn%40googlegroups.com.

Holger Knublauch

unread,
Sep 11, 2020, 9:10:17 PM9/11/20
to topbrai...@googlegroups.com


On 12/09/2020 09:21, Irene Polikoff wrote:


On Sep 11, 2020, at 6:02 PM, cbur...@healthwise.org <cbur...@healthwise.org> wrote:

These questions are more about SHACL than about EDG per se, but I think you experts will be able to help me.

1. sh:disjoint: I have used sh:disjoint to declare that the sh:path of a property shape is disjoint with another another property, like this:

ex:Concept-property
   a sh:PropertyShape ;
   sh:path ex:property ;
   sh:disjoint ex:property2 .

Testing this out in EDG 6.4.1 yields no constraint violations when I assign values to a certain instance of ex:Concept for both ex:property and ex:property2. Have I set this up incorrectly, or do I need to do something else to make EDG raise warnings in this situation?

Disjoint means that a given resource cannot have the same value for ex; property as for ex:property2.  E.g., a pref label for resource X can’t be the same as alLabel for resource X. Is this what you meant?
In case you're stuck, a minimal complete example would allow us to reproduce it.


Or do you mean something else i.e., it either have a value for ex:property or a value for ex:property2 e.g., either foaf:givenName or foaf:firstName, but not both. If so, then use xone: https://www.w3.org/TR/shacl/#XoneConstraintComponent

2. Inferring data: Suppose ex:property and ex:property2 are disjoint for a given shape, as specified above. If an instance of ex:Concept has exactly one value for either ex:property or ex:property2, I would like to infer that this is the value of ex:property3. How could this be modeled? 

The exact expression depends on your answer to the first question.
 
2. A different property pair constraint: This case is nearly the opposite of the above. Suppose I wish to specify that any value of ex:property4 (which has sh:maxCount 1) must be one of the values of ex:property5 (which has no sh:maxCount). How would I express that? (I don't see a way to do it using sh:equals.)

SPARQL-based constraint

Yes or dash:subSetOf already implements this SPARQL constraint:

http://datashapes.org/constraints.html#SubSetOfConstraintComponent

Holger

cbur...@healthwise.org

unread,
Sep 15, 2020, 2:24:20 PM9/15/20
to TopBraid Suite Users
Thanks for the help. I was indeed confused about the meaning of sh:disjoint

I have written a basic sh:xone constraint like this:

  sh:xone (
      [
        sh:property [
            sh:path concept_schema:preferred_specialty ;
          ] ;
      ]
      [
        sh:property [
            sh:path concept_schema:preferred_specialty_inferred ;
          ] ;
      ]
    ) ;
.

where concept_schema:preferred_specialty has only explicit values and concept_schema:preferred_specialty_inferred has only inferred values.

But now, in my concept data, whether 0, 1, or 2 of these properties has a value, I am still getting a constraint violation saying:
Value has 2 shapes out of 2 in the sh:xone enumeration

What could I be doing wrong?

Irene Polikoff

unread,
Sep 15, 2020, 2:35:06 PM9/15/20
to topbrai...@googlegroups.com
When minCount is not stated, it means minCount = 0.

Thus, 

sh:property [
            sh:path concept_schema:preferred_specialty ;
          ] ;

Is the same as

sh:property [
            sh:path concept_schema:preferred_specialty ;
            sh:minCount 0;
          ] ;

The same with the other shape.

So, indeed, irrespective of how many values you have, your data conforms to both shapes and it must conform to only one of them.

Add sh:minCount 1 to both property shapes. Then, you get a violation only of you have both properties populated or neither properties populated.

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

Carl Burnett

unread,
Sep 15, 2020, 3:37:16 PM9/15/20
to topbrai...@googlegroups.com

I guess this makes sense. I added a sh:minCount of 1.

 

Now I get no violation when concept_schema:preferred_specialty has a value. But I still get a violation when only concept_schema:preferred_specialty_inferred has a value. I imagine this is because it can only have inferred values and not explicit ones, or perhaps because the sh:path of the property shape is a magic property. This is what the property shape looks like:

 

concept_schema:HwcvConcept-has_inferred_specialty

  a sh:PropertyShape ;

  sh:path <http://metadata.healthwise.org/app/magic-props#has_inferred_specialty> ;

  rdfs:label "managing specialties (inferred)" ;

  sh:class concept_schema:SpecialtyConcept ;

  sh:group concept_schema:Ontological_Relationships ;

  sh:name "managing specialties (inferred)" ;

  sh:nodeKind sh:IRI ;

  sh:order 8.1 ;

  sh:values [

      <http://metadata.healthwise.org/app/magic-props#has_inferred_specialty> (

          sh:this

        ) ;

    ] ;

.

 

Is there anything I can do to tell the SHACL engine that inferred values for has_inferred_specialty should meet my sh:xone constraint?

 

As an aside: the phrasing of the constraint violation message for sh:xone could be a lot better. My taxonomy’s users don’t know or care what a “sh:xone enumeration” means. What would be helpful to them is a message like this: “Either [concept 1] or [concept 2] should have a value, but not both.”

 

 

From: topbrai...@googlegroups.com <topbrai...@googlegroups.com> On Behalf Of Irene Polikoff
Sent: Tuesday, September 15, 2020 11:35 AM
To: topbrai...@googlegroups.com
Subject: Re: [topbraid-users] SHACL help

 

*** External email: use caution ***

--
You received this message because you are subscribed to a topic in the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/topbraid-users/04w-ddzQ81I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/1F2112E2-0562-45D2-9DA2-73A8DCAAE555%40topquadrant.com.

cbur...@healthwise.org

unread,
Sep 15, 2020, 4:13:44 PM9/15/20
to TopBraid Suite Users

2. A different property pair constraint: This case is nearly the opposite of the above. Suppose I wish to specify that any value of ex:property4 (which has sh:maxCount 1) must be one of the values of ex:property5 (which has no sh:maxCount). How would I express that? (I don't see a way to do it using sh:equals.)

 

SPARQL-based constraint

Yes or dash:subSetOf already implements this SPARQL constraint:

http://datashapes.org/constraints.html#SubSetOfConstraintComponent

Holger


Holger, when using dash:subSetOf, is there a way to put an or in there? Like, a property's value must be a subset of property_1 OR property_2? 

Holger Knublauch

unread,
Sep 15, 2020, 7:38:48 PM9/15/20
to topbrai...@googlegroups.com

One option is to surround it with an outer sh:or, e.g.

ex:TestShape
    a sh:NodeShape ;
    sh:or (
        [
            sh:property [
                sh:path ex:property1 ;
                dash:subSetOf ex:other ;
            ]
        ]
        [
            sh:property [
                sh:path ex:property2 ;
                dash:subSetOf ex:other ;
            ]
        ]
    ) .

Depending on your desired semantics, you may also use a | path expression:

ex:TestShape
    a sh:NodeShape ;
    sh:property [
        sh:path [
            sh:alternativePath ( ex:property1 ex:property2 )
        ] ;
        dash:subSetOf ex:other ;
    ] .

The meaning of the latter is that the combined values of prop1 and prop2 must be a subset, so this may not be the exact semantics that you need.

Holger


Holger Knublauch

unread,
Sep 15, 2020, 7:54:34 PM9/15/20
to topbrai...@googlegroups.com


On 16/09/2020 05:37, Carl Burnett wrote:

I guess this makes sense. I added a sh:minCount of 1.

 

Now I get no violation when concept_schema:preferred_specialty has a value. But I still get a violation when only concept_schema:preferred_specialty_inferred has a value. I imagine this is because it can only have inferred values and not explicit ones, or perhaps because the sh:path of the property shape is a magic property. This is what the property shape looks like:

 

concept_schema:HwcvConcept-has_inferred_specialty

  a sh:PropertyShape ;

  sh:path <http://metadata.healthwise.org/app/magic-props#has_inferred_specialty> ;

  rdfs:label "managing specialties (inferred)" ;

  sh:class concept_schema:SpecialtyConcept ;

  sh:group concept_schema:Ontological_Relationships ;

  sh:name "managing specialties (inferred)" ;

  sh:nodeKind sh:IRI ;

  sh:order 8.1 ;

  sh:values [

      <http://metadata.healthwise.org/app/magic-props#has_inferred_specialty> (

          sh:this

        ) ;

    ] ;

.

 

Is there anything I can do to tell the SHACL engine that inferred values for has_inferred_specialty should meet my sh:xone constraint?

Up to 6.4, SHACL validation does not "see" the inferred values unless you have asserted them beforehand.

From 7.0 onwards, you can activate these inferences to be computed beforehand, by adding a triple

    ?ontology sh:entailment sh:Rules .

The latter should already work with the latest SHACL API snapshot.


 

As an aside: the phrasing of the constraint violation message for sh:xone could be a lot better. My taxonomy’s users don’t know or care what a “sh:xone enumeration” means. What would be helpful to them is a message like this: “Either [concept 1] or [concept 2] should have a value, but not both.”

I agree the current message template

"Value has " + count + " shapes out of " + shapes.size() + " in the sh:xone enumeration"

is a bit geeky. It would be doable to change it to "Value must conform to exactly one of the following shapes, but conforms to N: ..., ..., ...]"

It would be much harder to construct a message as you suggest because that would require deeper understanding of the mentioned shapes.

Holger


Reply all
Reply to author
Forward
0 new messages