Query-Solid icon indicating copy to clipboard operation
Query-Solid copied to clipboard

Enable JSON-LD expansion on subjects (in addition to properties)

Open matthieu-fesselier opened this issue 5 years ago • 8 comments

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}`)

matthieu-fesselier avatar Sep 16 '19 13:09 matthieu-fesselier

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.

RubenVerborgh avatar Sep 16 '19 13:09 RubenVerborgh

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.

rubensworks avatar Sep 16 '19 14:09 rubensworks

Great thanks! Any idea on how to reduce URLs on the meantime? Should we use the JSON-LD library?

matthieu-fesselier avatar Sep 17 '19 06:09 matthieu-fesselier

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]

rubensworks avatar Sep 17 '19 06:09 rubensworks

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?

matthieu-fesselier avatar Sep 17 '19 12:09 matthieu-fesselier

You get back a NamedNode; they are full URIs.

RubenVerborgh avatar Sep 17 '19 12:09 RubenVerborgh

Ok, you mean that the NamedNode URIs are never compacted with the current context?

matthieu-fesselier avatar Sep 18 '19 06:09 matthieu-fesselier

Indeed: https://rdf.js.org/data-model-spec/#namednode-interface

RubenVerborgh avatar Sep 18 '19 13:09 RubenVerborgh