Skip to content

Fix jsonld template ops#22

Merged
namedgraph merged 2 commits into
mainfrom
fix-jsonld-template-ops
Jun 29, 2026
Merged

Fix jsonld template ops#22
namedgraph merged 2 commits into
mainfrom
fix-jsonld-template-ops

Conversation

@namedgraph

Copy link
Copy Markdown
Member

No description provided.

namedgraph and others added 2 commits June 30, 2026 01:11
…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>
@namedgraph namedgraph merged commit 92c8e9c into main Jun 29, 2026
6 checks passed
@namedgraph namedgraph deleted the fix-jsonld-template-ops branch June 30, 2026 07:48
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