- From: ☮ elf Pavlik ☮ <perpetual-tripper@wwelves.org>
- Date: Sun, 19 Oct 2014 11:27:23 +0200
- To: Melvin Carvalho <melvincarvalho@gmail.com>
- CC: "public-rdfjs@w3.org" <public-rdfjs@w3.org>
On 10/17/2014 05:04 PM, Melvin Carvalho wrote:
>
>
> On 17 October 2014 16:45, Markus Lanthaler <markus.lanthaler@gmx.net
> <mailto:markus.lanthaler@gmx.net>> wrote:
>
> On 17 Okt 2014 at 15:35, ☮ elf Pavlik ☮ wrote:
> > Any recommendations for quick way of comparing, for now just equality,
> > graphs serialized in JSON-LD and Turtle?
>
> It depends on whether you have blank nodes in the document or not.
> If you don't simply convert it to N-Triples, sort the triples and do
> a string comparison.
>
>
> Yes, you have to do this in a certain way. Remove all whitespace and
> have exactly one space between the object an the .
>
>
>
> If you do have blank nodes, it becomes a bit more complex as you
> need to ensure that the bnodes get assigned the same bnode
> identifiers. We have been working on a graph normalization algorithm
> in the JSON-LD CG [1]. Luckily, jsonld.js implements this algorithm
> (also the JSON-LD playground supports it, just click on the
> normalize tab). After normalizing both graphs it is trivial to
> compare them.
>
>
> In node try something like:
>
> var jsonld = require('jsonld');
>
> jsonld.normalize(doc, {format: 'application/nquads'}, function(err, normalized) {
>
> // do something here
>
>
> });
>
> What I commonly do with a normalized doc is take the sha256 and use that for the @id. In this way you can compare ID's and know that the data is the same.
cool! i don't currently see need for it in testing since i can just
compare stings of full serializations
on the other hand it might come super handy for revisions in levelgraph!
Received on Sunday, 19 October 2014 09:29:32 UTC