feat(contextgen): add @type: @vocab coercion for eligible enums#8
Open
feat(contextgen): add @type: @vocab coercion for eligible enums#8
Conversation
5cdcd02 to
63c5dd9
Compare
Emit @type: @vocab with a scoped @vocab namespace for enum-ranged slots whose permissible values all have meaning IRIs that share a single namespace and whose text matches the meaning local name. This enables bare string enum values (e.g. "RoadTypeMotorway") to expand to full IRIs via JSON-LD 1.1 type coercion (section 4.2.3) combined with scoped contexts (section 4.1.8). The combined context preserves backward compatibility with structured {text, description, meaning} objects via the existing SKOS mappings. Enums that don't meet the eligibility criteria (missing meanings, mixed namespaces, or text/local-name mismatches) fall back to the existing ENUM_CONTEXT behavior. Refs: linkml#2497 Signed-off-by: Carlo van Driesten <carlo.van-driesten@bmw.de>
63c5dd9 to
5edfd2c
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
Adds JSON-LD 1.1
@type: @vocabcoercion for enum-ranged slots whose permissible values are eligible (all have meanings, single namespace, text matches local name).Problem
LinkML's
visit_enumis a no-op — enum permissible values are not emitted in the generated JSON-LD context. Slots with enum ranges only get a structuralENUM_CONTEXTmapping ({text: skos:notation, description: skos:prefLabel, meaning: @id}), which requires structured object values.In practice, JSON data files use bare string enum values (e.g.,
"DrivableAreaType": "RoadTypeMotorway"). Without context support, these remain plain strings and don't expand to IRIs.Upstream issue: linkml#2497
Approach
Uses JSON-LD 1.1 §4.2.3 (type coercion via
@vocab) combined with §4.1.8 (scoped contexts):This supports both value forms simultaneously:
"RoadTypeMotorway"→ expands to IRI via scoped@vocab{text, meaning}→ SKOS mappings still workEligibility Criteria
An enum qualifies only when ALL conditions are met:
meaningIRIIneligible enums fall back to the existing
ENUM_CONTEXTbehavior.Changes
jsonldcontextgen.py: Added_vocab_eligible_enum()method + modifiedvisit_slotenum branchtest_jsonldcontextgen.py: 7 new tests covering eligible/ineligible cases, pyld expansion verification, kitchen_sink fallbackTesting
References
@type: @vocab)