Giter Site home page Giter Site logo

Comments (7)

ashleysommer avatar ashleysommer commented on June 1, 2024

Hi @mgberg
This looks like a similar or duplicate problem to the one reported here: #29
And since that bug was fixed, this example should work in all versions of PySHACL from v0.11.1 onwards.

Can you tell me please, what version of PySHACL are you using?

from pyshacl.

ashleysommer avatar ashleysommer commented on June 1, 2024

@mgberg
I've run your example with pyshacl v0.11.3 (and latest v0.11.3.post1) and it works as expected with output:

Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):
	Severity: sh:Violation
	Source Shape: ex:NameConstraint
	Focus Node: ex:Bob
	Result Path: ex:name

If you're using a version of PySHACL older than v0.11.1, please upgrade to v0.11.1 or newer (preferrably always use the latest version).

If there is a good reason you're deliberately using an older version, let me know and I might be able to backport the owl:Class fix to it via a maintenance release.

from pyshacl.

mgberg avatar mgberg commented on June 1, 2024

My computer thought v0.10 was the most up-to-date version. I upgraded and it works. Thanks!

from pyshacl.

mgberg avatar mgberg commented on June 1, 2024

Hello again. If I run the following code:

shapes = rdf.Graph()
shapes.parse(data="""@prefix owl:  <http://www.w3.org/2002/07/owl#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh:  <http://www.w3.org/ns/shacl#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/ns#> .


ex:Person
        rdfs:label       "Person" ;
        rdf:type         owl:Class ;
        rdf:type         sh:NodeShape ;
        rdfs:subClassOf  owl:Thing ;
        sh:property      ex:Person-favoriteFood .

ex:Child
        rdfs:label       "Child" ;
        rdf:type         owl:Class ;
        rdf:type         sh:NodeShape ;
        rdfs:subClassOf  ex:Person .
        
ex:Person-favoriteFood
        rdf:type  sh:PropertyShape ;
        sh:path   ex:favoriteFood ;
        sh:class  ex:Food ;
        sh:name   "Favorite Food" .
""",format="ttl")

data = rdf.Graph()
data.parse(data="""@prefix owl:  <http://www.w3.org/2002/07/owl#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh:  <http://www.w3.org/ns/shacl#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/ns#> .
       
ex:Sally
        rdfs:label  "Sally" ;
        rdf:type    ex:Child ;
        ex:favoriteFood  ex:Sally .
""",format="ttl")

r = sh.validate(data_graph=data, shacl_graph=shapes, inference="both")
print(r[2])

no validation errors are reported. PySHACL is not inferring that the property shape applied to ex:Person should also be applied to ex:Child. If this is loaded in a TopQuadrant product, the error is reported correctly.

I have upgraded PySHACL to version 0.11.4.

Thanks!

from pyshacl.

ashleysommer avatar ashleysommer commented on June 1, 2024

Hi @mgberg

You're not seeing those RDFS subclasses being applied to the data because the class relationships are declared in the SHACL Shapes file.

When you enable inferencing, the process applies only to the data graph. The class relationships declared in the SHACL file don't affect it.

This is why the "extra ontology graph" feature exists in pySHACL. You can give a third graph to the validator, this other graph can contain your extra ontological class relationships. It is mixed in with the data graph before inferencing occurs, so the RDFS inferencer has all of the required class information needed to expand the data graph.

One easy fix for your code for now is to simply feed your SHACL Shapes graph to the ont_graph argument, like this:

r = sh.validate(data_graph=data, shacl_graph=shapes, ont_graph=shapes, inference="both")
print(r[2])

from pyshacl.

mgberg avatar mgberg commented on June 1, 2024

I see, that does work. Thanks!

from pyshacl.

ashleysommer avatar ashleysommer commented on June 1, 2024

@mgberg
Thanks for letting me know.

Heres an example of splitting them out into a separate graph:

shapes = rdf.Graph()
shapes.parse(data="""@prefix owl:  <http://www.w3.org/2002/07/owl#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh:  <http://www.w3.org/ns/shacl#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/ns#> .


ex:Person
        rdfs:label       "Person" ;
        rdf:type         owl:Class ;
        rdf:type         sh:NodeShape ;
        rdfs:subClassOf  owl:Thing ;
        sh:property      ex:Person-favoriteFood .

ex:Child
        rdfs:label       "Child" ;
        rdf:type         owl:Class ;
        rdf:type         sh:NodeShape ;
        rdfs:subClassOf  ex:Person .
        
ex:Person-favoriteFood
        rdf:type  sh:PropertyShape ;
        sh:path   ex:favoriteFood ;
        sh:class  ex:Food ;
        sh:name   "Favorite Food" .
""",format="ttl")


extra = rdf.Graph()
extra.parse(data="""@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 ex: <http://example.org/ns#> .

ex:Person
        rdfs:label       "Person" ;
        rdf:type         owl:Class ;
        rdfs:subClassOf  owl:Thing .

ex:Child
        rdfs:label       "Child" ;
        rdf:type         owl:Class ;
        rdfs:subClassOf  ex:Person .
        
""",format="ttl")

data = rdf.Graph()
data.parse(data="""@prefix owl:  <http://www.w3.org/2002/07/owl#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix sh:  <http://www.w3.org/ns/shacl#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/ns#> .
       
ex:Sally
        rdfs:label  "Sally" ;
        rdf:type    ex:Child ;
        ex:favoriteFood  ex:Sally .
""",format="ttl")

r = sh.validate(data_graph=data, shacl_graph=shapes, ont_graph=extra, inference="both")
print(r[2])

from pyshacl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.