[FEATURE]: Inherit relationships through the ontology · Issue #43 · databrickslabs/ontobricks · GitHub
Skip to content

[FEATURE]: Inherit relationships through the ontology #43

Closed

Description

@ulsmo

Is there an existing issue for this?

  • I have searched the existing issues

Problem Statement

When creating subclasses in the ontology, it's great that the attributes are inherited and can be added in the mappings.
Relationships don't get the same functionality - if there are relationships defined on the parent class, data cannot be mapped to the relationship for the subclass and no relationships are created in the knowledge graph for the subclass.

Proposed Solution

Either:

  1. Create an explicit mapping for relationships for the subclass when a parent has a defined relationship.
    This could result in a combination explosion for mappings, especially for self-referencing relationships.
  2. Load a relationship for the subclass based on the mapping from the parent class.
    This would require resolving which subclass the mapping should be applied to when loading.

Area

Mapping (Manual / SparkSQL)

Additional Context

It's possible to assign a mapping for both the parent and subclass entities, and their id's don't have to be the same. This leads to some modeling considerations that might influence how inherited relationships can work:

  1. If the knowledge graph loads entities at parent and subclass levels and the id's are the same, should both instances be loaded into separate entities or merged together at the subclass level?
  2. Should the modeler define a relationship between the parent and subclass to inform they are the same, or should the equality of the instances be inferred?
  3. If equality is inferred, can the query endpoints and AI chat functionality deduce the equality at execution time from the ontology, or would it be better to materialize these equality relationships using inference rules?

Activity

  1. ulsmo commented on Jun 24, 2026

    @ulsmo
    ContributorAuthor

    I explored approach 2, using one mapping to drive multiple entities and mappings.
    This seems like it should be possible using R2RML string templates if the class can be expressed from the data source - e.g. added as a CASE WHEN to create a class column representing the entity. Then the mapping for an entity could be:

    rr:subjectMap [ rr:class <BASE_URI#{class}> ;
            rr:template "BASE_URI/{class}/{id}" ] 
    

    and for a relationship:

    rr:predicateObjectMap [ rr:objectMap [ rr:template "BASE_URI/{source_class]/{source_id}" ] ;
            rr:predicate ont:RELATIONSHIP ] ;
    rr:subjectMap [ rr:template "BASE_URI/{target_class}/{target_id}" ] .
    

    I tried to define this in R2RML manually and import - it didn't map to any classes and the R2RML could not be generated, breaking the build of the knowledge graph.

    This would not fit natively within the current assumptions of the UI. So either it would have to be built in as a native feature, or it would require an "advanced" mapping mode that would support handcoded R2RML that could be used directly in the build phase.

  2. added this to the v0.9.0 milestone on Oct 26, 2026
  3. benoitcayladbx commented on Oct 26, 2026

    @benoitcayladbx
    Collaborator

    This landed in 0.9.0. We went with the second idea from the issue: do not clone the relationship mapping onto every subclass. The object property stays declared on the parent; subclasses inherit it at read time.

    What you get:

    • Studio / Mapping canvas — dashed subclass → range edges for inherited outgoing relations.
    • Entity panel — read-only “inherited from <parent>” list; Mapping Status links open the declaring class mapping.
    • Mapping / KG build — one SQL / R2RML triple map per property URI, on the class that declares the relation. Subclass instances that also type as the parent pick up those triples via rdfs:subClassOf. No second mapping on the child, so no mapping-combinatorial explosion (including self-loops).
    • OWL export — still rdfs:domain on the declaring class plus rdfs:subClassOf on the child.

    That also explains the R2RML experiment with {class} templates: OntoBricks still assumes one mapping per class/property URI. We did not add an “advanced” hand-coded R2RML mode.

    Not in scope (on purpose): incoming (range) inheritance, per-subclass relationship SQL, and inferring that a parent instance and a subclass instance are the same individual when their mapped IDs differ. Those stay two ABox nodes unless you model them as the same IRI (or add an explicit same-as / identity rule). If parent and subclass mappings share the same IRI, OWL already treats the subclass instance as a valid subject of the parent property.

    Docs: user guide “Inherited relations”; architecture “Inherited outgoing relations”. Tests: tests/units/ontology/test_inherited_relations.py, tests/units/front/test_inherited_relations_ui.py.

    Closing as completed in 0.9.0. If a case still fails (subclass KG with a distinct IRI from the parent, self-referencing properties, etc.), reopen with that example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions