Skip to content
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

Merged
merged 20 commits into from
May 26, 2022

Commits on Dec 8, 2021

  1. Add module to determine SHACL property constraints

    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 <sbernste@mitre.org>
    Signed-off-by: TJ Balon <tbalon@mitre.org>
    balon and stanbernsteen committed Dec 8, 2021
    Configuration menu
    Copy the full SHA
    fbe099f View commit details
    Browse the repository at this point in the history
  2. Formatting changes to browser_shapeinfo.html

    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 <sbernste@mitre.org>
    Signed-off-by: TJ Balon <tbalon@mitre.org>
    balon and stanbernsteen committed Dec 8, 2021
    Configuration menu
    Copy the full SHA
    5fee4eb View commit details
    Browse the repository at this point in the history
  3. Add shape properties to browser_shapeinfo.html

    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 <sbernste@mitre.org>
    Signed-off-by: TJ Balon <tbalon@mitre.org>
    balon and stanbernsteen committed Dec 8, 2021
    Configuration menu
    Copy the full SHA
    4a6d48c View commit details
    Browse the repository at this point in the history
  4. Function to check if an OWL.Class is SH.NodeShape

    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 <alexander.nelson@nist.gov>
    Signed-off-by: TJ Balon <tbalon@mitre.org>
    balon and ajnelson-nist committed Dec 8, 2021
    Configuration menu
    Copy the full SHA
    944e835 View commit details
    Browse the repository at this point in the history
  5. For SHACL NodeShapes, replace tree-diagram in HTML

    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 <tbalon@mitre.org>
    balon committed Dec 8, 2021
    Configuration menu
    Copy the full SHA
    85dff84 View commit details
    Browse the repository at this point in the history
  6. Formatting changes to browser_classinfo.html

    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 <sbernste@mitre.org>
    Signed-off-by: TJ Balon <tbalon@mitre.org>
    balon and stanbernsteen committed Dec 8, 2021
    Configuration menu
    Copy the full SHA
    a53acec View commit details
    Browse the repository at this point in the history

Commits on Dec 9, 2021

  1. Add 'Property Shapes' to browser_classinfo.html

    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 <sbernste@mitre.org>
    Signed-off-by: TJ Balon <tbalon@mitre.org>
    balon and stanbernsteen committed Dec 9, 2021
    Configuration menu
    Copy the full SHA
    1750e87 View commit details
    Browse the repository at this point in the history
  2. Adjust notion of "Top-level property" to account for SHACL shapes

    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 <alexander.nelson@nist.gov>
    Signed-off-by: TJ Balon <tbalon@mitre.org>
    balon and ajnelson-nist committed Dec 9, 2021
    Configuration menu
    Copy the full SHA
    f586950 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    153d5fa View commit details
    Browse the repository at this point in the history

Commits on Dec 16, 2021

  1. Configuration menu
    Copy the full SHA
    141fe7a View commit details
    Browse the repository at this point in the history
  2. Match new query's spelling to getSKOSDirectSupers

    This patch should have no functional impact, except possibly some
    speedup from a braces encapsulation.
    
    Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
    ajnelson-nist committed Dec 16, 2021
    Configuration menu
    Copy the full SHA
    ae42fbf View commit details
    Browse the repository at this point in the history
  3. Rely on implied sh:targetClass

    Review of the SHACL specification showed the sh:targetClass is not
    explicitly required under certain conditions, cited in
    getPropsApplicableByShapes.
    
    Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
    ajnelson-nist committed Dec 16, 2021
    Configuration menu
    Copy the full SHA
    6fa1b3b View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    1d7e289 View commit details
    Browse the repository at this point in the history
  5. Have class-shape confirmation function infer targetClass

    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 <alexander.nelson@nist.gov>
    ajnelson-nist committed Dec 16, 2021
    Configuration menu
    Copy the full SHA
    2eb8543 View commit details
    Browse the repository at this point in the history

Commits on Jan 20, 2022

  1. Configuration menu
    Copy the full SHA
    805d237 View commit details
    Browse the repository at this point in the history

Commits on Mar 11, 2022

  1. scigraph2 rdf test

    lambdamusic committed Mar 11, 2022
    Configuration menu
    Copy the full SHA
    c509dd8 View commit details
    Browse the repository at this point in the history

Commits on Apr 11, 2022

  1. Rename variable to prevent package name conflict; start type annotati…

    …on review
    
    This patch starts a series of type system reviews to diagnose a few
    similarly-appearing bugs.
    
    Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
    ajnelson-nist committed Apr 11, 2022
    Configuration menu
    Copy the full SHA
    9c3961b View commit details
    Browse the repository at this point in the history
  2. Restore whitespace

    ajnelson-nist committed Apr 11, 2022
    Configuration menu
    Copy the full SHA
    8217329 View commit details
    Browse the repository at this point in the history
  3. Flag problem spot

    ajnelson-nist committed Apr 11, 2022
    Configuration menu
    Copy the full SHA
    b4dd695 View commit details
    Browse the repository at this point in the history

Commits on Apr 27, 2022

  1. Rework shacl_helper.py

    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 <tbalon@mitre.org>
    Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
    ajnelson-nist committed Apr 27, 2022
    Configuration menu
    Copy the full SHA
    9bad9d9 View commit details
    Browse the repository at this point in the history