Skip to content

ontology: converters drop iri and prefixes #478

Description

@RyutoYoda

ontology/ontology.json gives concepts and relationships an optional iri, and the
document root a prefixes map that QName IRIs resolve against (added in #332, renamed
and documented in #400). converters/ontology was never updated, so the reference
Python implementation cannot handle a document that uses them.

There are two separate symptoms.

The parser rejects a document the schema accepts. Given iri_probe.yaml:

version: 0.2.0.dev0
name: IriProbe
prefixes:
  foaf: http://xmlns.com/foaf/0.1/
ontology:
- concept: Person
  type: EntityType
  iri: foaf:Person
  identify_by: [ name ]
  relationships:
  - name: name
    iri: foaf:name
    roles:
    - concept: String
    verbalizes: [ '{Person} is identified by {String}' ]
    multiplicity: OneToOne
$ uv run validation/validate.py iri_probe.yaml --schema ontology/ontology.json
Validation PASSED: iri_probe.yaml

$ uv run python -c "from pathlib import Path; from ossie_ontology.parser import OssieParser; OssieParser().parse(Path('iri_probe.yaml'))"
pydantic_core._pydantic_core.ValidationError: 3 validation errors for OssieSpec
ontology.0.relationships.0.iri
  Extra inputs are not permitted [type=extra_forbidden, input_value='foaf:name', input_type=str]
ontology.0.iri
  Extra inputs are not permitted [type=extra_forbidden, input_value='foaf:Person', input_type=str]
prefixes
  Extra inputs are not permitted [type=extra_forbidden, input_value={'foaf': 'http://xmlns.com/foaf/0.1/'}, input_type=dict]

Accepting them in the DTOs alone would not be enough. model.py has nowhere to hold
either field, so parse discards them and OssieToSpecConverter.convert(...).dump_yaml()
emits a document with the iri values and the prefixes map gone — silently, since both
fields are optional and their absence is valid. I confirmed this by adding the three
fields to spec.py only. The document then parses, and comes back like this:

version: 0.2.0.dev0
name: IriProbe
ontology:
- concept: Person
  type: EntityType
  identify_by:
  - name
  relationships:
  - name: name
    roles:
    - concept: String
    verbalizes:
    - '{Person} is identified by {String}'
    multiplicity: OneToOne

No error, no warning — both fields are optional, so their absence is a valid document.

The fix is to carry both through the whole path: spec.py -> model.py ->
spec_to_ossie -> ossie_to_spec.

This matters beyond the round trip. iri and prefixes are how an Ossie ontology is
pinned to an external RDF or OWL vocabulary, so any converter that targets one — #431
(SHACL/RDFS) and #389 (LinkML) — needs them to reach the model. Today they cannot.

Same shape as #424, which was about datatype.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageIssue needs triage by a maintainer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions