Skip to content

SPARQL FILTER() works as inverse to other validators #289

@hentoilusose

Description

@hentoilusose

Greetings. I'm comparing pySHACL to other validators such as the European Commissions ISAITB. There seems to be divergent behaviour between them in how to interpret FILTER(). An MWE below:

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix meta: <https://iri.foo.bar/schema/meta/> .
@prefix domain: <https://iri.foo.bar/ontology/domain/> .

meta:SPARQLRule a sh:SPARQLConstraint;
	sh:prefixes [
		sh:declare [
			sh:prefix "domain";
			sh:namespace "https://iri.foo.bar/ontology/domain/"^^xsd:anyURI ;
		]
	];
	sh:select """
		SELECT $this ?declaredLocalIdentifier ?foundLocalIdentifier
		WHERE {
			$this domain:hasLocalIdentifier ?declaredLocalIdentifier .
			BIND(REPLACE(STR($this), '^(.+/|.+#)', '', '') AS ?foundLocalIdentifier)
			FILTER(?declaredLocalIdentifier != ?foundLocalIdentifier)
		}""" ;
	sh:severity sh:Violation;
	sh:message "Found identifier was: {?foundLocalIdentifier}, declared identifier was: {?declaredLocalIdentifier}.".

meta:SPARQLShape a sh:NodeShape;
	domain:hasLocalIdentifier "SPARQLShape"^^xsd:NCName;
	sh:targetClass sh:NodeShape;
	sh:sparql meta:SPARQLRule;
	sh:severity sh:Violation.

When validating this shapes graph with itself, ISAITB sees no violation as all local identifiers stripped from the URI are identical to the declared ones, whereas pySHACL does. If I flip the equality assertion to =, pySHACL sees no Violation while ISAITB does.

To my understanding each individual result should be included in the result set if FILTER() evaluation is true - which it in this case it isn't (as the literal NCName and the identifier extracted from URI are identical). In the least there is discrepancy between validators but my current understanding is that pySHACL should evaluate FILTER() in inverse. Am I mistaken?

Here are the validation message first from pySHACL 0.30.0:

[] a sh:ValidationReport ;
    sh:conforms false ;
    sh:result [ a sh:ValidationResult ;
            sh:focusNode meta:SPARQLShape ;
            sh:resultMessage "Found identifier was: SPARQLShape, declared identifier was: SPARQLShape." ;
            sh:resultSeverity sh:Violation ;
            sh:sourceConstraint meta:SPARQLRule ;
            sh:sourceConstraintComponent sh:SPARQLConstraintComponent ;
            sh:sourceShape meta:SPARQLShape ;
            sh:value meta:SPARQLShape ] .

And from ISAITB validator 1.7.0:

[ rdf:type     sh:ValidationReport;
  sh:conforms  true
] .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions