Add download_jsonld_context field for JSON-LD context downloads#1942
Add download_jsonld_context field for JSON-LD context downloads#1942jdsika wants to merge 6 commits into
Conversation
b285b66 to
1f12035
Compare
|
Is this typical usage of JSON-LD, or an idiosyncrasy of LinkML? If it's just a LinkML-specific abuse of JSON-LD (which can store anything), then I would not be so supportive Can you give an example on how to parse a JSON-LD file to retrieve a vocabulary back out of it? Do you have some examples of this being used outside of LinkML-driven repositories? |
1f12035 to
5e8824b
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1942 +/- ##
==========================================
+ Coverage 42.51% 44.92% +2.41%
==========================================
Files 117 142 +25
Lines 8327 10639 +2312
Branches 1963 1856 -107
==========================================
+ Hits 3540 4780 +1240
- Misses 4582 5496 +914
- Partials 205 363 +158 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add a new download_jsonld_context field to the Resource model, following the existing download_jskos pattern. This enables registering direct download links for JSON-LD context files published by ontologies. The field is named download_jsonld_context (not download_jsonld) to clearly distinguish it from a full vocabulary serialization: a JSON-LD context provides term-to-IRI mappings and type coercion rules for compact instance data, not the ontology itself. Includes: - Field definition and getter with doctest on struct.py - Public resolver function get_jsonld_context_download in resolve.py - Re-export in __init__.py - Web UI badge rendering in resource.html - Template variable pass-through in ui.py - Regenerated schema.json - Example data entry for the gx (Gaia-X) prefix Signed-off-by: Carlo van Driesten <carlo.van-driesten@bmw.de>
5e8824b to
b19d0d0
Compare
|
Hi @cthoyt, I had a lengthy back and forth discussion with myself summarized below. I did rename to make the purpose of the specific JSON-LD file clearer. What do you think about it? SummaryPublishing standalone JSON-LD context files at stable URLs is standard W3C practice, not a LinkML idiosyncrasy. The most prominent examples — none of which use LinkML:
These are core W3C Recommendations. JSON-LD contexts are part of the JSON-LD 1.1 specification (§3.1). What a JSON-LD context doesA JSON-LD context provides two things:
This allows instance data to be written as plain, readable JSON while remaining fully interpretable as RDF. For example, the W3C Verifiable Credentials context declares: "issuanceDate": {"@id": "cred:issuanceDate", "@type": "xsd:dateTime"},
"issuer": {"@id": "cred:issuer", "@type": "@id"},
"holder": {"@id": "cred:holder", "@type": "@id"}So a credential can be written as The Gaia-X caseThe Gaia-X context happens to be generated by LinkML, but the output is a standard JSON-LD How to parse itAny standard JSON-LD processor can use the context: from pyld import jsonld
doc = {
"@context": "https://registry.lab.gaia-x.eu/development/context/development",
"@type": "gx:LegalPerson",
"gx:legalName": "Example Corp",
"gx:headquarterAddress": {
"@type": "gx:Address",
"gx:countrySubdivisionCode": "DE-BY"
}
}
# Expand: resolves all terms to full IRIs
expanded = jsonld.expand(doc)
# Convert to RDF:
rdf = jsonld.to_rdf(doc, {'format': 'application/n-quads'})With rdflib: from rdflib import Graph
g = Graph()
g.parse(data=json.dumps(doc), format="json-ld")
# Query with SPARQL, serialize to Turtle, etc.Personal motivation: compact JSON-LD in practiceBeyond the Gaia-X core context, I also maintain ASCS-eV/ontology-management-base — 21 domain ontologies for the ENVITED-X automotive simulation ecosystem built on top of Gaia-X. Each domain publishes an OWL + SHACL + JSON-LD context triad. The contexts for 20 of these domains are generated by a custom SHACL-based generator, not LinkML — they extract The practical benefit: instance data for automotive simulation assets can be written as compact JSON: {
"@context": [
"https://w3id.org/gaia-x/development#",
"https://w3id.org/ascs-ev/envited-x/hdmap/v6/"
],
"@type": "hdmap:HdMap",
"hdmap:hasQuantity": {
"@type": "hdmap:Quantity",
"length": 1.46,
"numberIntersections": 5
}
}Without the context, each float would require Rename:
|
|
what do you think @cthoyt ? |
|
@jdsika I'm at about 80% reject, 20% accept. Still thinking through if this is in scope and if I would want to take on the burden of maintaining code around this I'm still not convinced that using the contexts themselves is a typical way of communicating the contents of a controlled vocabulary. Why not just use RDF encoded in JSON-LD directly, instead of getting even more meta? I've never seen this pattern before. |
|
Hey @cthoyt — thank you for taking the time to think this through. I genuinely appreciate it. You're right that a JSON-LD context is a "helper artifact" — it's derived from the normative vocabulary, not the vocabulary itself. I fully acknowledge that distinction. My argument is purely practical: many projects publish these helpers at stable URLs because they're what developers actually dereference at runtime to write compact JSON-LD instance data. Schema.org, W3C Verifiable Credentials, ActivityStreams, and DID Core all do this — not because the context is the vocabulary, but because it's the artifact users need to use the vocabulary in JSON-LD. For Gaia-X specifically, the context URL is the most practical stable entry point for developers working with the ecosystem. That said, I understand if you feel this is out of scope for the Bioregistry's mission of cataloging vocabularies themselves. No hard feelings either way. Below is a summary of the conversation I had with my agent about this topic, for transparency:
|
Summary
Adds a new
download_jsonld_contextfield to theResourcemodel for registering direct download links to JSON-LD context files published by ontologies. This follows the exact pattern established bydownload_jskos.Motivation
This was discussed in #1939 — the Gaia-X ontology publishes a JSON-LD context at https://registry.lab.gaia-x.eu/development/context/development, but there was no appropriate field to capture it.
download_jsonis specifically for OBO Graph JSON. @cthoyt suggested a follow-up (comment):Rather than burying it in the description, this PR adds first-class support for it.
Changes
schema/struct.pydownload_jsonldfield +get_download_jsonld()getter with doctestresolve.pyget_jsonld_download()public resolver +__all__entry__init__.pyget_jsonld_downloadapp/ui.pyjsonld_downloadto templateapp/templates/resource.htmlschema/schema.jsondata/bioregistry.jsongx(Gaia-X) entry with JSON-LD context URLDesign Decisions
str | Nonetype (likedownload_jskos), notstr | AnnotatedURL | None— JSON-LD contexts don't have format variants_downloads()/has_download()— consistent withdownload_skosanddownload_jskoswhich are also excluded from OLS config eligibilitygxas the example prefixReferences
gxfor Gaia-X Trust Framework Ontology #1939 (comment about JSON-LD context field)download_jskosfield (added for JSKOS JSON format)