Hi Gary,

I have attached a (slightly) corrected version. Use sh:sparql instead of sh:propertyValidator. And for the prefixes I have just pointed at the dash namespace, which defines the correct things for the common namespaces such as xsd - I couldn't see if your declarations were correct as the example is a snippet only. Also I have used ?value as return variable in the SELECT because then it will be picked up by the validation report.

This may help https://www.topquadrant.com/technology/shacl/tutorial-sparql-constraints/ and of course the spec https://www.w3.org/TR/shacl/#sparql-constraints-example

HTH
Holger

On 29/07/2020 06:54, Gary Murphy wrote:
I am hoping to master the fine art of sh:sparql and sh:ask validators, and I have a situation where the source data can have geocoordinates as strings, eg "99.91°N"  - the following sparql code correctly detects values out of range:

SELECT *
WHERE {
  BIND("99.91°N" as ?value)
  BIND(abs(xsd:float(replace(str(?value),"[a-zA-Z°]",""))) as ?lat)
  FILTER( ?lat > "90.0"^^xsd:float )
}

So with a source graph schema:Geocoordinate

ex:BobPoint
  a schema:GeoCoordinates ;
  schema:latitude "-144.75N" ;
  schema:longitude "172" ;
.

I am expecting to detect that bad latitude with the following bit of shacl using sh:sparql to clean the ?value and cast it to float for comparison, just as with the above sparql code.  But it doesn't work ...

hmshape:GeoCoordinates-latitude-limits
  a sh:PropertyShape ;
  sh:path schema:latitude ;
  sh:propertyValidator [
        a sh:SPARQLSelectValidator ;
      sh:prefixes schema: ;
      sh:prefixes xsd: ;
      sh:select """
SELECT $this ?lat
WHERE {
  $this $PATH ?value .
  BIND(abs(xsd:float(replace(str(?value),\"[a-zA-Z° ]\",\"\"))) AS ?lat)
  FILTER( xsd:float(?lat) > xsd:float(90.0) )
}""" ;
    ] ;
.
hmshape:GeoCoordinatesShape
  a sh:NodeShape ;
  sh:property hmshape:GeoCoordinates-latitude-limits ;
  sh:targetClass schema:GeoCoordinates ;
.

Unfortunately, this rule always approves whatever value I give it, no warnings or errors.  I've tried variations, casting to xsd:float or not, using sh:validator with sh:ask, but it still accepts any value.  Just to be sure, I added sh:minCount 2 to assure myself the rule was being reached, and it is.

What am I missing?

Also, is this the correct use of sh:prefixes?  these are defined in the hmshape owl:Ontology with sh:declare bnodes
--
Gary Lawrence Murphy <g...@schemaapp.com <mailto:g...@schemaapp.com>> - Hunch Manifest, 15 Wyndham N 'C', Guelph
--
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-users+unsubscr...@googlegroups.com <mailto:topbraid-users+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/CADnyxpu7Fsf%3DN0vc%2BmWG2%2BnkiMD%3DHH5-uXwditHvF5zABGqYrA%40mail.gmail.com <https://groups.google.com/d/msgid/topbraid-users/CADnyxpu7Fsf%3DN0vc%2BmWG2%2BnkiMD%3DHH5-uXwditHvF5zABGqYrA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

--
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/topbraid-users/b2c75635-b510-59d3-f2af-4dfcb3ae9860%40topquadrant.com.
# baseURI: http://example.org/sparqlConstraint
# imports: http://datashapes.org/dash
# imports: http://datashapes.org/schema
# prefix: ex

@prefix dash: <http://datashapes.org/dash#> .
@prefix ex: <http://example.org/sparqlConstraint#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://example.org/sparqlConstraint>
  a owl:Ontology ;
  owl:imports <http://datashapes.org/dash> ;
  owl:imports <http://datashapes.org/schema> ;
  owl:versionInfo "Created with TopBraid Composer" ;
.
ex:BobPoint
  a schema:GeoCoordinates ;
  schema:latitude "-144.75N" ;
  schema:longitude "172" ;
.
ex:GeoCoordinates-latitude-limits
  a sh:PropertyShape ;
  sh:path schema:latitude ;
  sh:sparql [
      sh:message "Absolute latitude cannot be > 90" ;
      sh:prefixes <http://datashapes.org/dash> ;
      sh:select """SELECT $this ?value
WHERE {
  $this $PATH ?value .
  BIND(abs(xsd:float(replace(str(?value),\"[a-zA-Z° ]\",\"\"))) AS ?lat)
  FILTER( xsd:float(?lat) > xsd:float(90.0) )
}""" ;
    ] ;
.
schema:GeoCoordinates
  sh:property ex:GeoCoordinates-latitude-limits ;
.

Reply via email to