Code Monkey home page Code Monkey logo

Comments (8)

ashleysommer avatar ashleysommer commented on June 12, 2024

Hi @xyzisinus,
Thanks for your detailed write-up of this report.

I haven't yet had a chance to look deeply into what is causing the problem you are seeing, but my immediate concern is it might be related to some changes introduced in the most-recent v0.11.3 release of pyshacl.

Have you tried any other versions other than the latest release, to try to reproduce your problem?

Please try v0.11.1 to see if the problem is present, and if so, please try v0.10.0 and see if it is still present there.

I will look more deeply into exactly what is causing this problem later this weekend.

from pyshacl.

ashleysommer avatar ashleysommer commented on June 12, 2024

Update, reading it again, I think I see a problem in your shape definition. You are using both sh:targetObjectOf and sh:property together in the same shape, to try to enforce the same rule in two different ways. That is saying "everything that is an object of this property, should also have this property at this property path" which is incorrect for what you are trying to achieve.

You can do this rule with sh:targetObjectOf or sh:property but not both.

Try this:

schema:AddressShape
    a sh:NodeShape ;
    sh:targetObjectsOf schema:hasAddress ;
    sh:class schema:PostalAddress .

from pyshacl.

ashleysommer avatar ashleysommer commented on June 12, 2024

Update 2:
I was just thinking, you might be confusing targetObjectsOf and targetSubjectsOf
For example, changing your Shape to this, will work:

schema:AddressShape
    a sh:NodeShape ;
    sh:targetSubjectsOf schema:hasAddress ;
    sh:property [
        sh:path schema:hasAddress ;
        sh:class schema:PostalAddress ;
    ] .

That will do what you want, is it saying "get all targets that are subjects which have this hasAddress" and "on those targets, follow this property path to check its class".

However using targetObjectsOf like this:

schema:AddressShape
    a sh:NodeShape ;
    sh:targetObjectsOf schema:hasAddress ;
    sh:class schema:PostalAddress .

this is easier, and shorter and identical to the above. It says "find all targets which are the object of hasAddress, and check its class."

from pyshacl.

xyzisinus avatar xyzisinus commented on June 12, 2024

@ashleysommer Thank you very much for your quick response! I tried both suggestions in your update 2. The result of the first suggestion:

Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: [ sh:class schema:PostalAddress ; sh:path schema:hasAddress ]
        Focus Node: ex:Bob
        Value Node: ex:Alice
        Result Path: schema:hasAddress

The result of the second suggestion (2 errors reported):

Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
        Severity: sh:Violation
        Source Shape: schema:AddressShape
        Focus Node: ex:Alice
        Value Node: ex:Alice
Constraint Violation in NodeConstraintComponent (http://www.w3.org/ns/shacl#NodeConstraintComponent):
        Severity: sh:Violation
        Source Shape: [ sh:node schema:AddressShape ; sh:path schema:address ]
        Focus Node: ex:Bob
        Value Node: ex:BobsAddress
        Result Path: schema:address

Out of these two alternatives, the first one makes more sense to me because "hasAddress" path is used in reasoning.

from pyshacl.

xyzisinus avatar xyzisinus commented on June 12, 2024

And I'm still bit confused looking at the code in https://github.com/RDFLib/pySHACL/blob/master/pyshacl/shapes_graph.py starting from line 187, especially line 189 where targetObjectsOf is concerned. In this chunk of code (till the end of the file) I don't see how targetObjectsOf gets to participate in finding the focus nodes which are objects of some shape. I haven't looked/poked the code carefully yet. My observation is just from a quick scan of the code. Thanks!

from pyshacl.

ashleysommer avatar ashleysommer commented on June 12, 2024

Hi, the chunk of code in that file you're looking at is the "shapes detection routine" its job is to find all possible permutations of SHACL shapes in a shapes file, in order to later iterate over them. The code which builds focus nodes for a given shape is in a different file in the project.

See how sh:targetObjectsOf is used here:

return self.sg.graph.objects(self.node, SH_targetObjectsOf)

Then look on line 175, 210, and 239. I know the code is hard to follow, but I hope that helps you to understand how sh:targetObjectsOf is done in PyShacl.

from pyshacl.

xyzisinus avatar xyzisinus commented on June 12, 2024

@ashleysommer Thank you for the pointer! I'll look at the code when I get a chance :)

from pyshacl.

xyzisinus avatar xyzisinus commented on June 12, 2024

@ashleysommer I'm closing the issue now. Thank you for your support and insight!

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.