Code Monkey home page Code Monkey logo

Comments (5)

ashleysommer avatar ashleysommer commented on June 12, 2024 1

@ajhewett Thanks for taking the time to raise this issue.

The problem you are describing is one of pre-inferencing.
A couple of questions:

  1. How are you invoking pySHACL, via the command line or using the library in a larger project?
  2. Are you specifiying and pre-inferencing options, like "rdfs", "owlrl', or "both"?

The ParentShape constraint is not applied to the instance of Child, because the target graph does not know that Child inherits the rules of Parent, even though the RDFS subClassOf predicate is used in the Shape file.

In order for the ParentShape rule to apply to Child, there must exist a triple (in Data Graph) of (child_instance_id, rdf:type, ex:Parent). This is normally injected into the Data Graph by running the RDFS influencing step before validation.

In this case however, this would not work, because the RDFS Classes are declared in the SHACL Shapes File. RDFS pre-inferencing step is only applied to the Data Graph (the target graph), no RDFS declarations from the SHACL Shapes file are pulled into the Data Graph during the pre-inferencing step.

You would need to put this triple into the target graph:

(ex:Child, rdfs:subClassOf. ex:Parent)

Then run ensure you run the RDFS pre-inferencing step before validating, in order to get the result you are expecting.

Note, this same behaviour exists on the official SHACL Playground webapp here:
http://shacl.org/playground/
It uses an entirely different SHACL implementation, and gives the same result you are seeing here.

from pyshacl.

ashleysommer avatar ashleysommer commented on June 12, 2024 1

@ajhewett
The latest release of pySHACL (v0.9.9) has a new feature that will potentially solve the problem we were seeing above.

There is a new option to pass into the validator another external file containing extra ontological information, that is needed by the data graph in order for inferencing to proceed correctly.

In the example above, we would have an ontology.ttl file with

@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.com/ex#> .

ex:Parent a rdfs:Class ;
    rdfs:isDefinedBy ex: ;
    rdfs:comment "The parent class"@en ;
    rdfs:subClassOf owl:Thing .

ex:Child a rdfs:Class ;
    rdfs:isDefinedBy ex: ;
    rdfs:comment "The child class"@en ;
    rdfs:subClassOf ex:Parent .

Then pass that file into the validator with ont_graph="ontology.ttl" along with the shacl file and the target data file. Now the data file does not need to be modified before running the validator on it, and it can be simply a bare data snippet that is an instance of those classes defined in the ontology.

from pyshacl.

ajhewett avatar ajhewett commented on June 12, 2024

@ashleysommer many thanks for your prompt response. Very helpful and informative. 👍

To answer your questions:

  1. I am using the python library within a larger project.
  2. I specify the "rdfs" inferencing option and also tried the others.

My pyshacl library call looks like:

r = pyshacl.validate(target_graph=dataGraph.default_context, shacl_graph=shaclGraph, inference='rdfs', abort_on_error=False, meta_shacl=True, debug=False)

I did not realize that inferencing is only applied to the target graph with the implication that RDFS Classes declared in the SHACL Shapes graph are not automatically used.

Your suggestion to add a (ex:Child, rdfs:subClassOf. ex:Parent) triple to the target graph does indeed give the expected result. However, my use-case is validating json-ld data returned in a http response so I would prefer to avoid modifying the response if possible.

After some further experimentation I have been able to achieve a similar effect by enhancing the ParentShape to also target the Child class in addition to the Parent class. This is easier since I control the SHACL Shapes file.

I will close this issue since it is clearly not a pyshacl problem.

from pyshacl.

ashleysommer avatar ashleysommer commented on June 12, 2024

@ajhewett
I've been thinking about your use-case, and it does absolutely make sense for some applications of SHACL to have the RDFS Class relationships defined in the same file as the SHACL Shapes, and for the Data File to be bare instances of those classes.

I will think about how we could make that work, potentially by copying any rdfs:Class declarations from the SHACL graph into the Data graph before inferencing.
What I do know is that we can't run RDFS inferencing over the SHACL Shapes graph itself because a lot of the extra triples the inferencing engine adds to the SHACL Shapes and rules break the expected behaviour of those rules.

This new feature would need to be enabled via a flag, because it is probably not something users would expect to happen by default.

from pyshacl.

ajhewett avatar ajhewett commented on June 12, 2024

@ashleysommer Thanks, I will take a look.

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.