-
Notifications
You must be signed in to change notification settings - Fork 23
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
New feature: @template
#362
Comments
Specifically for URL-s there is a URI Template RFC document. I know we referred to it in the CSVW work, but that is something that @gkellogg knows way better. I do not know whether it is too much for what we want, whether it is also usable for non-URL purposes, etc. But it has the advantage of being documented and would avoid reinventing the wheel... |
I like the proposal.
Probably A little bit related: the Hydra explicit and basic variable representations for URI templates: https://www.hydra-cg.com/spec/latest/core/#example-22-the-different-variable-representations |
I really like the idea, and agree that for URIs, @iherman's suggestion on using URI Templates is the definitive way to go. I don't think URI Templates can (or should) be used for non-URI data, though. At least not without defining some clear processing rules (perhaps some inspiration can be sourced from RFC 5229). Something I believe is going to surface as a need almost immediately after …Which begs the question: How should |
I'm not convinced, I'm afraid. This is even more complex than the frequently requested ability to change datatypes / add classes with The data would not round-trip, as the template would not be reversible. Once the context has been applied, it cannot be unapplied. Even worse, once it was applied, it could then be applied again if it could be used with strings, resulting in (e.g.) "168 cm cm cm cm cm". The template pattern is not idempotent, and there's no way to know when to apply it and when it has already been applied. So I'm 👎 on the feature in its current state |
I agree with @azaroth42 Beside a lot of unresolved issues this feature brings, the current complexity of JSON-LD is quite big. There are plenty of syntax description formats (OAS, RAML, etc.) that can be used as a source for a preprocessor to transform an input into hypermedia format before passing it to JSON-LD processor. |
@iherman @asbjornu @pietercolpaert @asbjornu @azaroth42 @filip26 |
Okay, if it only works for numeric data (by which I mean I have use cases for this too, FWIW. We have information systems that naively use an incrementing integer as the core identity for records describing objects, people, places and events. If For example: http://vocab.getty.edu/aat/300194222 could have: With those caveats to ensure round tripping, I'm a definite +0 |
For values of We did use the URI templates mechanism for CSVW, and it can do everything we want, and probably needs some more consideration to see how it adapts to creating URIs from values. Something like One of the issues we've encountered recently, though, is that URI templates end up escaping non-ASCII data. I believe that you can uniformly decode the value of the template transformation without messing up any legitimate data, which we'd need to be sure to allow for. As @asbjornu says, a URI template can interpret other variable values, which could potentially come from other properties of the node, but this adds substantial complexity, and I would suggest we constrain ourselves to "the simplest thing which could possibly work", and see where that gets us. In this case, limiting ourselves to only the value of the Regarding non-IRI values, CSVW also considered using |
Would this not work for more general alphanumeric identifiers? There are plenty in wide use (e.g. UUIDs). The restriction to a single use of a single value is what seems to me to make it feasible, but perhaps I'm missing something. |
It should work for any URI, and with unescaping, IRI. It is just restricted to generate URIs, not general string literals. |
The problem is: if you try to compact Also, canonical numbers representations can (I think) be inserted into IRIs without any escaping/encoding, while other characters may need this.
Well, the second use case is important for us too...
This is why I was not suggesting to design a complex formatting mechanism, just dead-simple substitution -- or, more precisely: concatenating something before and after the original value. This also makes "unapplying" the template easy. Should the template fail to "unapply" during compaction (either because the expanded value does not match the prefix or suffix of the template, or because the substring in between does not parse to a number), the term definition will not apply. This is the same thing that happens when a term definition specifies a |
Here is a feature that I discussed with some colleagues, and that we really would like to see in a future version of JSON-LD.
Use cases
Consider the following example JSON, as would be produced by a Web API
We know from the API documentation that
id
is a unique local identifier for this entity, whose corresponding IRI ishttp://example.org/users/1234
. Unfortunately, there are two problems with the current spec:@id
accepts only strings;1234
was replaced with"1234"
, it would be resolved against the@base
of the context; setting the base tohttp://example.org/users/
for the sole purpose of this property would not always be appropriate.We also know from the API documentation that
height
is expressed in centimetres. We would like to map it using thecdt:ucum
datatype, i.e. into"168 cm"^^cdt:ucum"
.Proposed solution
@template
keyword that can appear in a term definition; the value is a string containing a single placeholder{}
, for examplehttp://example.org/users/{}
or{} cm
;@template
attribute is usable only if the@id
or@value
"matches" the template. Its value is then replaced by extracting the substring corresponding to the placeholder.An example context for the use-case above would then look like
Remaining issues
{}
the best choice for the placeholder?@template
for number values, or do we also use it with strings? There would possibly be useful use-cases with strings as well, but then compaction would have to decide whether to produce a string or a number (at least when the value can be parsed as a number)The text was updated successfully, but these errors were encountered: