From 3a63d911734ecc4b6ec0e01f3757f022791c9816 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Fri, 25 Oct 2019 13:59:19 +0200 Subject: [PATCH 1/7] Handle `@version` context entries --- core/reports/json-ld-api-tests-skip | 24 ------------------- .../com/github/jsonldjava/core/Context.java | 14 ++++++++++- .../github/jsonldjava/core/JsonLdConsts.java | 1 + .../github/jsonldjava/core/JsonLdError.java | 4 ++++ .../github/jsonldjava/core/JsonLdOptions.java | 2 +- 5 files changed, 19 insertions(+), 26 deletions(-) diff --git a/core/reports/json-ld-api-tests-skip b/core/reports/json-ld-api-tests-skip index 911bf5a6..127fc0db 100644 --- a/core/reports/json-ld-api-tests-skip +++ b/core/reports/json-ld-api-tests-skip @@ -56,11 +56,9 @@ https://w3c.github.io/json-ld-api/tests/compact-manifest#tc023 https://w3c.github.io/json-ld-api/tests/compact-manifest#tc024 https://w3c.github.io/json-ld-api/tests/compact-manifest#tc025 https://w3c.github.io/json-ld-api/tests/compact-manifest#tc026 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tc027 https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi01 https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi02 https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi03 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi04 https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi05 https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi06 https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi07 @@ -193,8 +191,6 @@ https://w3c.github.io/json-ld-api/tests/expand-manifest#t0122 https://w3c.github.io/json-ld-api/tests/expand-manifest#t0123 https://w3c.github.io/json-ld-api/tests/expand-manifest#t0124 https://w3c.github.io/json-ld-api/tests/expand-manifest#t0125 -https://w3c.github.io/json-ld-api/tests/expand-manifest#t0126 -https://w3c.github.io/json-ld-api/tests/expand-manifest#t0127 https://w3c.github.io/json-ld-api/tests/expand-manifest#t0128 https://w3c.github.io/json-ld-api/tests/expand-manifest#tc001 https://w3c.github.io/json-ld-api/tests/expand-manifest#tc002 @@ -221,7 +217,6 @@ https://w3c.github.io/json-ld-api/tests/expand-manifest#tc023 https://w3c.github.io/json-ld-api/tests/expand-manifest#tc024 https://w3c.github.io/json-ld-api/tests/expand-manifest#tc025 https://w3c.github.io/json-ld-api/tests/expand-manifest#tc026 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tc027 https://w3c.github.io/json-ld-api/tests/expand-manifest#tc028 https://w3c.github.io/json-ld-api/tests/expand-manifest#tc029 https://w3c.github.io/json-ld-api/tests/expand-manifest#tc030 @@ -371,10 +366,6 @@ https://w3c.github.io/json-ld-api/tests/expand-manifest#tn005 https://w3c.github.io/json-ld-api/tests/expand-manifest#tn006 https://w3c.github.io/json-ld-api/tests/expand-manifest#tn007 https://w3c.github.io/json-ld-api/tests/expand-manifest#tn008 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tp001 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tp002 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tp003 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tp004 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpi01 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpi02 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpi03 @@ -387,14 +378,12 @@ https://w3c.github.io/json-ld-api/tests/expand-manifest#tpi09 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpi10 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpi11 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr01 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr02 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr03 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr04 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr05 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr06 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr08 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr09 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr10 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr11 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr12 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr13 @@ -432,7 +421,6 @@ https://w3c.github.io/json-ld-api/tests/expand-manifest#tso05 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso06 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso07 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso08 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tso09 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso10 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso11 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso12 @@ -512,7 +500,6 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc023 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc024 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc025 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc026 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc027 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc028 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc029 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc030 @@ -522,9 +509,7 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc033 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc034 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi01 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi02 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi03 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi04 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi05 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi06 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi07 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi08 @@ -575,8 +560,6 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te122 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te123 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0124 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#t0125 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te126 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te127 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#te128 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tec01 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tec02 @@ -708,10 +691,6 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tn005 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tn006 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tn007 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tn008 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tp001 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tp002 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tp003 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tp004 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpi01 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpi02 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpi03 @@ -724,14 +703,12 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpi09 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpi10 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpi11 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr01 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr02 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr03 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr04 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr05 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr06 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr08 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr09 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr10 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr11 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr12 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr13 @@ -770,7 +747,6 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso05 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso06 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso07 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso08 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso09 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso10 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso11 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso12 diff --git a/core/src/main/java/com/github/jsonldjava/core/Context.java b/core/src/main/java/com/github/jsonldjava/core/Context.java index 8c149b08..979afe66 100644 --- a/core/src/main/java/com/github/jsonldjava/core/Context.java +++ b/core/src/main/java/com/github/jsonldjava/core/Context.java @@ -215,6 +215,18 @@ else if (context instanceof String) { // 3.3 throw new JsonLdError(Error.INVALID_LOCAL_CONTEXT, context); } + // 5.5 in 1.1 (https://w3c.github.io/json-ld-api/#context-processing-algorithm) + if (((Map) context).containsKey(JsonLdConsts.VERSION)) { + final Object version = ((Map) context).get(JsonLdConsts.VERSION); + // 5.5.1 + if(!version.equals(Double.valueOf(1.1))) { + throw new JsonLdError(Error.INVALID_VERSION_VALUE, context); + } + // 5.5.2 + if(options.getProcessingMode().equals(JsonLdOptions.JSON_LD_1_0)) { + throw new JsonLdError(Error.PROCESSING_MODE_CONFLICT, context); + } + } checkEmptyKey((Map) context); // 3.4 if (!parsingARemoteContext @@ -277,7 +289,7 @@ else if (context instanceof String) { final Map defined = new LinkedHashMap(); for (final String key : ((Map) context).keySet()) { if (JsonLdConsts.BASE.equals(key) || JsonLdConsts.VOCAB.equals(key) - || JsonLdConsts.LANGUAGE.equals(key)) { + || JsonLdConsts.LANGUAGE.equals(key) || JsonLdConsts.VERSION.equals(key)) { continue; } result.createTermDefinition((Map) context, key, defined); diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java index 9de5b76b..c16bba09 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java @@ -58,6 +58,7 @@ public final class JsonLdConsts { public static final String VOCAB = "@vocab"; public static final String BASE = "@base"; public static final String REQUIRE_ALL = "@requireAll"; + public static final String VERSION = "@version"; public enum Embed { ALWAYS, NEVER, LAST, LINK; diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java index 21ab5772..2e98bb90 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java @@ -102,6 +102,10 @@ public enum Error { INVALID_EMBED_VALUE("invalid @embed value"), + INVALID_VERSION_VALUE("invalid @version value"), + + PROCESSING_MODE_CONFLICT("processing mode conflict"), + // non spec related errors SYNTAX_ERROR("syntax error"), diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdOptions.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdOptions.java index dc139917..1786aae7 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdOptions.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdOptions.java @@ -87,7 +87,7 @@ public JsonLdOptions copy() { * http://www.w3.org/TR/json-ld-api/#widl-JsonLdOptions-processingMode * jsonld 1.1: https://www.w3.org/TR/json-ld11/#dfn-processing-mode */ - private String processingMode = JSON_LD_1_0; + private String processingMode = JSON_LD_1_1; /** * http://www.w3.org/TR/json-ld-api/#widl-JsonLdOptions-documentLoader */ From 5623b2826032086a6b58db3603a6285a5c771cca Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Tue, 29 Oct 2019 10:26:09 +0100 Subject: [PATCH 2/7] Include new keywords when skipping createTermDefinition --- core/reports/json-ld-api-tests-skip | 25 ------------------- .../com/github/jsonldjava/core/Context.java | 9 +++++-- .../github/jsonldjava/core/JsonLdConsts.java | 4 +++ 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/core/reports/json-ld-api-tests-skip b/core/reports/json-ld-api-tests-skip index 127fc0db..a3a2ad86 100644 --- a/core/reports/json-ld-api-tests-skip +++ b/core/reports/json-ld-api-tests-skip @@ -56,11 +56,8 @@ https://w3c.github.io/json-ld-api/tests/compact-manifest#tc023 https://w3c.github.io/json-ld-api/tests/compact-manifest#tc024 https://w3c.github.io/json-ld-api/tests/compact-manifest#tc025 https://w3c.github.io/json-ld-api/tests/compact-manifest#tc026 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi01 https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi02 https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi03 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi05 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi06 https://w3c.github.io/json-ld-api/tests/compact-manifest#tdi07 https://w3c.github.io/json-ld-api/tests/compact-manifest#te001 https://w3c.github.io/json-ld-api/tests/compact-manifest#te002 @@ -230,7 +227,6 @@ https://w3c.github.io/json-ld-api/tests/expand-manifest#tdi03 https://w3c.github.io/json-ld-api/tests/expand-manifest#tdi04 https://w3c.github.io/json-ld-api/tests/expand-manifest#tdi05 https://w3c.github.io/json-ld-api/tests/expand-manifest#tdi06 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tdi07 https://w3c.github.io/json-ld-api/tests/expand-manifest#tdi08 https://w3c.github.io/json-ld-api/tests/expand-manifest#tdi09 https://w3c.github.io/json-ld-api/tests/expand-manifest#tec01 @@ -386,9 +382,6 @@ https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr08 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr09 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr11 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr12 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr13 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr14 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr15 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr16 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr17 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr18 @@ -396,11 +389,8 @@ https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr19 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr20 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr21 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr22 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr23 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr24 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr25 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr26 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr27 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr28 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr29 https://w3c.github.io/json-ld-api/tests/expand-manifest#tpr30 @@ -420,9 +410,7 @@ https://w3c.github.io/json-ld-api/tests/expand-manifest#tso03 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso05 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso06 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso07 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tso08 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso10 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tso11 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso12 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso13 https://w3c.github.io/json-ld-api/tests/expand-manifest#ttn01 @@ -507,11 +495,6 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc031 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc032 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc033 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tc034 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi01 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi02 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi04 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi06 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi07 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi08 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi09 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi10 @@ -711,9 +694,6 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr08 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr09 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr11 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr12 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr13 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr14 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr15 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr16 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr17 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr18 @@ -721,11 +701,8 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr19 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr20 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr21 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr22 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr23 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr24 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr25 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr26 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr27 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr28 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr29 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tpr30 @@ -746,9 +723,7 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso03 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso05 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso06 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso07 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso08 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso10 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso11 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso12 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tso13 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#ttn01 diff --git a/core/src/main/java/com/github/jsonldjava/core/Context.java b/core/src/main/java/com/github/jsonldjava/core/Context.java index 979afe66..863fa5f0 100644 --- a/core/src/main/java/com/github/jsonldjava/core/Context.java +++ b/core/src/main/java/com/github/jsonldjava/core/Context.java @@ -4,6 +4,7 @@ import static com.github.jsonldjava.utils.Obj.newMap; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.LinkedHashMap; @@ -288,8 +289,12 @@ else if (context instanceof String) { // 3.7 final Map defined = new LinkedHashMap(); for (final String key : ((Map) context).keySet()) { - if (JsonLdConsts.BASE.equals(key) || JsonLdConsts.VOCAB.equals(key) - || JsonLdConsts.LANGUAGE.equals(key) || JsonLdConsts.VERSION.equals(key)) { + // jsonld 1.1: 5.13 in https://w3c.github.io/json-ld-api/#algorithm + if (Arrays + .asList(JsonLdConsts.BASE, JsonLdConsts.DIRECTION, JsonLdConsts.IMPORT, + JsonLdConsts.LANGUAGE, JsonLdConsts.PROPAGATE, + JsonLdConsts.PROTECTED, JsonLdConsts.VERSION, JsonLdConsts.VOCAB) + .contains(key)) { continue; } result.createTermDefinition((Map) context, key, defined); diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java index c16bba09..7773607c 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java @@ -59,6 +59,10 @@ public final class JsonLdConsts { public static final String BASE = "@base"; public static final String REQUIRE_ALL = "@requireAll"; public static final String VERSION = "@version"; + public static final String PROTECTED = "@protected"; + public static final String PROPAGATE = "@propagate"; + public static final String IMPORT = "@import"; + public static final String DIRECTION = "@direction"; public enum Embed { ALWAYS, NEVER, LAST, LINK; From d953a4fb787643e2a69762527fe7ef7bdf3c228e Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Tue, 29 Oct 2019 15:56:37 +0100 Subject: [PATCH 3/7] Support `@container` array syntax --- .../com/github/jsonldjava/core/Context.java | 51 ++++++++++++++++--- .../github/jsonldjava/core/JsonLdError.java | 2 +- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/github/jsonldjava/core/Context.java b/core/src/main/java/com/github/jsonldjava/core/Context.java index 863fa5f0..1f6fc5ac 100644 --- a/core/src/main/java/com/github/jsonldjava/core/Context.java +++ b/core/src/main/java/com/github/jsonldjava/core/Context.java @@ -10,6 +10,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import com.github.jsonldjava.core.JsonLdError.Error; import com.github.jsonldjava.utils.JsonLdUrl; @@ -413,13 +414,15 @@ private void createTermDefinition(Map context, String term, } definition.put(JsonLdConsts.ID, reverse); if (val.containsKey(JsonLdConsts.CONTAINER)) { - final String container = (String) val.get(JsonLdConsts.CONTAINER); + final Object containerObject = val.get(JsonLdConsts.CONTAINER); + final String container = selectContainer(checkValidContainerEntry(containerObject)); if (container == null || JsonLdConsts.SET.equals(container) || JsonLdConsts.INDEX.equals(container)) { definition.put(JsonLdConsts.CONTAINER, container); } else { throw new JsonLdError(Error.INVALID_REVERSE_PROPERTY, - "reverse properties only support set- and index-containers"); + "reverse properties only support set- and index-containers, but was: " + + containerObject); } } definition.put(JsonLdConsts.REVERSE, true); @@ -476,12 +479,16 @@ else if (term.indexOf(":") >= 0) { // 16) if (val.containsKey(JsonLdConsts.CONTAINER)) { - final String container = (String) val.get(JsonLdConsts.CONTAINER); - if (!JsonLdConsts.LIST.equals(container) && !JsonLdConsts.SET.equals(container) - && !JsonLdConsts.INDEX.equals(container) - && !JsonLdConsts.LANGUAGE.equals(container)) { + Object containerObject = val.get(JsonLdConsts.CONTAINER); + final List allContainers = checkValidContainerEntry(containerObject); + if (allContainers.isEmpty()) { + throw new JsonLdError(Error.INVALID_CONTAINER_MAPPING, containerObject); + } + String container = selectContainer(allContainers); + if (container == null) { throw new JsonLdError(Error.INVALID_CONTAINER_MAPPING, - "@container must be either @list, @set, @index, or @language"); + "@container must be either @list, @set, @index, or @language, but was: " + + allContainers); } definition.put(JsonLdConsts.CONTAINER, container); if (JsonLdConsts.TYPE.equals(term)) { @@ -507,6 +514,36 @@ else if (term.indexOf(":") >= 0) { defined.put(term, true); } + private String selectContainer(final List allContainers) { + Optional supportedContainer = allContainers.stream() + .filter(c -> Arrays.asList(JsonLdConsts.LIST, JsonLdConsts.SET, JsonLdConsts.INDEX, + JsonLdConsts.LANGUAGE, JsonLdConsts.GRAPH).contains(c)) + .findFirst(); + return (String) supportedContainer.orElse(null); + } + + // jsonld 1.1: 22.1 in + // https://w3c.github.io/json-ld-api/#create-term-definition + private List checkValidContainerEntry(final Object containerObject) { + List container = (List) (containerObject instanceof List ? containerObject + : Arrays.asList(containerObject)); + boolean anyOneOf = Arrays.asList(JsonLdConsts.GRAPH, JsonLdConsts.ID, JsonLdConsts.INDEX, + JsonLdConsts.LANGUAGE, JsonLdConsts.LIST, JsonLdConsts.SET, JsonLdConsts.TYPE) + .stream().anyMatch(v -> container.contains(v)) && container.size() == 1; + boolean graphWithOthers = container.contains(JsonLdConsts.GRAPH) + && (container.contains(JsonLdConsts.ID) || container.contains(JsonLdConsts.INDEX) + || container.contains(JsonLdConsts.SET)); + boolean setWithOthers = container.contains(JsonLdConsts.SET) + && Arrays + .asList(JsonLdConsts.INDEX, JsonLdConsts.ID, JsonLdConsts.TYPE, + JsonLdConsts.LANGUAGE) + .stream().anyMatch(v -> container.contains(v)); + if (anyOneOf || graphWithOthers || setWithOthers) { + return container; + } else + return Collections.emptyList(); + } + /** * IRI Expansion Algorithm * diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java index 2e98bb90..4ce6d681 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java @@ -109,7 +109,7 @@ public enum Error { // non spec related errors SYNTAX_ERROR("syntax error"), - NOT_IMPLEMENTED("not implemnted"), + NOT_IMPLEMENTED("not implemented"), UNKNOWN_FORMAT("unknown format"), From e316b1c2b5dd678287dbcbfea6ddc39e3d7c5b8f Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Fri, 29 Nov 2019 15:13:06 +0100 Subject: [PATCH 4/7] Support JSON literals --- core/reports/json-ld-api-tests-skip | 35 ------------------ .../com/github/jsonldjava/core/Context.java | 12 ++++--- .../com/github/jsonldjava/core/JsonLdApi.java | 36 +++++++++++++++++-- .../github/jsonldjava/core/JsonLdConsts.java | 2 ++ .../github/jsonldjava/core/JsonLdError.java | 2 ++ .../github/jsonldjava/core/JsonLdUtils.java | 4 ++- .../github/jsonldjava/core/RDFDataset.java | 29 +++++++++++++-- 7 files changed, 74 insertions(+), 46 deletions(-) diff --git a/core/reports/json-ld-api-tests-skip b/core/reports/json-ld-api-tests-skip index a3a2ad86..ffa4f259 100644 --- a/core/reports/json-ld-api-tests-skip +++ b/core/reports/json-ld-api-tests-skip @@ -78,16 +78,10 @@ https://w3c.github.io/json-ld-api/tests/compact-manifest#tin02 https://w3c.github.io/json-ld-api/tests/compact-manifest#tin03 https://w3c.github.io/json-ld-api/tests/compact-manifest#tin04 https://w3c.github.io/json-ld-api/tests/compact-manifest#tin05 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs01 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs02 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs03 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs04 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs05 https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs06 https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs07 https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs08 https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs09 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs10 https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs11 https://w3c.github.io/json-ld-api/tests/compact-manifest#tli01 https://w3c.github.io/json-ld-api/tests/compact-manifest#tli02 @@ -300,27 +294,10 @@ https://w3c.github.io/json-ld-api/tests/expand-manifest#tin06 https://w3c.github.io/json-ld-api/tests/expand-manifest#tin07 https://w3c.github.io/json-ld-api/tests/expand-manifest#tin08 https://w3c.github.io/json-ld-api/tests/expand-manifest#tin09 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs01 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs02 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs03 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs04 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs05 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs06 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs07 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs08 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs09 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs10 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs11 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs12 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs13 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs14 https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs15 https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs16 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs17 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs18 https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs19 https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs20 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs21 https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs22 https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs23 https://w3c.github.io/json-ld-api/tests/expand-manifest#tl001 @@ -432,17 +409,8 @@ https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tdi05 https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tdi06 https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tdi11 https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tdi12 -https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tjs01 -https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tjs02 -https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tjs03 -https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tjs04 -https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tjs05 -https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tjs06 -https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tjs07 https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tjs08 https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tjs09 -https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tjs10 -https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tjs11 https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tli01 https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tli02 https://w3c.github.io/json-ld-api/tests/fromRdf-manifest#tli03 @@ -618,10 +586,7 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs02 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs03 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs04 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs05 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs06 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs07 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs08 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs09 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs10 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs11 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs12 diff --git a/core/src/main/java/com/github/jsonldjava/core/Context.java b/core/src/main/java/com/github/jsonldjava/core/Context.java index 1f6fc5ac..cf0fcaa8 100644 --- a/core/src/main/java/com/github/jsonldjava/core/Context.java +++ b/core/src/main/java/com/github/jsonldjava/core/Context.java @@ -384,9 +384,14 @@ private void createTermDefinition(Map context, String term, } throw new JsonLdError(Error.INVALID_TYPE_MAPPING, type, error); } + // jsonld 1.1: 13.3 in https://w3c.github.io/json-ld-api/#algorithm-0 + if (JsonLdOptions.JSON_LD_1_0.equals(options.getProcessingMode()) + && (JsonLdConsts.NONE.equals(type) || JsonLdConsts.JSON.equals(type))) { + throw new JsonLdError(Error.INVALID_TYPE_MAPPING, type); + } // TODO: fix check for absoluteIri (blank nodes shouldn't count, at // least not here!) - if (JsonLdConsts.ID.equals(type) || JsonLdConsts.VOCAB.equals(type) + if (JsonLdConsts.ID.equals(type) || JsonLdConsts.VOCAB.equals(type) || JsonLdConsts.JSON.equals(type) || (!type.startsWith(JsonLdConsts.BLANK_NODE_PREFIX) && JsonLdUtils.isAbsoluteIri(type))) { definition.put(JsonLdConsts.TYPE, type); @@ -522,8 +527,7 @@ private String selectContainer(final List allContainers) { return (String) supportedContainer.orElse(null); } - // jsonld 1.1: 22.1 in - // https://w3c.github.io/json-ld-api/#create-term-definition + // jsonld 1.1: 22.1 in https://w3c.github.io/json-ld-api/#create-term-definition private List checkValidContainerEntry(final Object containerObject) { List container = (List) (containerObject instanceof List ? containerObject : Arrays.asList(containerObject)); @@ -607,8 +611,6 @@ String expandIri(String value, boolean relative, boolean vocab, Map newMap = newMap(); + newMap.put(JsonLdConsts.VALUE, value); + newMap.put(JsonLdConsts.TYPE, JsonLdConsts.JSON); + expandedValue = newMap; + } // 7.5 - else if (JsonLdConsts.LANGUAGE.equals(activeCtx.getContainer(key)) + else if (JsonLdConsts.LANGUAGE.equals(containerMapping) && value instanceof Map) { // 7.5.1) expandedValue = new ArrayList(); @@ -937,8 +964,11 @@ else if (JsonLdConsts.INDEX.equals(activeCtx.getContainer(key)) // null, so simply return it return null; } + else if (result.getOrDefault(JsonLdConsts.TYPE,"").equals(JsonLdConsts.JSON)) { + // jsonld 1.1: 14.3 in https://w3c.github.io/json-ld-api/#algorithm-3 + } // 8.3) - if (!(rval instanceof String) && result.containsKey(JsonLdConsts.LANGUAGE)) { + else if (!(rval instanceof String) && result.containsKey(JsonLdConsts.LANGUAGE)) { throw new JsonLdError(Error.INVALID_LANGUAGE_TAGGED_VALUE, "when @language is used, @value must be a string"); } diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java index 7773607c..34188dc5 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java @@ -27,6 +27,7 @@ public final class JsonLdConsts { public static final String RDF_OBJECT = RDF_SYNTAX_NS + "object"; public static final String RDF_LANGSTRING = RDF_SYNTAX_NS + "langString"; public static final String RDF_LIST = RDF_SYNTAX_NS + "List"; + public static final String RDF_JSON = RDF_SYNTAX_NS + "JSON"; public static final String TEXT_TURTLE = "text/turtle"; public static final String APPLICATION_NQUADS = "application/n-quads"; // https://www.w3.org/TR/n-quads/#sec-mediatype @@ -63,6 +64,7 @@ public final class JsonLdConsts { public static final String PROPAGATE = "@propagate"; public static final String IMPORT = "@import"; public static final String DIRECTION = "@direction"; + public static final String JSON = "@json"; public enum Embed { ALWAYS, NEVER, LAST, LINK; diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java index 4ce6d681..e5a82ad3 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java @@ -117,6 +117,8 @@ public enum Error { PARSE_ERROR("parse error"), + INVALID_JSON_LITERAL("invalid JSON literal"), + UNKNOWN_ERROR("unknown error"); private final String error; diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java index e0accff7..3a624387 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java @@ -32,7 +32,9 @@ static boolean isKeyword(Object key) { || "@language".equals(key) || "@list".equals(key) || "@omitDefault".equals(key) || "@reverse".equals(key) || "@preserve".equals(key) || "@set".equals(key) || "@type".equals(key) || "@value".equals(key) || "@vocab".equals(key) - || "@requireAll".equals(key); + || "@requireAll".equals(key) || "@version".equals(key)|| "@protected".equals(key) + || "@propagate".equals(key)|| "@import".equals(key)|| "@direction".equals(key) + || "@json".equals(key); } public static Boolean deepCompare(Object v1, Object v2, Boolean listOrderMatters) { diff --git a/core/src/main/java/com/github/jsonldjava/core/RDFDataset.java b/core/src/main/java/com/github/jsonldjava/core/RDFDataset.java index 8f8e18c2..6226f45c 100644 --- a/core/src/main/java/com/github/jsonldjava/core/RDFDataset.java +++ b/core/src/main/java/com/github/jsonldjava/core/RDFDataset.java @@ -5,6 +5,7 @@ import static com.github.jsonldjava.core.JsonLdConsts.RDF_NIL; import static com.github.jsonldjava.core.JsonLdConsts.RDF_REST; import static com.github.jsonldjava.core.JsonLdConsts.RDF_TYPE; +import static com.github.jsonldjava.core.JsonLdConsts.RDF_JSON; import static com.github.jsonldjava.core.JsonLdConsts.XSD_BOOLEAN; import static com.github.jsonldjava.core.JsonLdConsts.XSD_DECIMAL; import static com.github.jsonldjava.core.JsonLdConsts.XSD_DOUBLE; @@ -17,6 +18,7 @@ import static com.github.jsonldjava.core.JsonLdUtils.isValue; import static com.github.jsonldjava.utils.Obj.newMap; +import java.io.IOException; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.ArrayList; @@ -28,6 +30,8 @@ import java.util.Set; import java.util.regex.Pattern; +import com.github.jsonldjava.utils.JsonUtils; + /** * Starting to migrate away from using plain java Maps as the internal RDF * dataset store. Currently each item just wraps a Map based on the old format @@ -240,7 +244,18 @@ Map toObject(Boolean useNativeTypes) throws JsonLdError { else { rval.put("@type", type); } - } else if (!XSD_STRING.equals(type)) { + } + // jsonld 1.1: 2.5 in https://w3c.github.io/json-ld-api/#algorithm-16 + else if(RDF_JSON.equals(type)) { + rval.put("@type", "@json"); + try { + rval.put("@value", JsonUtils.fromString(value)); + } catch (IOException e) { + e.printStackTrace(); + throw new JsonLdError(JsonLdError.Error.INVALID_JSON_LITERAL, value, e); + } + } + else if (!XSD_STRING.equals(type)) { rval.put("@type", type); } } @@ -684,7 +699,17 @@ private Node objectToRDF(Object item) { return new Literal((String) value, datatype == null ? RDF_LANGSTRING : (String) datatype, (String) ((Map) item).get("@language")); - } else { + } + // jsonld 1.1: 8 in https://w3c.github.io/json-ld-api/#algorithm-13 + else if(JsonLdConsts.JSON.equals(datatype)) { + try { + return new Literal(JsonUtils.toString(value), RDF_JSON, null); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + else { return new Literal((String) value, datatype == null ? XSD_STRING : (String) datatype, null); } From 036d7dba584336804ea18ef64025b523afb2d4c8 Mon Sep 17 00:00:00 2001 From: Fabian Steeg Date: Tue, 10 Dec 2019 12:52:40 +0100 Subject: [PATCH 5/7] Some 1.1 tweaks --- core/reports/json-ld-api-tests-skip | 10 ---- .../com/github/jsonldjava/core/Context.java | 51 +++++++++++-------- .../com/github/jsonldjava/core/JsonLdApi.java | 19 +++++-- .../github/jsonldjava/core/JsonLdConsts.java | 1 + .../github/jsonldjava/core/JsonLdUtils.java | 3 +- 5 files changed, 48 insertions(+), 36 deletions(-) diff --git a/core/reports/json-ld-api-tests-skip b/core/reports/json-ld-api-tests-skip index ffa4f259..9216301e 100644 --- a/core/reports/json-ld-api-tests-skip +++ b/core/reports/json-ld-api-tests-skip @@ -78,10 +78,6 @@ https://w3c.github.io/json-ld-api/tests/compact-manifest#tin02 https://w3c.github.io/json-ld-api/tests/compact-manifest#tin03 https://w3c.github.io/json-ld-api/tests/compact-manifest#tin04 https://w3c.github.io/json-ld-api/tests/compact-manifest#tin05 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs06 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs07 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs08 -https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs09 https://w3c.github.io/json-ld-api/tests/compact-manifest#tjs11 https://w3c.github.io/json-ld-api/tests/compact-manifest#tli01 https://w3c.github.io/json-ld-api/tests/compact-manifest#tli02 @@ -294,13 +290,9 @@ https://w3c.github.io/json-ld-api/tests/expand-manifest#tin06 https://w3c.github.io/json-ld-api/tests/expand-manifest#tin07 https://w3c.github.io/json-ld-api/tests/expand-manifest#tin08 https://w3c.github.io/json-ld-api/tests/expand-manifest#tin09 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs15 https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs16 https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs19 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs20 https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs22 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tjs23 -https://w3c.github.io/json-ld-api/tests/expand-manifest#tl001 https://w3c.github.io/json-ld-api/tests/expand-manifest#tli01 https://w3c.github.io/json-ld-api/tests/expand-manifest#tli02 https://w3c.github.io/json-ld-api/tests/expand-manifest#tli03 @@ -597,10 +589,8 @@ https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs16 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs17 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs18 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs19 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs20 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs21 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs22 -https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tjs23 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tli01 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tli02 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tli03 diff --git a/core/src/main/java/com/github/jsonldjava/core/Context.java b/core/src/main/java/com/github/jsonldjava/core/Context.java index cf0fcaa8..69f9c9a7 100644 --- a/core/src/main/java/com/github/jsonldjava/core/Context.java +++ b/core/src/main/java/com/github/jsonldjava/core/Context.java @@ -262,12 +262,15 @@ else if (context instanceof String) { final Object value = ((Map) context).get(JsonLdConsts.VOCAB); if (value == null) { result.remove(JsonLdConsts.VOCAB); - } else if (value instanceof String) { - if (JsonLdUtils.isAbsoluteIri((String) value)) { - result.put(JsonLdConsts.VOCAB, value); + } + // jsonld 1.1: 5.8.3 in https://w3c.github.io/json-ld-api/#algorithm + else if (value instanceof String) { + if (((String) value).startsWith(JsonLdConsts.BLANK_NODE_PREFIX) + || JsonLdUtils.isAbsoluteIri((String) value) || JsonLdUtils.isRelativeIri((String) value)) { + result.put(JsonLdConsts.VOCAB, + expandIri((String) value, true, true, ((Map) result), null)); } else { - throw new JsonLdError(Error.INVALID_VOCAB_MAPPING, - "@value must be an absolute IRI"); + throw new JsonLdError(Error.INVALID_VOCAB_MAPPING, value); } } else { throw new JsonLdError(Error.INVALID_VOCAB_MAPPING, @@ -391,13 +394,12 @@ private void createTermDefinition(Map context, String term, } // TODO: fix check for absoluteIri (blank nodes shouldn't count, at // least not here!) - if (JsonLdConsts.ID.equals(type) || JsonLdConsts.VOCAB.equals(type) || JsonLdConsts.JSON.equals(type) - || (!type.startsWith(JsonLdConsts.BLANK_NODE_PREFIX) - && JsonLdUtils.isAbsoluteIri(type))) { - definition.put(JsonLdConsts.TYPE, type); - } else { + else if (!JsonLdConsts.ID.equals(type) && !JsonLdConsts.VOCAB.equals(type) + && !JsonLdConsts.JSON.equals(type) && !JsonLdConsts.NONE.equals(type) + && (!JsonLdUtils.isAbsoluteIri(type) || type.startsWith(JsonLdConsts.BLANK_NODE_PREFIX))) { throw new JsonLdError(Error.INVALID_TYPE_MAPPING, type); } + definition.put(JsonLdConsts.TYPE, type); } // 11) @@ -455,7 +457,7 @@ private void createTermDefinition(Map context, String term, definition.put(JsonLdConsts.ID, res); } else { throw new JsonLdError(Error.INVALID_IRI_MAPPING, - "resulting IRI mapping should be a keyword, absolute IRI or blank node"); + "resulting IRI mapping should be a keyword, absolute IRI or blank node, but was: " + res); } } @@ -1015,18 +1017,28 @@ public int compare(String a, String b) { typeLanguageMap.put(JsonLdConsts.TYPE, newMap()); containerMap.put(container, typeLanguageMap); } - + // jsonld 1.1: 3.8 in https://w3c.github.io/json-ld-api/#inverse-context-creation + final Map typeMap = (Map) typeLanguageMap + .get(JsonLdConsts.TYPE); // 3.8) if (Boolean.TRUE.equals(definition.get(JsonLdConsts.REVERSE))) { - final Map typeMap = (Map) typeLanguageMap - .get(JsonLdConsts.TYPE); if (!typeMap.containsKey(JsonLdConsts.REVERSE)) { typeMap.put(JsonLdConsts.REVERSE, term); } - // 3.9) - } else if (definition.containsKey(JsonLdConsts.TYPE)) { - final Map typeMap = (Map) typeLanguageMap - .get(JsonLdConsts.TYPE); + } + // jsonld 1.1: 3.10 in https://w3c.github.io/json-ld-api/#inverse-context-creation + else if(JsonLdConsts.NONE.equals(definition.get(JsonLdConsts.TYPE))) { + final Map languageMap = (Map) typeLanguageMap + .get(JsonLdConsts.LANGUAGE); + if(!languageMap.containsKey(JsonLdConsts.ANY)) { + languageMap.put(JsonLdConsts.ANY, term); + } + if(!typeMap.containsKey(JsonLdConsts.ANY)) { + typeMap.put(JsonLdConsts.ANY, term); + } + } + // 3.9) + else if (definition.containsKey(JsonLdConsts.TYPE)) { if (!typeMap.containsKey(definition.get(JsonLdConsts.TYPE))) { typeMap.put((String) definition.get(JsonLdConsts.TYPE), term); } @@ -1054,9 +1066,6 @@ public int compare(String a, String b) { if (!languageMap.containsKey(JsonLdConsts.NONE)) { languageMap.put(JsonLdConsts.NONE, term); } - // 3.11.4) - final Map typeMap = (Map) typeLanguageMap - .get(JsonLdConsts.TYPE); // 3.11.5) if (!typeMap.containsKey(JsonLdConsts.NONE)) { typeMap.put(JsonLdConsts.NONE, term); diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java index 802a5797..85873add 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java @@ -317,7 +317,9 @@ else if (JsonLdConsts.INDEX.equals(expandedProperty) // NOTE: expanded value must be an array due to expansion // algorithm. - + if (!(expandedValue instanceof List)) { + throw new JsonLdError(Error.NOT_IMPLEMENTED, "no array: " + expandedValue); + } // 7.5) if (((List) expandedValue).size() == 0) { // 7.5.1) @@ -659,11 +661,16 @@ else if (JsonLdConsts.VALUE.equals(expandedProperty)) { throw new JsonLdError(Error.INVALID_VALUE_OBJECT_VALUE, value); } } - if (value != null && (value instanceof Map || value instanceof List)) { + // jsonld 1.1: 13.4.7.2 in https://w3c.github.io/json-ld-api/#algorithm-3 + else if (value != null && (value instanceof Map || value instanceof List)) { throw new JsonLdError(Error.INVALID_VALUE_OBJECT_VALUE, - "value of " + expandedProperty + " must be a scalar or null"); + "value of " + expandedProperty + " must be a scalar or null, but was: " + value); } - expandedValue = value; + // jsonld 1.1: 13.4.7.3 in https://w3c.github.io/json-ld-api/#algorithm-3 + else { + expandedValue = value; + } + // jsonld 1.1: 13.4.7.4 in https://w3c.github.io/json-ld-api/#algorithm-3 if (expandedValue == null) { result.put(JsonLdConsts.VALUE, null); continue; @@ -828,6 +835,10 @@ else if (JsonLdConsts.LANGUAGE.equals(containerMapping) } // 7.5.2.2) for (final Object item : (List) languageValue) { + // jsonld 1.1: 13.7.4.2.1 in https://w3c.github.io/json-ld-api/#expansion-algorithm + if(item == null) { + continue; + } // 7.5.2.2.1) if (!(item instanceof String)) { throw new JsonLdError(Error.INVALID_LANGUAGE_MAP_VALUE, diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java index 34188dc5..f88be694 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdConsts.java @@ -65,6 +65,7 @@ public final class JsonLdConsts { public static final String IMPORT = "@import"; public static final String DIRECTION = "@direction"; public static final String JSON = "@json"; + public static final String ANY = "@any"; public enum Embed { ALWAYS, NEVER, LAST, LINK; diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java index 3a624387..a70ac560 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java @@ -34,7 +34,8 @@ static boolean isKeyword(Object key) { || "@type".equals(key) || "@value".equals(key) || "@vocab".equals(key) || "@requireAll".equals(key) || "@version".equals(key)|| "@protected".equals(key) || "@propagate".equals(key)|| "@import".equals(key)|| "@direction".equals(key) - || "@json".equals(key); + || "@json".equals(key) || "@none".equals(key) || "@included".equals(key) + || "@nest".equals(key) || "@prefix".equals(key); } public static Boolean deepCompare(Object v1, Object v2, Boolean listOrderMatters) { From a22f97e62b3ab1131218a989c3915a8ae0d1177d Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Fri, 13 Dec 2019 15:54:03 +0100 Subject: [PATCH 6/7] Minor additions - be more verbose in some error messages - add some more comments pointing to the specs - add a blank node condition according to spec 16.4 --- .../java/com/github/jsonldjava/core/Context.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/github/jsonldjava/core/Context.java b/core/src/main/java/com/github/jsonldjava/core/Context.java index 69f9c9a7..0f2cfbfc 100644 --- a/core/src/main/java/com/github/jsonldjava/core/Context.java +++ b/core/src/main/java/com/github/jsonldjava/core/Context.java @@ -265,12 +265,13 @@ else if (context instanceof String) { } // jsonld 1.1: 5.8.3 in https://w3c.github.io/json-ld-api/#algorithm else if (value instanceof String) { - if (((String) value).startsWith(JsonLdConsts.BLANK_NODE_PREFIX) + if (JsonLdUtils.isBlankNode((String) value) || JsonLdUtils.isAbsoluteIri((String) value) || JsonLdUtils.isRelativeIri((String) value)) { result.put(JsonLdConsts.VOCAB, expandIri((String) value, true, true, ((Map) result), null)); } else { - throw new JsonLdError(Error.INVALID_VOCAB_MAPPING, value); + throw new JsonLdError(Error.INVALID_VOCAB_MAPPING, + "@value must be an IRI or a blank node, but was: "+value); } } else { throw new JsonLdError(Error.INVALID_VOCAB_MAPPING, @@ -301,6 +302,7 @@ else if (value instanceof String) { .contains(key)) { continue; } + // TODO: passing result for active context and the value of the @protected entry from context, if any result.createTermDefinition((Map) context, key, defined); } } @@ -420,6 +422,7 @@ else if (!JsonLdConsts.ID.equals(type) && !JsonLdConsts.VOCAB.equals(type) "Non-absolute @reverse IRI: " + reverse); } definition.put(JsonLdConsts.ID, reverse); + // jsonld 1.1: 14.5 in https://w3c.github.io/json-ld-api/#algorithm-0 if (val.containsKey(JsonLdConsts.CONTAINER)) { final Object containerObject = val.get(JsonLdConsts.CONTAINER); final String container = selectContainer(checkValidContainerEntry(containerObject)); @@ -447,10 +450,10 @@ else if (!JsonLdConsts.ID.equals(type) && !JsonLdConsts.VOCAB.equals(type) throw new JsonLdError(Error.INVALID_IRI_MAPPING, "expected value of @id to be a string"); } - + // jsonld 1.1: 16.4 in https://w3c.github.io/json-ld-api/#algorithm-0 final String res = this.expandIri((String) val.get(JsonLdConsts.ID), false, true, context, defined); - if (JsonLdUtils.isKeyword(res) || JsonLdUtils.isAbsoluteIri(res)) { + if (JsonLdUtils.isKeyword(res) || JsonLdUtils.isAbsoluteIri(res) || JsonLdUtils.isBlankNode(res)) { if (JsonLdConsts.CONTEXT.equals(res)) { throw new JsonLdError(Error.INVALID_KEYWORD_ALIAS, "cannot alias @context"); } @@ -485,6 +488,7 @@ else if (term.indexOf(":") >= 0) { } // 16) + // jsonld 1.1: 21 in https://w3c.github.io/json-ld-api/#algorithm-0 if (val.containsKey(JsonLdConsts.CONTAINER)) { Object containerObject = val.get(JsonLdConsts.CONTAINER); final List allContainers = checkValidContainerEntry(containerObject); @@ -494,7 +498,7 @@ else if (term.indexOf(":") >= 0) { String container = selectContainer(allContainers); if (container == null) { throw new JsonLdError(Error.INVALID_CONTAINER_MAPPING, - "@container must be either @list, @set, @index, or @language, but was: " + "@container must be either @graph, @id, @index, @language, @list, @set or @type, but was: " + allContainers); } definition.put(JsonLdConsts.CONTAINER, container); @@ -1264,4 +1268,4 @@ public Map serialize() { return rval; } -} +} \ No newline at end of file From b6ba9e84aaf5548e7afff12d3b47bf4c368cae17 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Thu, 9 Apr 2020 10:43:47 -0700 Subject: [PATCH 7/7] Some inline comments on areas that can use improvement for 1.1 Focusing on expansion and context/term processing --- .../java/com/github/jsonldjava/core/Context.java | 14 ++++++++++++++ .../java/com/github/jsonldjava/core/JsonLdApi.java | 11 +++++++++++ .../com/github/jsonldjava/core/JsonLdUtils.java | 1 + 3 files changed, 26 insertions(+) diff --git a/core/src/main/java/com/github/jsonldjava/core/Context.java b/core/src/main/java/com/github/jsonldjava/core/Context.java index 0f2cfbfc..252d083d 100644 --- a/core/src/main/java/com/github/jsonldjava/core/Context.java +++ b/core/src/main/java/com/github/jsonldjava/core/Context.java @@ -165,6 +165,7 @@ public Context parse(Object localContext, List remoteContexts) throws Js * @throws JsonLdError * If there is an error parsing the contexts. */ + // GK: Note that parsing may also depend on some options: `override protected and `propagate` private Context parse(Object localContext, List remoteContexts, boolean parsingARemoteContext) throws JsonLdError { if (remoteContexts == null) { @@ -172,6 +173,7 @@ private Context parse(Object localContext, List remoteContexts, } // 1. Initialize result to the result of cloning active context. Context result = this.clone(); // TODO: clone? + // GK: note if localContext is a Map containing `@propagate` that value overrides the `propagate` option. // 2) if (!(localContext instanceof List)) { final Object temp = localContext; @@ -182,6 +184,8 @@ private Context parse(Object localContext, List remoteContexts, for (final Object context : ((List) localContext)) { // 3.1) if (context == null) { + // GK: Note, if active context has any protected terms, and `override protected` is not true, this should fail with 'invalid context nullification'. + // GK: Note, if `propagate` is false, the previous context should be associated with this new (null) context for potential rollback. result = new Context(this.options); continue; } else if (context instanceof Context) { @@ -190,6 +194,7 @@ private Context parse(Object localContext, List remoteContexts, // 3.2) else if (context instanceof String) { String uri = (String) result.get(JsonLdConsts.BASE); + // GK: Note, the context needs to be resolved against the location of the file containing the reference, not the base association from the context. The spec defines a `context base` for this purpose. uri = JsonLdUrl.resolve(uri, (String) context); // 3.2.2 if (remoteContexts.contains(uri)) { @@ -291,6 +296,8 @@ else if (value instanceof String) { } } + // GK: There are more keys to be checked: `@import`, `@direction`, `@propagate` and `@version`. + // GK: You'll want some `processingMode` method to use when doing conditional checks; default value is `json-ld-1.1`, but can be overridden using an API option. // 3.7 final Map defined = new LinkedHashMap(); for (final String key : ((Map) context).keySet()) { @@ -344,12 +351,14 @@ private void createTermDefinition(Map context, String term, defined.put(term, false); + // GK: Note, `@type` can also contain `@protected` in addition to `@container`. If `@container` is there, its value can only be `@set` (or `['@set']`). if (JsonLdUtils.isKeyword(term) && !(options.getAllowContainerSetOnType() && JsonLdConsts.TYPE.equals(term) && !(context.get(term)).toString().contains(JsonLdConsts.ID))) { throw new JsonLdError(Error.KEYWORD_REDEFINITION, term); } + // GK: Note, you'll need to retain any previous definition to make sure, if protected, that any new definition is compatible with it before ending this method. this.termDefinitions.remove(term); Object value = context.get(term); if (value == null || (value instanceof Map @@ -445,6 +454,7 @@ else if (!JsonLdConsts.ID.equals(type) && !JsonLdConsts.VOCAB.equals(type) definition.put(JsonLdConsts.REVERSE, false); // 13) + // GK: Note, there are some required checks to be sure that if the associated term expands to an IRI, it is compatible with `@id` and some other checks. if (val.get(JsonLdConsts.ID) != null && !term.equals(val.get(JsonLdConsts.ID))) { if (!(val.get(JsonLdConsts.ID) instanceof String)) { throw new JsonLdError(Error.INVALID_IRI_MAPPING, @@ -489,6 +499,7 @@ else if (term.indexOf(":") >= 0) { // 16) // jsonld 1.1: 21 in https://w3c.github.io/json-ld-api/#algorithm-0 + // GK: Note, `@container` can take on many more values, and be an array. Best always cast to an array and check to see if the container includes any useful value. There are also some checks to make sure that the content of `@context` is consistent. if (val.containsKey(JsonLdConsts.CONTAINER)) { Object containerObject = val.get(JsonLdConsts.CONTAINER); final List allContainers = checkValidContainerEntry(containerObject); @@ -520,6 +531,8 @@ else if (term.indexOf(":") >= 0) { } } + // GK: Note, other keys to check for are `@index`, `@context` (which requires a recursive call to Context.parse to make sure it's valid), `@direction`, `@nest`, and `@prefix`. + // GK: Note, this is where to check if the previous definition exists and is protected, and we're not overriding protected, that the two definitions are essentially compatible. // 18) this.termDefinitions.put(term, definition); defined.put(term, true); @@ -650,6 +663,7 @@ String compactIri(String iri, Object value, boolean relativeToVocab, boolean rev // 2) if (relativeToVocab && getInverse().containsKey(iri)) { + // GK: Sadly, term selection has become much more involved in 1.1. // 2.1) String defaultLanguage = (String) this.get(JsonLdConsts.LANGUAGE); if (defaultLanguage == null) { diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java index 85873add..1f7091ed 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java @@ -521,6 +521,7 @@ public Object expand(Context activeCtx, String activeProperty, Object element) return null; } + // GK: This would be the point to set `propertyScopedContext` to the `@context` entry for any term definition associated with `activeProperty`. // 3) if (element instanceof List) { // 3.1) @@ -553,14 +554,19 @@ else if (element instanceof Map) { // access helper final Map elem = (Map) element; // 5) + // This would be the place to revert the active context from any previous type-scoped context if the active context has a `previousContext` entry (with some exceptions when called from a map, or if it's a value object or a subject reference). + // GK: If we found a `propertyScopedContext` above, we can parse it to create a new activeCtx using the `override protected` option if (elem.containsKey(JsonLdConsts.CONTEXT)) { activeCtx = activeCtx.parse(elem.get(JsonLdConsts.CONTEXT)); } + // GK: This would be the place to remember this version of activeCtx as `typeScopedContext`. // 6) Map result = newMap(); // 7) final List keys = new ArrayList(elem.keySet()); Collections.sort(keys); + // GK: This is the place to check for a type-scoped context by checking any key that expands to `@type` to see the current context has a term that equals that key where the term definition includes `@context`, updating the activeCtx as you go (but using termScopedContext when checking the keys). + // GK: 1.1 made the following loop somewhat recursive, due to nesting, so might want to extract into a method. for (final String key : keys) { final Object value = elem.get(key); // 7.1) @@ -787,6 +793,7 @@ else if (JsonLdConsts.REVERSE.equals(expandedProperty)) { } } } + // GK: Also, `@included`, `@graph`, and `@direction` // 7.4.11.4) continue; } @@ -853,9 +860,12 @@ else if (JsonLdConsts.LANGUAGE.equals(containerMapping) } } // 7.6) + // GK: Also a place to see if key is `@json` for JSON literals. else if (JsonLdConsts.INDEX.equals(activeCtx.getContainer(key)) && value instanceof Map) { // 7.6.1) + // GK: `@index` also supports property indexing, if the term definition includes `@index`. + // GK: A map can also include `@none`. expandedValue = new ArrayList(); // 7.6.2) final List indexKeys = new ArrayList( @@ -903,6 +913,7 @@ else if (JsonLdConsts.INDEX.equals(activeCtx.getContainer(key)) ((Map) expandedValue).put(JsonLdConsts.LIST, tmp); } } + // GK: Other container possibilities including `@graph`, `@id`, and `@type` along with variations. // 7.10) if (activeCtx.isReverseProperty(key)) { // 7.10.1) diff --git a/core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java b/core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java index a70ac560..4d3591ae 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java @@ -26,6 +26,7 @@ static boolean isKeyword(Object key) { if (!isString(key)) { return false; } + // GK: Note that this set is somewhat dependent on the processing mode. return "@base".equals(key) || "@context".equals(key) || "@container".equals(key) || "@default".equals(key) || "@embed".equals(key) || "@explicit".equals(key) || "@graph".equals(key) || "@id".equals(key) || "@index".equals(key)