Repository navigation
Description
What happens
When a query declares a prefix whose namespace is itself an IRI in the result, the JSON-LD formatter writes that IRI in an @id position as the bare prefix name. With PREFIX b: <https://ns.flur.ee/business/>, the object of
b:Account rdfs:isDefinedBy <https://ns.flur.ee/business/> .comes out of a CONSTRUCT as
"rdfs:isDefinedBy": [{ "@id": "b" }]In JSON-LD an @id of "b" is a relative IRI, resolved against the document's base. Any standards-conformant reader therefore gets a different IRI. Fluree reads the file back as intended, so a round trip through Fluree hides the problem.
Found exporting a whole model from fluree/solo (fluree/solo#1476): with the model's prefixes declared, rdflib 7.6.0 read 403 of the seeded Business Model's 9,312 triples wrong. All 403 are rdfs:isDefinedBy objects naming the b: or schema: namespace. The Turtle written from the same query and prefixes is correct (b: / b: a owl:Ontology).
Cause
ContextCompactor::compact_id (fluree-graph-json-ld/src/compact.rs, on main) calls compact_with, whose first step is an exact match against the context's term definitions:
// 1. Exact match
if let Some(prefix) = exact.get(iri) {
return prefix.clone();
}That is right in vocabulary position (properties, @type). JSON-LD 1.1's IRI compaction uses a term for an IRI only when vocab is true, though. A term whose IRI mapping equals the IRI also can't serve as the prefix of a compact IRI. So in an @id position the result should be the full IRI, or a @base-relative form.
This is the same family as #1280 (@id compacted against @vocab), which routed @id through compact_id. The exact-term step inside it is what remains.
Repro
PREFIX b: <https://ns.flur.ee/business/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }Run it over
<https://ns.flur.ee/business/Account> <http://www.w3.org/2000/01/rdf-schema#isDefinedBy> <https://ns.flur.ee/business/> .and ask for the default (JSON-LD) answer. Expected: {"@id": "https://ns.flur.ee/business/"}. Actual: {"@id": "b"}.
Fix
Skip the exact-term match when allow_vocab_strip is false (the @id path), or keep separate exact maps so that exact_id holds only the @id-term mappings that JSON-LD allows.
Meanwhile
fluree/solo's model export now sends no prefixes with a JSON-LD export, so every IRI is written in full.
🤖 Generated with Claude Code
Activity