Skip to content

feat(context): add --xsd-anyuri-as-iri flag for IRI type coercion#3

Open
jdsika wants to merge 1 commit intomainfrom
fix/uri-context-type
Open

feat(context): add --xsd-anyuri-as-iri flag for IRI type coercion#3
jdsika wants to merge 1 commit intomainfrom
fix/uri-context-type

Conversation

@jdsika
Copy link
Copy Markdown

@jdsika jdsika commented Mar 26, 2026

Summary

Add an --xsd-anyuri-as-iri flag to the JSON-LD context generator that emits "@type": "@id" for xsd:anyURI slots instead of the default "@type": "xsd:anyURI".

Problem

JSON-LD processors treat xsd:anyURI values as plain strings. When a LinkML slot has range uri (mapped to xsd:anyURI), the generated context marks it as a string type. Downstream RDF consumers then cannot distinguish IRIs from string literals.

Solution

When --xsd-anyuri-as-iri is set, the context generator checks whether a slot's range resolves to xsd:anyURI and, if so, emits "@type": "@id" to ensure the value is interpreted as an IRI reference during JSON-LD expansion.

Testing

Existing tests pass. The flag defaults to False, preserving current behaviour.

@jdsika jdsika force-pushed the fix/uri-context-type branch from b8091b3 to c9cba82 Compare March 28, 2026 10:51
…I consistency

Add an opt-in --xsd-anyuri-as-iri flag to both the JSON-LD context generator
and the OWL generator, aligning their treatment of range: uri / range:
uriorcurie slots with the SHACL generator's built-in behavior.

Without this flag, the three generators disagree on URI-typed properties:
- OWL:     owl:DatatypeProperty + rdfs:range xsd:anyURI (literal)
- SHACL:   sh:nodeKind sh:IRI (IRI node) — built-in, no flag needed
- Context: @type: xsd:anyURI (literal)

With this flag enabled:
- OWL:     owl:ObjectProperty, no rdfs:range (IRI node)
- SHACL:   sh:nodeKind sh:IRI (unchanged)
- Context: @type: @id (IRI node)

Per OWL 2 Sec 5.3-5.4, ObjectProperty connects individuals to individuals
(IRI nodes), while DatatypeProperty connects individuals to literals.
When SHACL demands sh:IRI and JSON-LD coerces to @id, the OWL layer
must emit ObjectProperty to maintain cross-generator coherence.

Context generator changes:
- New field xsd_anyuri_as_iri (default False) on ContextGenerator
- URI_RANGES_WITH_XSD constant extends URI_RANGES with XSD.anyURI
- visit_slot() and _literal_coercion_for_ranges() check the flag

OWL generator changes:
- New field xsd_anyuri_as_iri (default False) on OwlSchemaGenerator
- slot_owl_type(): promotes URI-range slots to ObjectProperty
- transform_class_slot_expression(): skips literal classification
- _range_is_datatype(): returns False for URI ranges when flag set
- CLI: --xsd-anyuri-as-iri / --no-xsd-anyuri-as-iri option

Signed-off-by: jdsika <carlo.van-driesten@bmw.de>
@jdsika jdsika force-pushed the fix/uri-context-type branch from c9cba82 to 169d11c Compare March 28, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant