Re: Handling integers

Hey Angelo,

Would you mind creating an example of what you're doing on https://glitch.com/ (or similar)?

We might also want to loop in the RDF.js folks as this seems like a limitation with their tooling and not with JSON-LD syntax or API.

Cheers,
Benjamin


--

http://bigbluehat.com/

http://linkedin.com/in/benjaminyoung

________________________________
From: Angelo Veltens <angelo.veltens@online.de>
Sent: Friday, November 15, 2019 12:06 PM
To: Dave Longley <dlongley@digitalbazaar.com>; public-linked-json@w3.org <public-linked-json@w3.org>; Benjamin Young <byoung@bigbluehat.com>
Subject: Re: Handling integers

Thanks Dave and Robert,

I did not use useNativeTypes since I am not using jsonld.fromRDF, but
rdfjs-base/serializer-jsonld[1], which does not seem to have such an option.

I guess support for the flag could at least be added to
rdfjs-base/serializer-jsonld-ext[2] so this is a helpful hint, indeed.

I will have to dive back into the topic when I find time. Thanks a lot
for now!

[1] https://github.com/rdfjs-base/serializer-jsonld
[2] https://github.com/rdfjs-base/serializer-jsonld-ext

Kind regards,
Angelo

On 15.11.19 17:27, Dave Longley wrote:
>
> Angelo,
>
> The following gist may do what you want:
>
> https://gist.github.com/dlongley/92b76fb43039893091a5a3b6a3b6aa9e
>
> There is a flag when converting from RDF called `useNativeTypes` that
> will parse well-known XSD types (such as `xsd:integer`) into JSON native
> types. Then you can compact to your context and get the output you want.
>
> If you don't want that blank node ID to appear, you can use framing to
> prune blank node IDs. If don't care about that or if your data has IDs
> this is a non-issue. Note that jsonld.js will also presently insert
> `@graph` into the framing output, but this will be changed as soon as
> jsonld.js is updated to the JSON-LD 1.1 algorithms.
>
> Is this the sort of thing you're looking for?
>
> On 11/15/19 11:02 AM, Angelo Veltens wrote:
>> Hi Benjamin,
>>
>> thanks for your explanation. I appreciate any response even though
>> it's late, no problem :)
>>
>> The big benefit I see in JSON-LD, is that it really simplifies the
>> usage of RDF in JavaScript applications, as in many cases an RDF
>> graph can be compacted to a plain and simple JSON object. Of course
>> there are always graphs that get more complicated, like when it
>> contains multiple languages or non primitive types. But in my
>> experience many, many practical cases can be serialized to a
>> simple-to-use JSON object.
>>
>> This is why I find it very annoying to get
>>
>> "age": {
>>      "@value": "27",
>>      "@type": "http://www.w3.org/2001/XMLSchema#integer"
>>    }
>>
>> when one could also use a simple
>>
>> "age": 27
>>
>> This is just making things more complicated without necessity.
>>
>> This way, JSON-LD is just yet-another-RFD-serialization and looses
>> it's benefits in my opinion.
>>
>> Although I understand your conclusion, this is my input/feedback from
>> a practicability point-of-view.
>>
>> Kind regards,
>> Angelo
>>
>> On 04.10.19 17:41, Benjamin Young wrote:
>>> Hey Angelo,
>>>
>>> Sorry I missed this email back in...May. ;-P
>>>
>>> I wondered very similar things, and we discussed them a bit in the
>>> JSON-LD WG recently:
>>> https://github.com/w3c/json-ld-bp/issues/14
>>>
>>> The ultimate conclusion is that JSON-LD does one thing: encodes a
>>> graph in JSON by mapping local names to global names (and wrangling
>>> various JSON shapes into graphy ones).
>>>
>>> So, essentially type casting of this sort, isn't JSON-LD's job...but
>>> a tool that uses the expanded form (for instance) might be able to
>>> clean-up data on ingest or generation.
>>>
>>> Here's how I summarized it in the issue:
>>> https://github.com/w3c/json-ld-bp/issues/14#issuecomment-532125931
>>>
>>> Ultimately we plan to explain that in the forthcoming Best Practices
>>> guide. As someone else who's shared this confusion, your input here
>>> would be most welcome. :)
>>>
>>> Cheers,
>>> Benjamin
>>> Co-Chair, W3C JSON-LD
>>>
>>> --
>>>
>>> http://bigbluehat.com/
>>>
>>> http://linkedin.com/in/benjaminyoung
>>>
>>> ------------------------------------------------------------------------
>>>
>>> *From:* Angelo Veltens <angelo.veltens@online.de>
>>> *Sent:* Friday, May 31, 2019 4:46 AM
>>> *To:* JSON-LD CG <public-linked-json@w3.org>
>>> *Subject:* Handling integers
>>> Hi everybody,
>>>
>>> Question regarding Integers in JSON-LD.
>>>
>>> Given the following snippet:
>>>
>>> {
>>>   "@context": {
>>>     "@vocab": "http://vocab.example/"
>>>   },
>>>   "age": {
>>>     "@value": "27",
>>>     "@type": "http://www.w3.org/2001/XMLSchema#integer"
>>>   }
>>> }
>>>
>>> Is there a JSON-LD algorithm / context to transform it to a real JSON
>>> integer?
>>>
>>> {
>>>   "@context": {
>>>     "@vocab": "http://vocab.example/"
>>>   },
>>>   "age": 27
>>> }
>>>
>>> They are semantically the same, but the upper construct is much more
>>> complicated to handle in JavaScript application and does not give any
>>> additional value. I would have expected at least the compact algorithm
>>> to output the latter construct.
>>>
>>> All the best,
>>> Angelo
>>>
>
>

Received on Friday, 15 November 2019 19:46:45 UTC