Skip to content

Commit d0c5cfc

Browse files
committed
updated new tests and fixed core to match spec changes.
1 parent 85e52e6 commit d0c5cfc

20 files changed

Lines changed: 170 additions & 44 deletions

core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ void generateNodeMap(Object element, Map<String, Object> nodeMap, String activeG
901901
}
902902

903903
void generateNodeMap(Object element, Map<String, Object> nodeMap, String activeGraph,
904-
String activeSubject, String activeProperty, Map<String, Object> list)
904+
Object activeSubject, String activeProperty, Map<String, Object> list)
905905
throws JsonLdError {
906906
// 1)
907907
if (element instanceof List) {
@@ -966,9 +966,10 @@ else if (elem.containsKey("@list")) {
966966
final Map<String, Object> result = new LinkedHashMap<String, Object>();
967967
result.put("@list", new ArrayList<Object>());
968968
// 5.2)
969-
for (final Object item : (List<Object>) elem.get("@list")) {
970-
generateNodeMap(item, nodeMap, activeGraph, activeSubject, activeProperty, result);
971-
}
969+
//for (final Object item : (List<Object>) elem.get("@list")) {
970+
// generateNodeMap(item, nodeMap, activeGraph, activeSubject, activeProperty, result);
971+
//}
972+
generateNodeMap(elem.get("@list"), nodeMap, activeGraph, activeSubject, activeProperty, result);
972973
// 5.3)
973974
JsonLdUtils.mergeValue(node, activeProperty, result);
974975
}
@@ -992,30 +993,37 @@ else if (elem.containsKey("@list")) {
992993
tmp.put("@id", id);
993994
graph.put(id, tmp);
994995
}
995-
// 6.4)
996-
if (activeProperty != null) {
996+
// 6.4) TODO: SPEC this line is asked for by the spec, but it breaks various tests
997+
//node = (Map<String, Object>) graph.get(id);
998+
// 6.5)
999+
if (activeSubject instanceof Map) {
1000+
// 6.5.1)
1001+
JsonLdUtils.mergeValue((Map<String, Object>) graph.get(id), activeProperty, activeSubject);
1002+
}
1003+
// 6.6)
1004+
else if (activeProperty != null) {
9971005
final Map<String, Object> reference = new LinkedHashMap<String, Object>();
9981006
reference.put("@id", id);
999-
// 6.4.2)
1007+
// 6.6.2)
10001008
if (list == null) {
1001-
// 6.4.2.1+2)
1009+
// 6.6.2.1+2)
10021010
JsonLdUtils.mergeValue(node, activeProperty, reference);
10031011
}
1004-
// 6.4.3) TODO: SPEC says to add ELEMENT to @list member, should
1012+
// 6.6.3) TODO: SPEC says to add ELEMENT to @list member, should
10051013
// be REFERENCE
10061014
else {
10071015
JsonLdUtils.mergeValue(list, "@list", reference);
10081016
}
10091017
}
1010-
// 6.5)
1018+
// TODO: SPEC this is removed in the spec now, but it's still needed (see 6.4)
10111019
node = (Map<String, Object>) graph.get(id);
1012-
// 6.6)
1020+
// 6.7)
10131021
if (elem.containsKey("@type")) {
10141022
for (final Object type : (List<Object>) elem.remove("@type")) {
10151023
JsonLdUtils.mergeValue(node, "@type", type);
10161024
}
10171025
}
1018-
// 6.7)
1026+
// 6.8)
10191027
if (elem.containsKey("@index")) {
10201028
final Object elemIndex = elem.remove("@index");
10211029
if (node.containsKey("@index")) {
@@ -1026,49 +1034,42 @@ else if (elem.containsKey("@list")) {
10261034
node.put("@index", elemIndex);
10271035
}
10281036
}
1029-
// 6.8)
1037+
// 6.9)
10301038
if (elem.containsKey("@reverse")) {
1031-
// 6.8.2+6.8.4)
1039+
// 6.9.1)
1040+
final Map<String, Object> referencedNode = new LinkedHashMap<String, Object>();
1041+
referencedNode.put("@id", id);
1042+
// 6.9.2+6.9.4)
10321043
final Map<String, Object> reverseMap = (Map<String, Object>) elem
10331044
.remove("@reverse");
1034-
// 6.8.3)
1045+
// 6.9.3)
10351046
for (final String property : reverseMap.keySet()) {
10361047
final List<Object> values = (List<Object>) reverseMap.get(property);
1037-
// 6.8.3.1)
1048+
// 6.9.3.1)
10381049
for (final Object value : values) {
1039-
// 6.8.1) TODO: SPEC for pass by reference languages,
1040-
// referencedNode needs to be recreated for each loop,
1041-
// otherwise the @id member gets removed inside the
1042-
// generateNodeMap call and screws things up for
1043-
// subsequent calls
1044-
final Map<String, Object> referencedNode = new LinkedHashMap<String, Object>();
1045-
referencedNode.put("@id", id);
1046-
// 6.8.3.1.1)
1047-
JsonLdUtils.mergeValue((Map<String, Object>) value, property,
1048-
referencedNode);
1049-
// 6.8.3.1.2)
1050-
generateNodeMap(value, nodeMap, activeGraph, null, null, null);
1050+
// 6.9.3.1.1)
1051+
generateNodeMap(value, nodeMap, activeGraph, referencedNode, property, null);
10511052
}
10521053
}
10531054
}
1054-
// 6.9)
1055+
// 6.10)
10551056
if (elem.containsKey("@graph")) {
10561057
generateNodeMap(elem.remove("@graph"), nodeMap, id, null, null, null);
10571058
}
1058-
// 6.10)
1059+
// 6.11)
10591060
final List<String> keys = new ArrayList<String>(elem.keySet());
10601061
Collections.sort(keys);
10611062
for (String property : keys) {
10621063
final Object value = elem.get(property);
1063-
// 6.10.1)
1064+
// 6.11.1)
10641065
if (property.startsWith("_:")) {
10651066
property = generateBlankNodeIdentifier(property);
10661067
}
1067-
// 6.10.2)
1068+
// 6.11.2)
10681069
if (!node.containsKey(property)) {
10691070
node.put(property, new ArrayList<Object>());
10701071
}
1071-
// 6.10.3)
1072+
// 6.11.3)
10721073
generateNodeMap(value, nodeMap, activeGraph, id, property, null);
10731074
}
10741075
}

core/src/test/java/com/github/jsonldjava/core/JsonLdProcessorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ public void addHttpLink(String nextLink) {
318318
}
319319
}
320320

321-
@Rule
322-
public Timeout timeout = new Timeout(10000);
321+
//@Rule
322+
//public Timeout timeout = new Timeout(10000);
323323

324324
@Rule
325325
public TemporaryFolder tempDir = new TemporaryFolder();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"@context": {
3+
"foo": "http://example.com/foo"
4+
}
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"@context": [{
3+
"foo": "http://example.com/foo"
4+
}, {
5+
"bar": "http://example.com/bar"
6+
}],
7+
"foo": "foo-value",
8+
"bar": "bar-value"
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"@context": {
3+
"foo": "http://example.com/foo"
4+
},
5+
"foo": "foo-value",
6+
"http://example.com/bar": "bar-value"
7+
}

core/src/test/resources/json-ld.org/compact-manifest.jsonld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,14 @@
569569
"input": "compact-0070-in.jsonld",
570570
"context": "compact-0070-context.jsonld",
571571
"expect": "compact-0070-out.jsonld"
572+
}, {
573+
"@id": "#t0071",
574+
"@type": ["jld:PositiveEvaluationTest", "jld:CompactTest"],
575+
"name": "input has multiple @contexts, output has one",
576+
"purpose": "Expanding input with multiple @contexts and compacting with just one doesn't output undefined properties",
577+
"input": "compact-0071-in.jsonld",
578+
"context": "compact-0071-context.jsonld",
579+
"expect": "compact-0071-out.jsonld"
572580
}
573581
]
574582
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "json-ld/tests",
3+
"type": "library",
4+
"description": "The offical JSON-LD test suite",
5+
"keywords": [ "JSON-LD", "jsonld" ],
6+
"homepage": "http://json-ld.org/test-suite/",
7+
"license": "CC0-1.0",
8+
"authors": [
9+
{
10+
"name": "JSON-LD Community Group",
11+
"homepage": "http://json-ld.org/"
12+
}
13+
],
14+
"support": {
15+
"email": "public-linked-json@w3.org",
16+
"irc": "irc://irc.freenode.org/json-ld",
17+
"source": "https://github.com/json-ld/json-ld.org/",
18+
"issues": "https://github.com/json-ld/json-ld.org/issues"
19+
}
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"@context": {
3+
"foo": "http://example.org/foo",
4+
"bar": { "@reverse": "http://example.org/bar", "@type": "@id" }
5+
},
6+
"foo": "Foo",
7+
"bar": [ "http://example.org/origin", "_:b0" ]
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"@id": "_:b0",
4+
"http://example.org/foo": [ { "@value": "Foo" } ]
5+
},
6+
{
7+
"@id": "_:b1",
8+
"http://example.org/bar": [ { "@id": "_:b0" } ]
9+
},
10+
{
11+
"@id": "http://example.org/origin",
12+
"http://example.org/bar": [ { "@id": "_:b0" } ]
13+
}
14+
]

core/src/test/resources/json-ld.org/flatten-manifest.jsonld

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@
318318
"input": "flatten-0044-in.jsonld",
319319
"context": "flatten-0044-context.jsonld",
320320
"expect": "flatten-0044-out.jsonld"
321+
}, {
322+
"@id": "#t0045",
323+
"@type": ["jld:PositiveEvaluationTest", "jld:FlattenTest"],
324+
"name": "Blank nodes with reverse properties",
325+
"purpose": "Proper (re-)labeling of blank nodes if used with reverse properties.",
326+
"input": "flatten-0045-in.jsonld",
327+
"expect": "flatten-0045-out.jsonld"
321328
}
322329
]
323330
}

0 commit comments

Comments
 (0)