Skip to content

feat: auto-generate RDF/XML and JSON-LD serialisations from TTL source #10

@Daham-Mustaf

Description

@Daham-Mustaf

Context

The mobilityDCAT-AP ontology is currently maintained in three separate files:

  • mobilitydcat-ap_v1.1.0.ttl — Turtle (hand-edited)
  • mobilitydcat-ap_v1.1.0.rdf — RDF/XML (hand-edited)
  • mobilitydcat-ap_v1.1.0.jsonld — JSON-LD (hand-edited)

All three are edited independently, which leads to inconsistencies — the bugs
found in issue #179 exist because the three files have drifted from each other.

Proposal

Single source of truth: the TTL file.

The RDF/XML and JSON-LD serialisations should be automatically generated from
the TTL file using a script. This means:

  • Maintainers only edit mobilitydcat-ap_v1.1.0.ttl
  • A script converts it to .rdf and .jsonld
  • The generated files are committed to the repository
  • CI can verify the generated files are up to date with the TTL source

Implementation

A script scripts/serialise_ontology.py using rdflib:

from rdflib import Graph

g = Graph()
g.parse("mobilitydcat-ap_v1.1.0.ttl", format="turtle")
g.serialize("mobilitydcat-ap_v1.1.0.rdf", format="xml")
g.serialize("mobilitydcat-ap_v1.1.0.jsonld", format="json-ld")

Benefits

  • Single point of edit — no more three-way inconsistencies
  • Bugs fixed in TTL automatically propagate to all formats
  • Simpler review — only TTL needs to be reviewed in PRs
  • Can be integrated into CI to auto-regenerate on TTL change

Relation to existing scripts

The repository already has scripts/serialise-vocabulary.sh and
scripts/serialise-examples.sh. This would add a dedicated ontology
serialisation script following the same pattern.

Related

  • #179 — bugs caused by manual three-file maintenance
  • #180 — PR fixing those bugs across all three files manually (last time)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions