Skip to content

Expand incoming_class.json and outgoing_class.json views to support SHACL property shapes#334

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-97797f0b-f335-42dc-909f-bf848fff50e9
Draft

Expand incoming_class.json and outgoing_class.json views to support SHACL property shapes#334
Copilot wants to merge 3 commits intomainfrom
copilot/fix-97797f0b-f335-42dc-909f-bf848fff50e9

Conversation

Copy link
Contributor

Copilot AI commented Sep 11, 2025

This PR implements support for SHACL property shapes as links between classes in the incoming_class.json and outgoing_class.json views, addressing the requirement to show SHACL relationships alongside traditional class hierarchy relationships.

Problem

The existing class JSON views only supported basic RDF class hierarchy relationships (rdfs:subClassOf and owl:equivalentClass). They did not recognize SHACL property shapes that create semantic links between classes through shape constraints, missing important relationships in knowledge graphs that use SHACL for data validation and structure definition.

Solution

Extended the SPARQL queries in both templates to detect SHACL property shapes that create class-to-class relationships through:

1. NodeShapes with Target Classes

?source sh:targetClass ?target

Detects when a NodeShape targets a specific class.

2. Property Shapes with Class Constraints

?nodeshape sh:property ?propshape.
?propshape sh:class|sh:node ?target

Finds property shapes that constrain values to be instances of specific classes.

3. Classes Used as NodeShapes

?source rdf:type sh:NodeShape.
?source sh:property ?propshape.
?propshape sh:class|sh:node ?target

Supports the pattern where classes are directly declared as NodeShapes with their own property constraints.

Example SHACL Patterns Supported

# Separate NodeShape
:PersonShape a sh:NodeShape ;
    sh:targetClass :Person ;
    sh:property [
        sh:path :worksFor ;
        sh:class :Organization ;
    ] .

# Class as NodeShape  
:Organization a rdfs:Class, sh:NodeShape ;
    sh:property [
        sh:path :hasEmployee ;
        sh:class :Person ;
    ] .

These now appear as links: PersonShape→Person, Person→Organization, Organization→Person.

Changes Made

  • whyis/namespace.py: Added SHACL namespace (sh:) support
  • whyis/templates/incoming_class.json: Extended with 3 UNION clauses for SHACL patterns
  • whyis/templates/outgoing_class.json: Extended with 4 UNION clauses for SHACL patterns

All changes preserve existing functionality while adding comprehensive SHACL support through minimal, well-documented additions.

Validation

  • ✅ SPARQL syntax validation passed
  • ✅ All SHACL patterns covered (separate NodeShapes, classes as NodeShapes, property constraints)
  • ✅ Backward compatibility maintained (existing rdfs:subClassOf relationships still work)
  • ✅ Comprehensive test data created demonstrating functionality

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ON views

Co-authored-by: jpmccu <602385+jpmccu@users.noreply.github.com>
Copilot AI changed the title [WIP] Expand the incoming_class.json and outgoing_class.json views to support showing SHACL property shapes as links between classes. It should support use of classes as nodeshapes, but also separate nodeshapes. Expand incoming_class.json and outgoing_class.json views to support SHACL property shapes Sep 11, 2025
Copilot AI requested a review from jpmccu September 11, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants