Closed marcolarosa closed 4 years ago
The playground is running 1.8.0. Difference is likely the base URI you are processing with and that those ids are relative. That paradisec.org id should probably start with http or https? Otherwise it would be relative to the playground URL itself.
@davidlehn thankyou!
How can I get my script to behave the same as the playground? I don't see base defined anywhere in the playground and I'm not defining a base anywhere as far as I can tell but I do want relative URLs.
The playground uses it's own URL as the base, IIRC. We had to guess what the least confusing default would be. It should be an adjustable UI option but no one has added that feature yet. The jsonld.js compact API has a base
option you can set to whatever you'd like.
@davidlehn Ahh the lack of a configurable base in the playground explains one part of the mystery! I'm just looking at the jsonld docs and I don't see the option for configuring the base (though that may be my lack of familiarity with the tool).
Are you able to provide a small example of how I would use compact?
Thanks heaps!
Like this but with an options param: https://github.com/digitalbazaar/jsonld.js/#compact
const compacted = await jsonld.compact(doc, context, {base: ...});
The API options docs are just in the code at the moment: https://github.com/digitalbazaar/jsonld.js/blob/master/lib/jsonld.js.
@davidlehn
ok - thanks for the info.
I've been diving around in the jsonld.js
and compact.js
code and it seems like the prefixing is happening long before the compaction code. In fact, it looks like the required option is skipExpansion: true
, viz:
(async () => {
let root = await jsonld.compact(data, {
"@context": "https://schema.org",
},
{
"skipExpansion": true,
}
);
console.log(JSON.stringify(root, null, 2));
})();
Results in (what I'm expecting):
{
"@context": "https://schema.org",
"id": "./",
"http://pcdm.org/models#hasMember": {
"id": "paradisec.org.au/AC1/001"
}
}
I also tried with:
{
"base": null,
"compactArrays": false,
"compactToRelative": true,
"skipExpansion": true,
}
But it was skipExpansion that did the trick.
Does that seem right to you?
Closing as stale/this should be filed under json-ld.org as an issue or feature for the playground.
If I run the following node script (using jsonld v1.8):
I get:
In the playground however, the same
data
compacted gives:Notice that the value for the "hasMember" id in the script output has a
/
prepended to it (/paradisec... vs paradisec...) that doesn't get added in the playground.Why is that?