SHACL-SPARQL not reporting constraint violation

This is likely a syntax error on my part, but I am hoping someone can help me out because it will serve as an example in a larger project.

Referring to the attached data file minEx-Data.ttl, :Animal_00M02 should violate the constraint where End Date must be greater than or equal to Begin Date as written in the SHACL file minEx-SHACL.TTL. The query itself is correct as proven by executing minEx-RawQueryThis.rq which returns the correct observation that contains the error (Animal_00M02).

Suggestions greatly appreciated!

PS: Would love to see more documentation, and examples, or a webinar for advanced SHACL-SPARQL in Stardog. :slight_smile:

minEx-Data.TTL (940 Bytes) minEx-RawQueryThis.rq (535 Bytes) minEx-SHACL.TTL (991 Bytes)

I got to thinking, maybe this is an issue with the date comparison, even though it works in SPARQL. So I wrote this (rather pathetic) kludge and once again it works as a SPARQL query, but not as SHACL-SPARQL. Is anyone able to reproduce this problem?

SELECT $this ?beginDate ?endDate
  $this :hasReferenceInterval ?interval .
  ?interval :ReferenceBegin   ?beginIRI ;
            :ReferenceEnd     ?endIRI .
  ?beginIRI time:inXSDDate    ?beginDate .
  ?endIRI   time:inXSDDate    ?endDate .
  BIND (year(?beginDate)*10000 + 
        month(?beginDate)*100 +
        day(?beginDate)  AS ?beginDateInt )
  BIND (year(?endDate)*10000 + 
        month(?endDate)*100 +
        day(?endDate)  AS ?endDateInt )
 FILTER  (! (xsd:integer(?endDateInt) >= xsd:integer(?beginDateInt) ))

Hi Tim,

It looks like your constraint has two issues:

  1. You declare the time prefix in your SHACL, but not the base prefix! You want:
sh:prefixes [
    sh:declare [
      sh:prefix "time" ;
      sh:namespace ""^^xsd:anyURI ;
    ], [
      sh:prefix "" ;
      sh:namespace ""^^xsd:anyURI ;
  ] ;
  1. Your focus node is :ReferenceInterval, however the way your query is written, $this will only ever be bound to :AnimalSubject entities. I rewrote the query so that ?interval is now $this as follows:
  """SELECT $this (?beginDate AS ?intervalStart) (?endDate AS ?intervalEnd)
    WHERE {
      $this     :ReferenceBegin       ?beginIRI ;
                :ReferenceEnd         ?endIRI .
      ?beginIRI time:inXSDDate        ?beginDate .
      ?endIRI   time:inXSDDate        ?endDate .
      FILTER  (! (?endDate >= ?beginDate ))
    }""" ;

Adding this constraint, I was able to see a violation. I'm assuming this doesn't rewrite the constraint in a way that makes it not what you're looking for, but if it does, let me know and we can look more into it.

Thank you! This works, and makes sense. I wish there were more detailed SHACL-SPARQL examples available.

Other than executing a follow-up query, is there a way to to identify in the report which AnimalSubject has the interval that trips the constraint? I expect this is outside of the scope of SHACL-SPARQL.

Thanks again. Case closed (and it was my syntax all along)

Stephen, If you want to grab some easy Stackoverflow reputation karma, you can copypasta to my question on StackOverflow. I just put a bounty on it this afternoon. Enjoy a sweet +50 . :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.