Proper use of sh:prefixes

195 views
Skip to first unread message

Jan Voskuil

unread,
Jun 1, 2021, 4:39:22 AM6/1/21
to topbrai...@googlegroups.com

Hi,

While trying to familiarize myself with sh:values in EDG, I fail to get the results I think I expect using sh:prefixes. I’ve read the spec and Holger’s mail dd March 22 2021 on this topic in  this forum.

In TopBraid Examples Geo Ontology, I added a values property shape to g:GeoConcept that counts the number of narrowers, see [1]. It works as expected.

But I had to use sh:prefixes as in [2], with the urn-URI. When using the “external graph URI” as the graphURI as in [3], the prefix declaration is not found, even though I did set this parameter on the settings tab, as seen under [4].

 

The external graphURI is to be used as value of owl:imports*, so I would expect [3] to work, or is this by design? -j

 

[1]

 

[2]

g:GeoConcept-numberOfNarrowers

  a sh:PropertyShape ;

  sh:path g:numberOfNarrowers ;

  sh:datatype xsd:integer ;

 sh:maxCount 1 ;

  sh:name "number of narrowers" ;

  sh:values [

      sh:prefixes <urn:x-evn-master:geography_ontology> ;

      sh:select """

      SELECT COUNT(?n)

      WHERE {

        ?n skos:broader ?this .

      }

      """ ;

    ] ;

.

 

[3]

      sh:prefixes <http://topquadrant.com/ns/examples/geography#> ;

or

      sh:prefixes g: ;

 

[4]

<urn:x-evn-master:geography_ontology>

  a owl:Ontology ;

  metadata:status metadata:UnderDevelopmentStatus ;

  swa:defaultNamespace http://topquadrant.com/ns/examples/geography# ;

  teamwork:externalGraphURI g: ;

  rdfs:comment "Schema definition for Geography Taxonomy." ;

  rdfs:label "TopBraid Examples Geo Ontology" ;

  owl:imports http://datashapes.org/dash ;

  owl:imports http://datashapes.org/graphql ;

  owl:imports http://spinrdf.org/spl ;

  owl:imports http://topbraid.org/skos-xl.shapes ;

  owl:imports http://topbraid.org/skos.shapes ;

  owl:imports http://topbraid.org/tbgeo ;

  owl:imports http://topbraid.org/teamworkconstraints ;

  sh:declare [

      sh:namespace http://topquadrant.com/ns/examples/geography#^^xsd:anyURI ;

      sh:prefix "g" ;

    ] ;

  sh:declare [

      sh:namespace http://www.w3.org/2004/02/skos/core#^^xsd:anyURI ;

     sh:prefix "skos" ;

    ] ;

  sh:declare [

      sh:namespace http://www.wikidata.org/prop/direct/^^xsd:anyURI ;

      sh:prefix "wdt" ;

    ] ;

.

 

Jan Voskuil | CEO Taxonic

Veldzigt 2, 3454 PW, De Meern, The Netherlands

T +31 (0)88 829 66 00 | M:+31 (0)6 14488335

jan.v...@taxonic.com | www.taxonic.com

Registered office in Den Haag, The Netherlands

Registration Number Chamber of Commerce: 54529190

 

Irene Polikoff

unread,
Jun 1, 2021, 12:20:38 PM6/1/21
to topbrai...@googlegroups.com


On Jun 1, 2021, at 4:39 AM, Jan Voskuil <jan.v...@taxonic.com> wrote:

Hi, 
While trying to familiarize myself with sh:values in EDG, I fail to get the results I think I expect using sh:prefixes. I’ve read the spec and Holger’s mail dd March 22 2021 on this topic in  this forum.
In TopBraid Examples Geo Ontology, I added a values property shape to g:GeoConcept that counts the number of narrowers, see [1]. It works as expected.
But I had to use sh:prefixes as in [2], with the urn-URI. When using the “external graph URI” as the graphURI as in [3], the prefix declaration is not found, even though I did set this parameter on the settings tab, as seen under [4].
 
The external graphURI is to be used as value of owl:imports*, so I would expect [3] to work, or is this by design? -j


Right, the external graph URI only works for import/export and re-directs of owl:imports, not in SPARQL. You do need to refer to the actual URI that has prefix declarations.

Btw, Your declarations in (4) seem to be missing quotes around the namespaces. They should be

sh:declare [
      sh:namespace "http://topquadrant.com/ns/examples/geography#"^^xsd:anyURI ;
      sh:prefix "g" ;
    ] ;


You probably already know this, but just in case - if you decide to declare a prefix in the query, use:

sh:values [
      sh:prefixes [
          sh:declare [
              sh:namespace "http://www.w3.org/2004/02/skos/core#"^^xsd:anyURI ;
              sh:prefix "skos" ;
            ] ;
        ] ;
      sh:select """
      SELECT COUNT(?n)
      WHERE {
        ?n skos:broader ?this .
      }
      """ ;
    ] ;

Also, there is no need to use SPARQL for this particular example. You could do the following:

skos:Concept-countOfChildren
  a sh:PropertyShape ;
  sh:path g:countOfChildren ;
  sh:datatype xsd:integer ;
  sh:name "count of children" ;
  sh:values [
      sh:count [
          sh:path [
              sh:inversePath skos:broader ;
            ] ;
        ] ;
    ] ;
.
 
[1]
<image002.png>

-- 
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/AM0PR03MB37457F535B94C01BE60F12B9E93E9%40AM0PR03MB3745.eurprd03.prod.outlook.com.

Holger Knublauch

unread,
Jun 1, 2021, 9:43:55 PM6/1/21
to topbrai...@googlegroups.com

Yes, and the underlying issue is that sh:prefixes will follow the owl:imports closure but while editing in EDG those owl:imports will be attached to the Home resource urn:x-evn-master:XY which is different from the external namespace resource. You could theoretically declare your prefixes at the external graph URI

ex:MyGraph
    a owl:Ontology ;
    owl:imports <http://datashapes.org/dash> ;
    sh:declare [ ... ]
.

and then do sh:prefixes ex:MyGraph in your SPARQL query.

In either case, this is a common pain point for SHACL users that unfortunately was required because RDF graphs do not have a concept of prefixes (which are an aspect of the serialization only), yet SHACL is serialization-agnostic.

Holger

Jan Voskuil

unread,
Jun 4, 2021, 7:29:09 AM6/4/21
to topbrai...@googlegroups.com

Thanks Irene, very useful, -j

Reply all
Reply to author
Forward
0 new messages