Problems defining prefixes in SPARQL-based shapes

53 views
Skip to first unread message

Steve Ray

unread,
Mar 22, 2021, 4:40:28 PM3/22/21
to TopBraid Suite Users
I have been working around this problem by avoiding any prefixes when defining a shape with SPARQL, but this still bugs me. Attached are two tiny files, epp1.shapes.ttl and epp2.shapes.ttl.

I'm running the SHACL reasoner.
epp1 works - it does not use any prefixes inside the shape.
epp2 is identical to epp1, except it declares the owl: prefix in the shape. 

TBC complains that it cannot resolve owl:SymmetricProperty.

I have tried following the documentation for this, but clearly I'm getting something wrong. What am I missing?

Steve


epp1.shapes.ttl
epp2.shapes.ttl

Irene Polikoff

unread,
Mar 22, 2021, 5:15:21 PM3/22/21
to topbrai...@googlegroups.com
  a owl:Ontology ;
  owl:imports <http://datashapes.org/dash> ;
  owl:versionInfo "Created with TopBraid Composer" ;
  sh:prefixes [sh:declare [
      sh:namespace "http://www.w3.org/2002/07/owl#"^^xsd:anyURI ;
      sh:prefix "owl" ;
    ] ;];

--
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/CAGUep85Rf1yk3YVsLV3ihJjso7w5uF%2BBGqFOSpPWybBCuGw6nQ%40mail.gmail.com.
<epp1.shapes.ttl><epp2.shapes.ttl>

Steve Ray

unread,
Mar 22, 2021, 6:09:31 PM3/22/21
to TopBraid Suite Users
Wow! I could have saved so much time, had I asked earlier. The W3C SHACL spec example misses the sh:prefixes statement in section 5.2.1 (https://www.w3.org/TR/shacl/#sparql-prefixes).

Now I can go back and do it the way I thought it should work!

Parenthetically, I suppose there might be some rationale behind it, but it seems very cumbersome to have to declare prefixes in three places:

@prefix at the top of the file
sh:prefixes in the Ontology declaration
sh:prefixes in the shape definition.

...and each with a slightly different syntax:
 sh:namespace "http://www.w3.org/2002/07/owl#"^^xsd:anyURI ;

This is really a comment to W3C of course, not TopQuadrant.


Thanks for your speedy reply!
Steve




Steve Ray

unread,
Mar 22, 2021, 6:25:52 PM3/22/21
to TopBraid Suite Users
I'm afraid I spoke too soon. I added the sh:prefixes statement exactly as in your response, and I'm still getting an unresolved prefix error.

a owl:Ontology ;
owl:versionInfo "Created with TopBraid Composer" ;
sh:prefixes [sh:declare [
sh:namespace "http://www.w3.org/2002/07/owl#"^^xsd:anyURI ;
sh:prefix "owl" ;
] ;
] ;
.

Steve




On Mon, Mar 22, 2021 at 2:15 PM Irene Polikoff <ir...@topquadrant.com> wrote:

Holger Knublauch

unread,
Mar 22, 2021, 7:49:47 PM3/22/21
to topbrai...@googlegroups.com

In your first example, add

  sh:rule [
      a sh:SPARQLRule ;
      sh:prefixes <http://data.ashrae.org/standard223/1.0/inference/owl-subset> ;

because

<http://data.ashrae.org/standard223/1.0/inference/owl-subset>


    sh:declare [
      sh:namespace "http://www.w3.org/2002/07/owl#"^^xsd:anyURI ;
      sh:prefix "owl" ;
    ] .

is already a correct prefix declaration.

If you attempt something like in your second example:

      sh:prefixes <http://www.w3.org/2002/07/owl> ;

then the assumption is that the following triples are present

<http://www.w3.org/2002/07/owl>


    sh:declare [
      sh:namespace "http://www.w3.org/2002/07/owl#"^^xsd:anyURI ;
      sh:prefix "owl" ;
    ] .

which they are not.

There is clear evidence that too many people struggle with this aspect of the SHACL spec, and that as an editor I should have done a better job there. If I could simply re-upload the SHACL spec this would be the first thing to fix. However, the formal W3C process doesn't allow this easily.

I have to admit I never liked to even have the need to declare those namespaces as triples - this is a mixed blessing because nobody seems to understand the syntax yet namespace prefixes are a serialization concept only, not a graph concept. At some stage I may just give up on this and change our SHACL engine to simply add the declared prefixes from the files, like SPIN did for pragmatic reasons, ignoring the spec.

BTW both examples have a mismatch between the baseURI and the owl:Ontology. I suggest to keep them aligned.

HTH
Holger

Steve Ray

unread,
Mar 23, 2021, 12:36:14 PM3/23/21
to TopBraid Suite Users
I think the light bulb just went on.

Are you saying that the natural language interpretation of the sh:prefixes triple inside a SPARQLRule is:

"Go to the following graph URI to get the definitions for the prefixes you will need in the SPARQL query"...

...and in the ontology declaration, you use the sh:declare to do those definitions.  (without wrapping those sh:declare statements inside a sh:prefixes clause)?

(I will test this while waiting for the Australian day to begin. :)


Steve




Steve Ray

unread,
Mar 23, 2021, 12:46:28 PM3/23/21
to TopBraid Suite Users
Wonderful! It works!

Also, point taken on the mismatch between baseURI statement and owl:Ontology statement. I had thrown together the two examples and overlooked that bit of housekeeping.

For anybody else who is interested, I'm attaching the working example using prefixes (and fixing the above baseURI/owl:Ontology mismatch).

Steve




On Mon, Mar 22, 2021 at 4:49 PM Holger Knublauch <hol...@topquadrant.com> wrote:
epp2.shapes.ttl

Holger Knublauch

unread,
Mar 23, 2021, 6:32:21 PM3/23/21
to topbrai...@googlegroups.com


On 2021-03-24 2:36 am, Steve Ray wrote:
I think the light bulb just went on.

Are you saying that the natural language interpretation of the sh:prefixes triple inside a SPARQLRule is:

"Go to the following graph URI to get the definitions for the prefixes you will need in the SPARQL query"...

...and in the ontology declaration, you use the sh:declare to do those definitions.  (without wrapping those sh:declare statements inside a sh:prefixes clause)?

Yes exactly. The idea is that each graph declares its "main" prefix and then includes the other prefixes that it needs via owl:imports. Since the owl:imports are found at the graph URI resource, this was a natural place to attach this info to, without too much redundancy. Anyone who owl:imports your graph can then use its own owl:Ontology and will get the other prefix declarations automatically.

A problem is that this one example in the SHACL spec

    https://www.w3.org/TR/shacl/#sparql-constraints-example

doesn't include the triples behind ex: and most readers will not scroll down to

    https://www.w3.org/TR/shacl/#sparql-prefixes

for the full picture.

Holger


Steve Ray

unread,
Mar 23, 2021, 6:49:11 PM3/23/21
to TopBraid Suite Users
Also, the ambiguity in the example is that ex: represents both a prefix found in the SPARQL query and also represents the URI for the ontology in which the prefixes are defined. I had interpreted the example at    https://www.w3.org/TR/shacl/#sparql-constraints-example to mean "Identify all the prefixes you need in the query here" rather than "go to this URI to find all the prefix definitions".

Also, by the way, I have never succeeded in using the prefix as in your example at  https://www.w3.org/TR/shacl/#sparql-constraints-example .  In your example you say 
	sh:prefixes ex: ;
		sh:select """
I have only gotten it to work when I expand ex: to the full URI. I wondered whether it was because the ex: turns into http://example.com/ns# and when I spell it out I don't include the #, rather I write <http://example.com/ns>.

Steve




Holger Knublauch

unread,
Mar 23, 2021, 8:08:02 PM3/23/21
to topbrai...@googlegroups.com

On 2021-03-24 8:48 am, Steve Ray wrote:

Also, the ambiguity in the example is that ex: represents both a prefix found in the SPARQL query and also represents the URI for the ontology in which the prefixes are defined. I had interpreted the example at    https://www.w3.org/TR/shacl/#sparql-constraints-example to mean "Identify all the prefixes you need in the query here" rather than "go to this URI to find all the prefix definitions".

Also, by the way, I have never succeeded in using the prefix as in your example at  https://www.w3.org/TR/shacl/#sparql-constraints-example .  In your example you say 
	sh:prefixes ex: ;
		sh:select """
I have only gotten it to work when I expand ex: to the full URI. I wondered whether it was because the ex: turns into http://example.com/ns# and when I spell it out I don't include the #, rather I write <http://example.com/ns>.

Yes this is easy to get wrong. URLs ending with # are often used without the # for the base URI/owl:Ontology. This problem doesn't exist for namespaces ending with /

So regardless of the namespace, you typically want to reference the *base URI* (aka named graph) which is where the owl:Ontology is. In the SHACL spec's example that base URI and namespace are identical and both end with the #. However, if you had

<http://example.com/ns>
    a owl:Ontology ;
    sh:declare ...

then you would use sh:prefixes <http://example.com/ns> without the hash. For the examples and the SHACL namespace itself we chose to use a # URL both for the namespace and the graph URI.

(These are very recurring questions not only from you, which indicates that there is a deeper design problem with this aspect of the RDF world).

Holger


Reply all
Reply to author
Forward
0 new messages