digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.66k stars 195 forks source link

Adds preserve order logic for fromRdf and test case #396

Open dnllowe opened 4 years ago

dnllowe commented 4 years ago

For issue 395 (Preserving order of parent nodes and property nodes)

I was previously working with a team that needed to preserve the order of parent and child nodes when created from RDF.

For example, given the quads below, we'd want to control whether subjects 1, 2, and 3 get sorted, and whether their children (properties 1, 2, and 3) are sorted. As of now, fromRdf will always sort the parent nodes and children (Subject 1, Properties 1,2,3; Subject 2, Properties 1,2,3 etc...), losing the original order:

<http://example.com/Subject3/Property3> <http://example.com/value> "3" <http://example.com/Subject3> .
<http://example.com/Subject3/Property1> <http://example.com/value> "1" <http://example.com/Subject3> .
<http://example.com/Subject3/Property2> <http://example.com/value> "2" <http://example.com/Subject3> .

<http://example.com/Subject1/Property3> <http://example.com/value> "3" <http://example.com/Subject1> .
<http://example.com/Subject1/Property1> <http://example.com/value> "1" <http://example.com/Subject1> .
<http://example.com/Subject1/Property2> <http://example.com/value> "2" <http://example.com/Subject1> .

<http://example.com/Subject2/Property3> <http://example.com/value> "3" <http://example.com/Subject2> .
<http://example.com/Subject2/Property1> <http://example.com/value> "1" <http://example.com/Subject2> .
<http://example.com/Subject2/Property2> <http://example.com/value> "2" <http://example.com/Subject2> .

The codebase was .NET, so the team was using the linked-data-dotnet/json-ld.net package. Ultimately, we forked our changes from that package, but I'd like to merge those changes into both the .NET library and the node library.