Skip to content

Commit 743598f

Browse files
committed
Limits ordering logic to JsonLdApi.FromRdf
1 parent 058d7e1 commit 743598f

28 files changed

+220
-2538
lines changed

src/json-ld.net/Core/JsonLdApi.cs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ public virtual JToken Compact(Context activeCtx, string activeProperty, JToken e
123123
// 7)
124124
JArray keys = new JArray(element.GetKeys());
125125

126-
//if (opts.GetSortGraphNodes())
127-
{
128-
keys.SortInPlace();
129-
}
126+
keys.SortInPlace();
130127

131128
foreach (string expandedProperty in keys)
132129
{
@@ -496,10 +493,7 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
496493
// 7)
497494
JArray keys = new JArray(element.GetKeys());
498495

499-
//if (opts.GetSortGraphNodes())
500-
{
501-
keys.SortInPlace();
502-
}
496+
keys.SortInPlace();
503497

504498
foreach (string key in keys)
505499
{
@@ -818,10 +812,7 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
818812
// 7.6.2)
819813
JArray indexKeys = new JArray(value.GetKeys());
820814

821-
//if (opts.GetSortGraphNodes())
822-
{
823-
indexKeys.SortInPlace();
824-
}
815+
indexKeys.SortInPlace();
825816

826817
foreach (string index in indexKeys)
827818
{
@@ -1305,10 +1296,7 @@ private void GenerateNodeMap(JToken element, JObject nodeMap,
13051296
// 6.11)
13061297
JArray keys = new JArray(element.GetKeys());
13071298

1308-
//if (!opts.GetSortGraphNodes())
1309-
{
1310-
keys.SortInPlace();
1311-
}
1299+
keys.SortInPlace();
13121300

13131301
foreach (string property_1 in keys)
13141302
{
@@ -1456,10 +1444,7 @@ private void Frame(JsonLdApi.FramingContext state, JObject nodes
14561444
// add matches to output
14571445
JArray ids = new JArray(matches.GetKeys());
14581446

1459-
//if (!opts.GetSortGraphs())
1460-
{
1461-
ids.SortInPlace();
1462-
}
1447+
ids.SortInPlace();
14631448

14641449
foreach (string id in ids)
14651450
{
@@ -1524,10 +1509,7 @@ private void Frame(JsonLdApi.FramingContext state, JObject nodes
15241509
JObject element = (JObject)matches[id];
15251510
JArray props = new JArray(element.GetKeys());
15261511

1527-
//if (!opts.GetSortGraphNodes())
1528-
{
1529-
props.SortInPlace();
1530-
}
1512+
props.SortInPlace();
15311513

15321514
foreach (string prop in props)
15331515
{
@@ -1606,10 +1588,7 @@ private void Frame(JsonLdApi.FramingContext state, JObject nodes
16061588
// handle defaults
16071589
props = new JArray(frame.GetKeys());
16081590

1609-
//if (!opts.GetSortGraphNodes())
1610-
{
1611-
props.SortInPlace();
1612-
}
1591+
props.SortInPlace();
16131592

16141593
foreach (string prop_1 in props)
16151594
{
@@ -2151,7 +2130,7 @@ public virtual JArray FromRDF(RDFDataset dataset)
21512130
// 6)
21522131
JArray ids = new JArray(defaultGraph.GetKeys());
21532132

2154-
if (!opts.GetSortGraphs())
2133+
if (opts.GetSortGraphsFromRdf())
21552134
{
21562135
ids.SortInPlace();
21572136
}
@@ -2167,7 +2146,7 @@ public virtual JArray FromRDF(RDFDataset dataset)
21672146
// 6.1.2)
21682147
JArray keys = new JArray(graphMap[subject_1].GetKeys());
21692148

2170-
if (!opts.GetSortGraphNodes())
2149+
if (opts.GetSortGraphNodesFromRdf())
21712150
{
21722151
keys.SortInPlace();
21732152
}

src/json-ld.net/Core/JsonLdOptions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public virtual JsonLD.Core.JsonLdOptions Clone()
4242

4343
private bool produceGeneralizedRdf = false;
4444

45-
private bool sortGraphs = true;
45+
private bool sortGraphsFromRdf = true;
4646

47-
private bool sortGraphNodes = true;
47+
private bool sortGraphNodesFromRdf = true;
4848
// base options
4949
// frame options
5050
// rdf conversion options
@@ -149,24 +149,24 @@ public virtual void SetProduceGeneralizedRdf(bool produceGeneralizedRdf)
149149
this.produceGeneralizedRdf = produceGeneralizedRdf;
150150
}
151151

152-
public virtual bool GetSortGraphs()
152+
public virtual bool GetSortGraphsFromRdf()
153153
{
154-
return sortGraphs;
154+
return sortGraphsFromRdf;
155155
}
156156

157-
public virtual void SetSortGraphs(bool sortGraphs)
157+
public virtual void SetSortGraphsFromRdf(bool sortGraphs)
158158
{
159-
this.sortGraphs = sortGraphs;
159+
this.sortGraphsFromRdf = sortGraphs;
160160
}
161161

162-
public virtual bool GetSortGraphNodes()
162+
public virtual bool GetSortGraphNodesFromRdf()
163163
{
164-
return sortGraphNodes;
164+
return sortGraphNodesFromRdf;
165165
}
166166

167-
public virtual void SetSortGraphNodes(bool sortGraphNodes)
167+
public virtual void SetSortGraphNodesFromRdf(bool sortGraphNodes)
168168
{
169-
this.sortGraphNodes = sortGraphNodes;
169+
this.sortGraphNodesFromRdf = sortGraphNodes;
170170
}
171171
public string format = null;
172172

src/json-ld.net/Core/NormalizeUtils.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ public virtual object HashBlankNodes(IEnumerable<string> unnamed_)
4646
bool named = false;
4747
IList<string> hashes = new List<string>(unique.Keys);
4848

49-
//if (!options.GetSortGraphs())
50-
{
51-
hashes.SortInPlace();
52-
}
49+
hashes.SortInPlace();
5350

5451
foreach (string hash in hashes)
5552
{
@@ -79,10 +76,7 @@ public virtual object HashBlankNodes(IEnumerable<string> unnamed_)
7976
// enumerate duplicate hash groups in sorted order
8077
hashes = new List<string>(duplicates.Keys);
8178

82-
//if (!options.GetSortGraphs())
83-
{
84-
hashes.SortInPlace();
85-
}
79+
hashes.SortInPlace();
8680

8781
// process each group
8882
for (int pgi = 0; ; pgi++)
@@ -119,11 +113,8 @@ public virtual object HashBlankNodes(IEnumerable<string> unnamed_)
119113
) && !(quad["name"] == null) ? (string)((IDictionary<string,object>)((IDictionary<string,object>)quad)["name"])["value"] : null));
120114
}
121115

122-
//if (!options.GetSortGraphs())
123-
{
124-
// sort normalized output
125-
normalized.SortInPlace();
126-
}
116+
// sort normalized output
117+
normalized.SortInPlace();
127118

128119
// handle output format
129120
if (options.format != null)
@@ -156,11 +147,8 @@ public virtual object HashBlankNodes(IEnumerable<string> unnamed_)
156147
{
157148
if (n_2 == group.Count)
158149
{
159-
//if (!options.GetSortGraphs())
160-
{
161-
// name bnodes in hash order
162-
results.SortInPlace(new _IComparer_145());
163-
}
150+
// name bnodes in hash order
151+
results.SortInPlace(new _IComparer_145());
164152

165153
foreach (NormalizeUtils.HashResult r in results)
166154
{
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"@context": {
3+
}
4+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
[
2+
{
3+
"@id": "http://example.org/node/3",
4+
"@graph": [
5+
{
6+
"@id": "http://example.org/object/3",
7+
"http://example.org/value": [
8+
{
9+
"@id": "n3-o3-value"
10+
}
11+
]
12+
},
13+
{
14+
"@id": "http://example.org/object/1",
15+
"http://example.org/value": [
16+
{
17+
"@id": "n3-o1-value"
18+
}
19+
]
20+
},
21+
{
22+
"@id": "http://example.org/object/2",
23+
"http://example.org/value": [
24+
{
25+
"@id": "n3-o2-value"
26+
}
27+
]
28+
}
29+
]
30+
},
31+
{
32+
"@id": "http://example.org/node/1",
33+
"@graph": [
34+
{
35+
"@id": "http://example.org/object/3",
36+
"http://example.org/value": [
37+
{
38+
"@id": "n1-o3-value"
39+
}
40+
]
41+
},
42+
{
43+
"@id": "http://example.org/object/1",
44+
"http://example.org/value": [
45+
{
46+
"@id": "n1-o1-value"
47+
}
48+
]
49+
},
50+
{
51+
"@id": "http://example.org/object/2",
52+
"http://example.org/value": [
53+
{
54+
"@id": "n1-o2-value"
55+
}
56+
]
57+
}
58+
]
59+
},
60+
{
61+
"@id": "http://example.org/node/2",
62+
"@graph": [
63+
{
64+
"@id": "http://example.org/object/3",
65+
"http://example.org/value": [
66+
{
67+
"@id": "n2-o3-value"
68+
}
69+
]
70+
},
71+
{
72+
"@id": "http://example.org/object/1",
73+
"http://example.org/value": [
74+
{
75+
"@id": "n2-o1-value"
76+
}
77+
]
78+
},
79+
{
80+
"@id": "http://example.org/object/2",
81+
"http://example.org/value": [
82+
{
83+
"@id": "n2-o2-value"
84+
}
85+
]
86+
}
87+
]
88+
}
89+
]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"@type": "mf:Manifest",
3+
"name": "Compaction",
4+
"description": "JSON-LD sorting graphs and nodes when running Compact",
5+
"test-context": "compact-context.jsonld",
6+
"input": "compact-in.jsonld",
7+
"sequence": [
8+
{
9+
"@id": "#t0001",
10+
"sort-type": "jld:GraphsAndNodes",
11+
"test-type": "jld:Compact",
12+
"name": "sort graphs and nodes",
13+
"purpose": "graphs and nodes sorted when running Compact",
14+
"expect": "compact-out-sort-graphs-and-nodes.jsonld"
15+
},
16+
{
17+
"@id": "#t0002",
18+
"sort-type": "jld:Graphs",
19+
"test-type": "jld:Compact",
20+
"name": "sort graphs only",
21+
"purpose": "graphs sorted when running Compact",
22+
"expect": "compact-out-sort-graphs.jsonld"
23+
},
24+
{
25+
"@id": "#t0003",
26+
"sort-type": "jld:Nodes",
27+
"test-type": "jld:Compact",
28+
"name": "sort graph nodes only",
29+
"purpose": "graph nodes sorted when running Compact",
30+
"expect": "compact-out-sort-graph-nodes.jsonld"
31+
},
32+
{
33+
"@id": "#t0004",
34+
"sort-type": "jld:None",
35+
"test-type": "jld:Compact",
36+
"name": "sort nothing",
37+
"purpose": "sort nothing running Compact",
38+
"expect": "compact-out-no-sorting.jsonld"
39+
}
40+
]
41+
}

test/json-ld.net.tests/Sorting/W3C/expand-0002-in.jsonld

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/json-ld.net.tests/Sorting/W3C/expand-0002-out.jsonld

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)