- From: Pierre-Antoine Champin <pierre-antoine@w3.org>
- Date: Fri, 25 Nov 2022 16:38:17 +0100
- To: Paul Tyson <phtyson@sbcglobal.net>
- Cc: public-json-ld@w3.org
- Message-ID: <af727dbb-15c6-89dd-daad-d56a69db30a5@w3.org>
Dear Paul, chiming in a little late, On 17/11/2022 16:33, Paul Tyson wrote: > > Thank you all for suggestions, but as Vladimir said, I must > distinguish by value not context. > > The specific use case is SHACL, and the property is sh:hasValue. The > focus node being validated can have any datatype. If I'm expecting a > non-native JSON value, the shape would have to written with a local > type declaration, like: > > "sh:property": { > "sh:path": "ex:foo", > "sh:hasValue": {"@type": "http://example.org/yugo"} > } > > This is inconvenient, and not suitable for applying a context to a > given json payload. > > I wonder if the WG would consider an extension to the @type syntax, > allowing a list of coercion types to try, so one could write a term > expansion in the context like: > > > "sh:hasValue": { > "@type": ["@id","xsd:dateTime"] > } > > If none of these coercions work, > JSON-LD processors have no notion of a coercion "working" or "failing". They just take the value of `@type` and stick it as the datatype of the literal. Simple. If the value in the data is not a valid lexical value for that datatype, then the JSON-LD processor will produce an ill-formed literal. Garbage in, garbage out... Arguably, it would be nice if JSON-LD processors were smarter... but they are already very complex. Coming back to your original example, an alternative is to disambiguate the value type with the property name -- nothing prevents you from having different JSON keys map to the same IRI, but with different parameters for type coercion. Example (also on the playground: https://tinyurl.com/327x2jpz ): { "@context": { "ex": "http://example.org/ns/", "foo": "ex:foo", "foo_id": { "@id": "ex:foo", "@type": "@id"}, "foo_dt": { "@id": "ex:foo", "@type": "ex:dateTime"} }, "ex:thing1": {"foo": 1}, "ex:thing2": {"foo": "a string"}, "ex:thing3": {"foo_id": "http://example.org/yugo"}, "ex:thing4": {"foo_dt": "2022-11-16T21:04:41"} } Granted, this is more demanding to the user, but that is more "JSONy" than requiring explicit node object or value objects as the values of "foo". NB: this is a frequent pattern for generating language-tagged strings in different languages : https://www.w3.org/TR/json-ld11/#example-70-expanded-term-definition-with-language best > use the best native JSON type conversion. If the context author wants > to limit the coercion attempts to just those named, a final token > could be added to the list, such as an empty string. In that case, if > no type coercion succeeded, an error would be thrown. > > Regards, > --Paul > > On 11/17/22 09:07, Vladimir Alexiev wrote: >> Thanks Roman! Good trick. >> I've used nested contexts in EPCIS 2, but scoped by class. >> >> That assumes ex:thing4/ex:foo is consistently always the same kind of >> literal. >> The way I understood Paul is that ex:foo is to be distinguished by >> value, not by place of use (context). >> >> On Thu, Nov 17, 2022 at 4:24 PM Roman Evstifeev >> <someuniquename@gmail.com> wrote: >> >> On Thu, 17 Nov 2022 at 06:24, Paul Tyson <phtyson@sbcglobal.net> >> wrote: >> > >> > I have a property that can take any type of RDF term as a value. >> > >> > { >> > "@context": { >> > "ex": "http://example.org/ns/", >> > }, >> > "ex:thing1": {"ex:foo": 1}, >> > "ex:thing2": {"ex:foo": "a string"}, >> > "ex:thing3": {"ex:foo": "http://example.org/yugo"} >> > "ex:thing4": {"ex:foo": "2022-11-16T21:04:41"} >> > } >> > >> > Is there any way to construct the context to make this come out >> in RDF like: >> > >> > _:b0 <http://example.org/ns/thing1> _:b1 . >> > _:b0 <http://example.org/ns/thing2> _:b2 . >> > _:b0 <http://example.org/ns/thing3> _:b3 . >> > _:b0 <http://example.org/ns/thing4> _:b4 . >> > _:b1 <http://example.org/ns/foo> >> > "1"^^<http://www.w3.org/2001/XMLSchema#integer> . >> > _:b2 <http://example.org/ns/foo> "a string" . >> > _:b3 <http://example.org/ns/foo> <http://example.org/yugo> . >> > _:b4 <http://example.org/ns/foo> >> > >> "2022-11-16T21:04:41"^^<http://www.w3.org/2001/XMLSchema#dateTime> . >> > >> > Thanks and regards, >> > --Paul >> > >> > >> >> You can use property-scoped context: >> >> { >> "@context": { >> "ex": "http://example.org/ns/", >> "xsd": "http://www.w3.org/2001/XMLSchema#", >> "ex:thing3": { >> "@context": { >> "ex:foo": { >> "@type": "@id" >> } >> } >> }, >> "ex:thing4": { >> "@context": { >> "ex:foo": { >> "@type": "xsd:dateTime" >> } >> } >> } >> >> }, >> "ex:thing1": {"ex:foo": 1}, >> "ex:thing2": {"ex:foo": "a string"}, >> "ex:thing3": {"ex:foo": "http://example.org/yugo"}, >> "ex:thing4": {"ex:foo": "2022-11-16T21:04:41"} >> } >> >> json-ld playground: https://tinyurl.com/dwpf68db >>
Attachments
- application/pgp-keys attachment: OpenPGP public key
Received on Friday, 25 November 2022 15:38:21 UTC