Fix jsonld template ops#22
Merged
Merged
Conversation
…ph parse A JSON-LD-shaped dict (carrying @id/@type/@graph/@context) was eagerly parsed to an rdflib.Graph at the process_json layer. When such a dict embedded @op operations, the parse ran before they resolved; unresolved @op objects are illegal JSON-LD (@id must be a string IRI, not an object), so the parser silently minted blank nodes and the intended URIs were lost. The eager parse turns out to be redundant: every op that consumes a JSON-LD body (POST, PUT, Merge, ldh Create*/Add*) already parses a dict itself, and does so with the correct base IRI (publicID=<target url>) that a central parse cannot know. So instead of special-casing op-bearing JSON-LD, drop the Graph fast path entirely: process_json now resolves any embedded @op/variable references in place via _resolve_jsonld and returns a dict for the consuming op to parse. This also removes a latent base-IRI inconsistency between the fast path (no publicID) and the consumers. Add regression tests: op-valued @id resolves to a URIRef (no blank-node subject), nested {"@id": "..."} fragments stay dicts, and pure-data JSON-LD round-trips to the expected graph via a consumer parse. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Establish a uniform RDF type convention: execute() is pure rdflib, execute_json() is the JSON boundary that converts via to_graph(), and process_json() never parses JSON-LD to a Graph. Previously every consuming op hand-rolled the same `Graph().parse(json.dumps(data), format="json-ld", publicID=...)` dance, with inconsistent base-IRI handling (Merge/CONSTRUCT omitted publicID, POST/PUT/ldh ops set it). Add Operation.to_graph(data, *, base=None) as the single conversion point — dict is parsed as JSON-LD at the given base IRI, an existing Graph passes through, anything else raises — and route all 16 parse sites through it (POST, PUT, Merge, CONSTRUCT, DESCRIBE, and the ldh Create*/Add*/Generate* ops). The Generate* ops now also accept a JSON-LD document for their ontology arg, not only a Graph. Document the convention in CLAUDE.md and add tests for to_graph (dict parse, Graph pass-through, base-IRI resolution, type error). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
No description provided.