-
Notifications
You must be signed in to change notification settings - Fork 152
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
Ability to declare a container as both @language and @set #407
Comments
I don’t know how frequent having multiple string values per language are (I haven’t seen this often) but I tagged it as a request for the next version of JSON-LD. Thanks for the suggestion |
The current behavior is the one I would expect. But non-RDF developers might like sets (JS arrays) with a single element. That could be a more general use case. |
@akuckartz Yeah, as a JS developer I find that I easily end up with a lot of extra code to normalize the data to make it easier work with. For instance I currently have something like this to cast the altLabels to arrays: function asArray(x) {
return typeof(x) == 'undefined' ? [] : (typeof(x) == 'string' ? [x] : x);
}
function valuesAsArray(x) {
x = x ? x : {};
Object.keys(x).forEach(function(key) {
x[key] = asArray(x[key]);
});
return x;
}
concept.altLabel = valuesAsArray(concept.altLabel); |
@danmichaelo, btw, if you're using jsonld.js you can use: var thisIsAnArrayOfValues = jsonld.getValues(node, 'property'); |
@dlongley Sweet, thanks! |
We have this use case as well, for serializing vocabularies in SKOS and in providing data level internationalization. Each term has multiple labels in multiple languages, and it would be nice to be able to use |
@azaroth42 good to know. Do you have a proposal for addressing this in the spec? |
Here's a proposal for both this issue and #269: PROPOSAL: updating the definition of
This allows a term definition such as the following: {
"@context": {
"skos": "http://www.w3.org/2004/02/skos/core#",
"prefLabel": {
"@id": "skos:prefLabel",
"@container": "@language @set"
},
"altLabel": {
"@id": "skos:altLabel",
"@container": "@language @set"
}
}
} Other than If this is acceptable, please 👍 or 👎 this comment, or suggest an improvement. |
Can you describe the rationale for whitespace separation rather than a JSON array? e.g. what was undesirable about:
Also, is the order of |
It could go either way, whitespace separation keeps values of
vs.
Checking for appropriate combinations should be done as another way of supporting backwards-compatibility. If that's preferable, we could amend the proposal to use the array form. |
👍 for the array form |
My fear about micro-DSLs even as simple as "whitespace separated terms" is that they invariably end up less and less micro. OTOH, I understand the backwards compatibility desire of keeping the data type only a string, and also to avoid annoying type checking. I'm 👍 to the proposal and don't mind either a string or an array, with a vague preference for an array. |
👍 for the proposal with a slight preference for array (i.e. with a preference for mixed type with "ready to use" values over a microsyntax). |
👍 for the array version, very 👎 for the microsyntax (whitespace delimited). |
Array version it is. I'll implement and do a PR when I have time. |
…ion to other appropriate keywords. Addresses json-ld/json-ld.org#269 and json-ld/json-ld.org#407.
The example really shouldn't use |
@niklasl Which example uses more than one |
@gkellogg I only saw it in the proposal context above (#407 (comment)). Just in case anyone would build off of that. |
Okay, sure. Didn't make it into the PR. |
Just in case it would be more comprehensible, we might consider splitting the support for "container-as-an-indexed-dict" and "container-as-an-array" into two keywords. That is, in JSON-LD 1.1, declaring a term to be indexed on Apart from splitting up the current meaning of containers for the possible benefit of intuitive understanding of indexed dicts, this proposal would then look like: "altLabel": {"@index": "@language", "@container": "@set"}, With this, I cannot say whether this is better or not. It might be more intuitive for someone who isn't accustomed to JSON-LD 1.0. For the rest of us, this certainly does throw things around a bit (and I admit I haven't at all considered the consequences in terms of the spec text yet). It did occur to me quite a while back originally though, so I'd like to through it out here for consideration, if for nothing else than to avoid second thoughts further down the line. (Admittedly, using |
Related to #269 . I would like to use
@language
maps with@set
, but haven't found a way to do so.My data is following the SKOS model, where each concept can have one preferred label per language, and any number of alternative labels per language. To make the data easy to work with, I'm trying to achieve the following output:
The best context I've come up with is this (JSON-LD Playground):
but this makes
altLabel
a set (or a js list) only if there's more than one item, an object otherwise. I would like to forcealtLabel
to always be a set.The text was updated successfully, but these errors were encountered: