feat(context): add --xsd-anyuri-as-iri flag for IRI type coercion#3
Open
feat(context): add --xsd-anyuri-as-iri flag for IRI type coercion#3
Conversation
b8091b3 to
c9cba82
Compare
…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>
c9cba82 to
169d11c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add an
--xsd-anyuri-as-iriflag to the JSON-LD context generator that emits"@type": "@id"forxsd:anyURIslots instead of the default"@type": "xsd:anyURI".Problem
JSON-LD processors treat
xsd:anyURIvalues as plain strings. When a LinkML slot has rangeuri(mapped toxsd: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-iriis set, the context generator checks whether a slot's range resolves toxsd:anyURIand, 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.