LDflex / Query-Solid

Simple access to data in Solid pods through LDflex expressions
https://solid.github.io/query-ldflex/
MIT License
66 stars 15 forks source link

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

Open matthieu-fesselier opened 5 years ago

matthieu-fesselier commented 5 years ago

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}`)
RubenVerborgh commented 5 years ago

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.

rubensworks commented 5 years ago

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.

matthieu-fesselier commented 5 years ago

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

rubensworks commented 5 years ago

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]
matthieu-fesselier commented 5 years ago

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?

RubenVerborgh commented 5 years ago

You get back a NamedNode; they are full URIs.

matthieu-fesselier commented 5 years ago

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

RubenVerborgh commented 5 years ago

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