-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional SHACL support to Ontospy/gendocs #107
Additional SHACL support to Ontospy/gendocs #107
Conversation
This patch is the first in a series to bring Ontospy's current state of SHACL support up to the level where the Shapes pages are built. Serialization will be handled in a later patch. ontospy/core/shacl_helper.py: * Returns dictionary of SHACL property constraints, given an Ontospy object ontospy/core/ontospy.py: * Imports shacl_helper to build SHACL property constraints * Amends call to build SHACL property constraints at end of build_shapes method - Modifies logic to allow all_shapes to be built Co-authored-by: Dr. Stanley A Bernsteen <[email protected]> Signed-off-by: TJ Balon <[email protected]>
This patch modifies the browser_shapeinfo.html file to adjust the formatting and provide documentation. The patch has no functional changes. Modifications: * Addition of comments to note logic for panels * Reformat HTML to conventional tag indentation * Remove excess whitespace Co-authored-by: Dr. Stanley A Bernsteen <[email protected]> Signed-off-by: TJ Balon <[email protected]>
This modifies the browser_shapeinfo.html file to display the SHACL shape properties based on the OntoShape object that is rendered on the HTML page. Co-authored-by: Dr. Stanley A Bernsteen <[email protected]> Signed-off-by: TJ Balon <[email protected]>
This patch adds functionality to the HTML rendering portion of the ontodocs, and includes an additional namespace for rdflib. ontospy/ontodocs/viz/viz_html_multi.py: * Adds function to identify OWL Classes which define themselves as SHACL Node Shapes - shape and class URIs must match - must be of RDF.type: SH.NodeShape - must be of RDF.type: OWL.Class ontospy/core/utils.py: * Imports SH namespace for rdflib Co-authored-by: Alex Nelson <[email protected]> Signed-off-by: TJ Balon <[email protected]>
This patch replaces the tree-diagram in the browser_shapeinfo.html file if the shape is a SHACL NodeShape and OWL Class (with matching URIs). ontospy/ontodocs/viz_factory.py: * Imports Library for django.template * Adds filter to call ontospy.core.utils.slugify() from a django template ontospy/ontodocs/viz/viz_html_multi.py: * Checks shapes to see if they are defined as OWL.Class & SH.NodeShape - Updates parents/children of the entity to the matching class's parents/children for the tree-diagram during template rendering ontospy/../browser/browser_shapeinfo.html: * Replaces hyperlinks in tree-diagram to generalize if a shape/class diagram is build built - links are prefixed with "shape-" - slugs are replaced with qname and a call to the slugify filter Signed-off-by: TJ Balon <[email protected]>
This patch modifies the browser_classinfo.html file to adjust the formatting and provide documentation. The patch has no functional changes. Modifications: * Addition of comments to note logic for panels * Reformat HTML to conventional tag indentation * Remove excess whitespace Co-authored-by: Dr. Stanley A Bernsteen <[email protected]> Signed-off-by: TJ Balon <[email protected]>
This patch modifies the browser_classinfo.html file to display a panel for classes which have associated SHACL property shapes. If an ontology does not implement SHACL, there are no functional changes. Co-authored-by: Dr. Stanley A Bernsteen <[email protected]> Signed-off-by: TJ Balon <[email protected]>
Thanks. I'll be able to review it over the next few days. |
This patch addresses a use case where an ontology defines no or few rdfs:domain statements for its properties, instead relating properties to classes via SHACL shapes. If a property is associated to classes via SHACL property shapes within an ontology, it does not seem appropriate to treat the property as universally applicable. Co-authored-by: Alex Nelson <[email protected]> Signed-off-by: TJ Balon <[email protected]>
Attached is uco_monolithic.ttl, which can be used for testing the features in this patch series. The file could also be constructed by running the makefile found in the ucoProject/UCO repository. Thanks! |
This patch should have no functional impact, except possibly some speedup from a braces encapsulation. Signed-off-by: Alex Nelson <[email protected]>
Review of the SHACL specification showed the sh:targetClass is not explicitly required under certain conditions, cited in getPropsApplicableByShapes. Signed-off-by: Alex Nelson <[email protected]>
The SHACL specification, section 2.1.3.3 "Implicit Class Targets", indicates a reflexive sh:targetClass triple is implied for a SHACL Class that is also a Shape. The function updated in this patch reviewed NodeShapes for being classes based on an explicit sh:targetClass statement. This patch changes the check to rely on that triple being implied under the SHACL specification conditions. Additionally, the "Class" definition is adjusted to being a SHACL Class, which covers RDFS Classes in addition to the prior implementation of only OWL classes. References: * https://www.w3.org/TR/shacl/#implicit-targetClass Signed-off-by: Alex Nelson <[email protected]>
This PR has received an in-flight update, for the same reason noted over on PR 108. |
First of all, thanks! This looks like a terrific addition to Ontospy. I just released a minor new version v 1.9.9.4 that should simplify merging this functionality (it's in master), so would you please update your changes accordingly? Here's a few comments to get started.
Hope this makes sense.. PS Just FYI I was planning to clean up the whole codebase (admittedly a bit dated and messy!) and release a V2 of Ontospy in the near future, with better docs etc.... I'll hold off doing that until we complete this PR! |
Hi I added a feature request in #104 and I think your PR does what I strive for :-) I did the following:
What I get as HTML looks correct in terms of property shapes on the class page. This is really nice! However, I tried this with my own ontology which consists of
As observed in #107 (comment) I don't see the Shapes page anymore. Could this be because classes and node shapes do not use the same IRI? For some more details about the ontology I use, please see #104 Thanks a lot! |
Thank you both for the feedback! We'll be getting back to you next week. |
Thank you for the feedback. We had a discussion today about a timeline to updating the PR as requested. We're both currently tied up on a few tasks, but plan to address this early next week with plans to have something ready to push by next Friday. We will also look at the issues presented involving the missing shapes page on some ontologies. |
Sounds good, thanks. If there are any updates at my end, I'll let you know. |
We're working through the remarks now. We've made a catch-up merge to integrate @lambdamusic , re:
Could you explain what behavior you're seeing here? After our catch-up merge, we regenerated the page, and saw these effects:
I suspect we've actually resolved your second issue, but that's mainly from our failure to reproduce what you saw. |
On further review, |
On the shapes page, we intend to list a table of how properties associate with a class. There's a conceptual hop there, which is probably something we need to talk through to come to a good design consensus. The user interface complexity we're trying to hide is going to apply to SHACL-based schemes that don't define So, we tried to apply some redundancy - having the properties associated via SHACL be listed on the class page as well. This saves the user two clicks (oscillating between shapes and class pages) per level of the class hierarchy they want to review. We probably wouldn't go for this redundancy if SHACL had a concept of "SubNodeShape," but they don't. That's the feedback we could get to today, we're happy to discuss this further. |
Hi folks - first of all, wish I had time to get back to you sooner, sorry about that and thanks a lot for the patience. 1) Shapes HTML page for scigraph is ok@ajnelson-nist as you pointed out, the scigraph ontology 'shapes' page is not missing anymore. Don't know what's changed, I do recall noticing the difference, but of course I might be wrong. So all's good there. Backward compatibility is fine. 2) New ontospy tests errorI do get an error when running the test suite ( ...
File "/Users/michele.pasin/code/python/ontospy/ontospyProject/ontospy/cli.py", line 181, in scan
action_analyze(sources, endpoint, print_opts, verbose, extra, raw, individuals, format)
File "/Users/michele.pasin/code/python/ontospy/ontospyProject/ontospy/core/actions.py", line 123, in action_analyze
g = Ontospy(
File "/Users/michele.pasin/code/python/ontospy/ontospyProject/ontospy/core/ontospy.py", line 134, in __init__
self.build_all(
File "/Users/michele.pasin/code/python/ontospy/ontospyProject/ontospy/core/ontospy.py", line 249, in build_all
self.build_shapes()
File "/Users/michele.pasin/code/python/ontospy/ontospyProject/ontospy/core/ontospy.py", line 635, in build_shapes
shacl_constraints = build_shacl_constraints(self)
File "/Users/michele.pasin/code/python/ontospy/ontospyProject/ontospy/core/shacl_helper.py", line 255, in build_shacl_constraints
add_property_constraints_from_shape_triples(lineage_class.uri, property_constraints, shape.triples)
File "/Users/michele.pasin/code/python/ontospy/ontospyProject/ontospy/core/shacl_helper.py", line 298, in add_property_constraints_from_shape_triples
raise Exception('Something is very wrong. Class URI not in triples.')
Exception: Something is very wrong. Class URI not in triples. The error is triggered by line line 297. Not really sure I fully understand the logic there, so maybe you can shed some light. Depending on how bad the cause of the error is, I'd suggest issuing a warning instead and/or failing silently. 3) SciGraph shapes errorYou are totally right @ajnelson-nist, Anyhow, good that you spotted it. I've updated the test RDF with File "/Users/michele.pasin/code/python/ontospy/ontospyProject/ontospy/core/shacl_helper.py", line 298, in add_property_constraints_from_shape_triples
raise Exception('Something is very wrong. Class URI not in triples.')
Exception: Something is very wrong. Class URI not in triples. So, even more curious about how to get rid of that. To sum up - I believe that after addressing that validation error above, we're good to go :-) The UI issues you mentioned are important, but maybe better tackled outside this PR and by using more test input data. |
…on review This patch starts a series of type system reviews to diagnose a few similarly-appearing bugs. Signed-off-by: Alex Nelson <[email protected]>
First, @tobiasschweizer , you were right to give a poke, thanks for that. @lambdamusic , thank you for the test case. We stumbled on a similar issue. @balon and I have started a type review of the |
A recent release of UCO triggered a documentation build failure, localized to something in `shacl_helper.py`. Review of the code found a few missed characteristics of the SHACL specification. The build failure came from an assumption that a SHACL PropertyShape would always be a blank node. While in UCO this was previously true, a named SHACL Property Shape was introduced, defeating the assumption in `shacl_helper.py`. The issue proved difficult to diagnose. As an aid, the file received type signature additions, to help separate RDFLib types, from OntoSpy types, from types local to `shacl_helper.py`. Some class-level variables also got promoted to module-level variables, because (1) their usage behavior was effectively as a module-level variable, and (2) the design pattern can lead to nefariously difficult behavior to debug. See [1], searching the page for the phrase "mistaken use of a class variable". For the sake of improving code comprehensibility, some coding patterns that were using nested `DefaultDict`s to assist with RDF triple iteration were replaced with using temporary `rdflib.Graph`s, for the `graph.triples()` iterator. It's fair to note this trade for comprehensibility may have come at some runtime expense. With this patch, `shacl_helper.py` independently passes static type review by running `mypy` (version 0.942). Type errors are reported from other files that were reviewed only as deep as was necessary to review `shacl_helper.py`'s type goals (especially `entities.py`), but we consider reviewing type signatures in those files as out of scope of this pull request. Also with this patch, UCO 0.8.0 documentation once again builds. References: * [1] https://docs.python.org/3/tutorial/classes.html Acked-by: TJ Balon <[email protected]> Signed-off-by: Alex Nelson <[email protected]>
@lambdamusic : @balon and I think the "Something is very wrong" exception has been addressed. I think we've covered the tests you've mentioned above; |
Thanks @ajnelson-nist @balon this is good to go! |
Thank you! |
Hi there, That is great news, I'll try this asap. |
This patch series is intended to bring Ontospy's current SHACL support up to the level of displaying Property Shapes
on class pages and Shape Properties on shape pages.
A new module, ontospy/core/shacl_helper.py, returns SHACL property constraints, is attached to each OntoClass object,
once the shapes are built in Ontospy.
A few notes on changes:
Please advise if there is a better approach to increasing the support for SHACL into Ontospy, or if any modifications are
needed to the current patch presented.