Query-Solid
Query-Solid copied to clipboard
Enable JSON-LD expansion on subjects (in addition to properties)
As we sometimes use the resource ids in URLs, we would like to use reduced ids to make it cleaner. I expected the following code to work but I get an error. Am I doing something wrong here?
const base_context = {
...
"collective":"https://api.happy-dev.fr/collectives/"
};
await solid.data.context.extend(base_context);
const resource = solid.data['collective:1']
console.log(`${await resource.name}`)
JSON-LD context expansion is currently not used for the base subject (directly after 'solid.data'), only for properties. It does indeed make sense to extend it to this case.
For reference when this will be implemented:
It is important to use base expansion here, instead of the vocab expansion that is currently used for properties. This is because JSON-LD requires subjects (and objects) to be resolved against @base
, and predicates against @vocab
.
Great thanks! Any idea on how to reduce URLs on the meantime? Should we use the JSON-LD library?
Considering jsonld-context-parser
is already added as a dependency, you could use that as follows:
const ContextParser = require('jsonld-context-parser').ContextParser;
const normalizedContext = await myParser.parse({
...
"collective":"https://api.happy-dev.fr/collectives/"
});
const iri = ContextParser.expandTerm('collective:1', normalizedContext);
const resource = solid.data[iri]
Thanks!
When I get the type
of this container: https://api.happy-dev.fr/collectives/
I get the expanded field http://www.w3.org/ns/ldp#Container
, but I expected ldp:Container
. Is it the same problem here?
You get back a NamedNode; they are full URIs.
Ok, you mean that the NamedNode URIs are never compacted with the current context?
Indeed: https://rdf.js.org/data-model-spec/#namednode-interface