Skip to content

Ontology: decouple Ontologies, Semantic Models, and their Mappings - #458

Open
shao-xie wants to merge 2 commits into
apache:mainfrom
shao-xie:decouple-ontology-mapping-documents
Open

shao-xie wants to merge 2 commits into
apache:mainfrom
shao-xie:decouple-ontology-mapping-documents

Conversation

@shao-xie

@shao-xie shao-xie commented Sep 24, 2026 •

Copy link
Copy Markdown

Summary

This proposal recommends splitting that the single Ossie ontology document into three distinct documents: an ontology document, a semantic model document (already standalone today), and a new mapping document, connected by external references instead of embedding. That lets one ontology map to many semantic models, and one semantic model be reused by many ontologies, without duplicating either, and brings the ontology specification in line with the community's recent alignment on one semantic model per document.

The core spec already states one semantic model per document, with no bundling and no cross-model references (core-spec/spec.md). PR #383 made that concrete for every semantic model document except the one still embedded inside an ontology's ontology_mappings, which it explicitly carved out and deferred.

This closes that gap. A mapping can now be written as its own document, validated against the new ontology/mapping.json, instead of embedding a full semantic model inside ontology_mappings. It references exactly one ontology and exactly one semantic model by {name, iri}, name checked against the referenced document's own name, iri saying where to resolve it from. An ontology mapped to more than one semantic model becomes one mapping document per semantic model, each independently owned, rather than one shared ontology_mappings list every owner has to edit.

This does not remove or change the existing embedded shape: ontology_mappings/OntologyMap keeps validating exactly as it does today, now annotated deprecated: true and pointing at the standalone alternative. No kind discriminator is introduced; a mapping document is recognized the same way the existing two document kinds are, structurally, by having concept_mappings, a field neither an ontology nor a semantic model document has.

examples/flights.yaml is split into its three parts (flights.ontology.yaml, flights.semantic_model.yaml, flights.mapping.yaml) as a worked example, byte-identical to the original content, only regrouped. All three, plus the existing tpcds/flights examples, validate cleanly with validation/validate.py against their respective schemas.

Related Issues

Close the gap of PR #383

Checklist

Specification

  • Spec changes are included in core-spec/ and follow the existing structure
  • Spec changes have been discussed on the mailing list or in a linked issue
  • Breaking changes to the spec are clearly called out in the summary

Ontology

  • Ontology changes in ontology/ are consistent with spec changes
  • New or modified terms are defined and documented

Converters

  • Converter logic in converters/ is updated to reflect spec or ontology changes
  • New converters include tests under the converter's test directory

Validation

  • Validation rules in validation/ are updated if the spec changed
  • New validation cases are covered by tests

Documentation

  • docs/ is updated to reflect any user-facing changes
  • New features or behaviors are documented with examples where appropriate
  • CONTRIBUTING.md is updated if the contribution process changed

Examples

  • examples/ are added or updated for any new spec constructs or converter support

Tests

  • All existing tests pass (pytest / CI green)
  • New functionality is covered by tests

Compliance

  • ASF license headers are present on all new source files
  • No third-party dependencies are added without PMC/IPMC approval

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this proposal @shao-xie ! Decoupling the ontology, semantic model, and mapping into separate standalone documents is a great design that directly aligns with the core spec's "one semantic model per document" direction and enables clean reuse without duplicating models.

Before we can merge, please address the following items:

  1. Rebase on main considering merge conflicts ontology/ontology.md.
  2. Fix schema resolution in validation/validate.py.
  3. If possible, add unit tests in test_ontology.py.
  4. Update the CI (validation-ci.yml) update the path triggers to include examples/flights*.yaml and add validation steps for the new examples so CI guards against regressions.
  5. Spec checklist as I was confused 😄 In the PR description you checked Spec changes are included in core-spec but no changes in core-spec are included. You should not check this point.

Comment thread ontology/mapping.json
Comment on lines +29 to +35
"concept_mappings": {
"type": "array",
"items": {
"$ref": "https://raw.githubusercontent.com/apache/ossie/main/ontology/ontology.json#/$defs/ConceptMapping"
},
"description": "Maps logical model constructs to some concept and its relationships in the referenced ontology"
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this $ref points to https://raw.githubusercontent.com/apache/ossie/main/ontology/ontology.json#/$defs/ConceptMapping, validating a mapping document offline or via validation/validate.py currently fails:

[Schema] Cannot resolve schema reference: https://raw.githubusercontent.com/apache/ossie/main/ontology/ontology.json#/$defs/ConceptMapping

In validation/validate.py, validate_schema only pre-registers core-spec/ossie-schema.json in its referencing.Registry. To allow flights.mapping.yaml (and future mapping documents) to validate, please update validate_schema in validation/validate.py to also load and register ontology/ontology.json (under both its $id and its raw GitHub URL), e.g.:

   ontology_path = Path(__file__).parent.parent / "ontology" / "ontology.json"
   ontology = json.loads(ontology_path.read_text())
   ontology_resource = Resource.from_contents(ontology)

   registry = Registry().with_resources([
       (core["$id"], resource),
       ("https://raw.githubusercontent.com/apache/ossie/main/core-spec/ossie-schema.json", resource),
       (ontology["$id"], ontology_resource),
       ("https://raw.githubusercontent.com/apache/ossie/main/ontology/ontology.json", ontology_resource),
   ])

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread ontology/mapping.json
"type": "string",
"description": "Must equal the referenced document's own 'name'; carries this reference's checkable identity regardless of location"
},
"iri": {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that iri is optional here (required: ["name"]), which makes sense for environments where a catalog resolves document locations purely by logical name.

In ontology/ontology.md, it would be helpful to explicitly document this distinction in a small sub-table (stating that name is required and iri is optional) to avoid ambiguity.

Comment thread ontology/ontology.md
| `description` | string | No | Human-readable description |
| `ai_context` | string/object | No | Additional context for AI tools |
| `ontology` | list | Yes | Concepts and relationships they group that form this ontology |
| `ontology_mappings` | list | No | Deprecated; accepted only so existing documents continue to validate. Write mappings as [mapping documents](#mapping-documents) instead |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up: there is a merge conflict here with recent PR #400 (which added prefixes to this table). When rebasing onto main, please ensure both prefixes and ontology_mappings rows are retained.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread ontology/ontology.md
in the ontology. Just as ontologies are partitioned by concept, ontology maps partition into concept
mappings that group by some concept.

### Mapping documents

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a merge conflict at the start of this section against PR #441 (which documented embedding complete core documents inside ontology_mappings). When rebasing, placing the ### Mapping documents section first and keeping the deprecation note for embedded mappings will align nicely.

Also, could we add a sub-table here for the reference object (DocumentReference)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread ontology/ontology.md
- **0.2.0.dev0** (2026-05-29): Basic support for ontologies and logical schema mappings
- Core ontology structure: Concepts, relationships, and business rules (requires and derived_by)
- Schema mappings from one or more logical models into an ontology
- Mapping documents (`ontology/mapping.json`) that reference one ontology and one semantic

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section conflicts with commits on main from PR #400 (IRIs and prefixes) and PR #441 (embedded core document versions). Please retain those entries when resolving the rebase.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +21 to +26
ontology:
name: Flights
iri: ./flights.ontology.yaml
semantic_model:
name: Flights semantic model
iri: ./flights.semantic_model.yaml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names align cleanly with flights.ontology.yaml and flights.semantic_model.yaml. The relative ./ reference is clean and works well for file-based repository layouts.

Shao Xie and others added 2 commits September 30, 2026 18:01
Add ontology/mapping.json for mapping documents that reference exactly one
ontology and one semantic model by {name, iri} instead of embedding them, and
deprecate the embedded ontology_mappings list. Document the mapping document
and its reference object in ontology.md, and split examples/flights.yaml into
flights.ontology.yaml, flights.semantic_model.yaml and flights.mapping.yaml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PEsT5t9mcXM6fF4QUC8Y7V
Register ontology/ontology.json alongside the core schema in validate.py's
registry, so mapping documents that reference ConceptMapping validate offline.
Add tests for mapping documents and the split flights examples, and validate
the flights examples in Validation CI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PEsT5t9mcXM6fF4QUC8Y7V
@shao-xie
shao-xie force-pushed the decouple-ontology-mapping-documents branch from 843147b to b78ab22 Compare September 30, 2026 18:08
@shao-xie shao-xie changed the title Decouple Ontologies, Semantic Models, and Their Mappings Through External References Ontology: decouple Ontologies, Semantic Models, and their Mappings Sep 30, 2026
@shao-xie

shao-xie commented Sep 30, 2026 via email

Copy link
Copy Markdown
Author

@kurtStirewalt

Copy link
Copy Markdown
Contributor

Looks good @shao-xie . Thanks for putting this together.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants