Hello,


Thank you for your previous email.



I am trying to use SHACL-SPARQL to validate some data and it does not seem to 
work as intended. I am trying to validate an example (shape and data) found in 
the book "Validating RDF data".





The shape is as follows:



:UserShape a sh:NodeShape ;

sh:targetClass :User ; //all instances of class user must conform to the 
following SPARQL constraint

sh:sparql [

a sh:SPARQLConstraint ;

sh:message "schema:name must equal schema:givenName + schema:familyName"; 
//this is what I would like the constraint to do

sh:prefixes [

sh:declare [

sh:prefix "schema" ;

sh:namespace "http://schema.org/"^^xsd:anyURI ;

]

] ;

sh:select"""

SELECT $this (schema:name AS ?path) (?name as ?value)

WHERE {

$this schema:name ?name .

$this schema:givenName ?givenName .

$this schema:familyName ?familyName .

FILTER (!isLiteral (?value) ||

    !isLiteral (?givenName) ||

    !isLiteral (?familyName) ||

    concat( str(?givenName), ' ',  str(?familyName)) !=?name

)

}""" ;

] .





The data graph is as follows:



:Alice a :User ;

schema:givenName "Alice" ;

schema:familyName "Cooper" ;

schema:name "Alice Cooper" .



:Bob a :User ;

schema:givenName "Bob" ;

schema:familyName "Smith" ;

schema:name "Robert Smith" .





The Jena code is as follows:



public class ValidationTest {



            public static void main(String[] args) {



                        String SHAPE = "C:\\Users\\Test.txt" ;

                        String DATA = "C:\\Users\\TestData.txt" ;



                        Graph shapesGraph = RDFDataMgr.loadGraph(SHAPE, 
Lang.TURTLE) ;

                        Graph dataGraph = RDFDataMgr.loadGraph(DATA, 
Lang.TURTLE) ;



                        Shapes shapes = Shapes.parse(shapesGraph) ;



                        ShaclValidator validator = ShaclValidator.get()  ;

                        ValidationReport report = 
validator.validate(shapesGraph, dataGraph) ;



                        System.out.println() ;

                        RDFDataMgr.write(System.out, report.getModel(), 
Lang.TTL) ;

                        }

}



The validation result is as follows:





[ a            sh:ValidationReport ;

  sh:conforms  true

] .



As you can see, one node should conform and one node should not, but this is 
not what I am getting as a validation result. Please advise.



Thank you very much

Yasir

Reply via email to