Skip to content

Evaluate replacing the hand-written context walker with pyld #118

Description

@LukasOro

src/oold/validation/context_resolution.py hand-walks an OO-LD @context chain in about 300 lines to produce a flattened context. Its module docstring justified this by claiming a JSON-LD processor cannot consume these entries. That claim is false and has been corrected in #114; the code was left in place.

Evidence the premise was wrong

Pointing pyld at tests/data/oold/Person.schema.json as a remote context, with a document loader mapping the fixture directory:

doc = {"@context": "https://example.org/Person.schema.json", "name": "Ada"}
jsonld.expand(doc)
# -> [{"http://schema.org/name": [{"@value": "Ada"}]}]

It resolved, following the relative sibling Thing.schema.json and picking up the schema: prefix defined several hops up the chain. Per JSON-LD 1.1 a remote context document only needs a top-level @context; other entries are ignored. That is what OOLD-CMP-b926 guarantees by requiring an OO-LD schema to be usable as a context without further processing.

What is actually needed

The callers do not want expansion. They want the effective context as a value: which terms a schema defines and which hop each came from, for term reporting and the per-property attribution in src/oold/validation/predicates.py. pyld does return the flattened active context, through JsonLdProcessor.process_context - see #118 (comment) and the confirmation below it. What it does not carry is per-term provenance: mappings records no source document, so "which hop defined this term" has to be recovered by processing the chain a hop at a time and diffing.

Work

  • Determine whether the effective context can be obtained from pyld without relying on private API, for example by expanding a probe document built from the schema's declared properties and reading back the mapping
  • Compare the result against resolve_context() across the whole fixture corpus, including the scoped-context form {"@id": ..., "@context": "Other.schema.json"}
  • If it holds, replace the walker; if it does not, record which specific capability is missing so the module has a justification that survives review

Constraint

rule.* and context.* verdicts must not move. The parity tests (OOLD_SCHEMA_DIR=../oold-schema uv run pytest -m parity) are the gate.

Raised from review of #114 (comment).

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions