Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
matthieu-fesselier opened this issue Sep 16, 2019 · 8 comments
Labels
feature A new feature to be added

Comments

@matthieu-fesselier
Copy link

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
Copy link
Member

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 RubenVerborgh added the feature A new feature to be added label Sep 16, 2019
@RubenVerborgh RubenVerborgh changed the title Cannot use reduced ids Enable JSON-LD expansion on subjects (in addition to properties) Sep 16, 2019
@rubensworks
Copy link
Contributor

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
Copy link
Author

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

@rubensworks
Copy link
Contributor

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
Copy link
Author

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
Copy link
Member

You get back a NamedNode; they are full URIs.

@matthieu-fesselier
Copy link
Author

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

@RubenVerborgh
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature to be added
Projects
None yet
Development

No branches or pull requests

3 participants