- From: Melvin Carvalho <melvincarvalho@gmail.com>
- Date: Fri, 17 Oct 2014 17:04:12 +0200
- To: Markus Lanthaler <markus.lanthaler@gmx.net>
- Cc: "public-rdfjs@w3.org" <public-rdfjs@w3.org>
- Message-ID: <CAKaEYhJqCbJoG-rNTSZxASzb7RecEdV9U5pjFTw=PAmmmxcV5Q@mail.gmail.com>
On 17 October 2014 16:45, Markus Lanthaler <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. > > > HTH, > Markus > > > [1] http://json-ld.org/spec/latest/rdf-graph-normalization/ > > > -- > Markus Lanthaler > @markuslanthaler > > > > >
Received on Friday, 17 October 2014 15:04:41 UTC