diff --git a/core/reports/json-ld-api-tests-skip b/core/reports/json-ld-api-tests-skip index 911bf5a6..9216301e 100644 --- a/core/reports/json-ld-api-tests-skip +++ b/core/reports/json-ld-api-tests-skip @@ -56,13 +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#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 https://w3c.github.io/json-ld-api/tests/compact-manifest#te001 https://w3c.github.io/json-ld-api/tests/compact-manifest#te002 @@ -83,16 +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#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 @@ -193,8 +178,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 +204,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 @@ -235,7 +217,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 @@ -309,30 +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#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 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 @@ -371,10 +331,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,19 +343,14 @@ 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 -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 @@ -407,11 +358,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 @@ -431,10 +379,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#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 https://w3c.github.io/json-ld-api/tests/expand-manifest#tso13 https://w3c.github.io/json-ld-api/tests/expand-manifest#ttn01 @@ -456,17 +401,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 @@ -512,7 +448,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 @@ -520,13 +455,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#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 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi09 https://w3c.github.io/json-ld-api/tests/toRdf-manifest#tdi10 @@ -575,8 +503,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 @@ -652,10 +578,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 @@ -666,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 @@ -708,10 +629,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,19 +641,14 @@ 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 -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 @@ -744,11 +656,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 @@ -769,10 +678,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#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 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 8c149b08..252d083d 100644 --- a/core/src/main/java/com/github/jsonldjava/core/Context.java +++ b/core/src/main/java/com/github/jsonldjava/core/Context.java @@ -4,11 +4,13 @@ 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; 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; @@ -163,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) { @@ -170,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; @@ -180,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) { @@ -188,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)) { @@ -215,6 +222,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 @@ -248,12 +267,16 @@ 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 (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 must be an absolute IRI"); + "@value must be an IRI or a blank node, but was: "+value); } } else { throw new JsonLdError(Error.INVALID_VOCAB_MAPPING, @@ -273,13 +296,20 @@ else if (context 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()) { - if (JsonLdConsts.BASE.equals(key) || JsonLdConsts.VOCAB.equals(key) - || JsonLdConsts.LANGUAGE.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; } + // TODO: passing result for active context and the value of the @protected entry from context, if any result.createTermDefinition((Map) context, key, defined); } } @@ -321,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 @@ -366,15 +398,19 @@ 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) - || (!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) @@ -395,14 +431,17 @@ private void createTermDefinition(Map context, String term, "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 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); @@ -415,22 +454,23 @@ private void createTermDefinition(Map context, String term, 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, "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"); } 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); } } @@ -458,13 +498,19 @@ 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)) { - 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 @graph, @id, @index, @language, @list, @set or @type, but was: " + + allContainers); } definition.put(JsonLdConsts.CONTAINER, container); if (JsonLdConsts.TYPE.equals(term)) { @@ -485,11 +531,42 @@ 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); } + 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 * @@ -553,8 +630,6 @@ String expandIri(String value, boolean relative, boolean vocab, 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); } @@ -998,9 +1084,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); @@ -1199,4 +1282,4 @@ public Map serialize() { return rval; } -} +} \ No newline at end of file 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 74cea926..1f7091ed 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java @@ -188,7 +188,12 @@ public Object compact(Context activeCtx, String activeProperty, Object element, // 4 if (elem.containsKey(JsonLdConsts.VALUE) || elem.containsKey(JsonLdConsts.ID)) { final Object compactedValue = activeCtx.compactValue(activeProperty, elem); - if (!(compactedValue instanceof Map || compactedValue instanceof List)) { + boolean isScalar = !(compactedValue instanceof Map || compactedValue instanceof List); + // jsonld 1.1: 7 in https://w3c.github.io/json-ld-api/#algorithm-6 + boolean isJson = activeCtx.getTermDefinition(activeProperty) != null + && JsonLdConsts.JSON.equals( + activeCtx.getTermDefinition(activeProperty).get(JsonLdConsts.TYPE)); + if (isScalar || isJson) { return compactedValue; } } @@ -312,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) @@ -514,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) @@ -546,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) @@ -580,6 +593,8 @@ else if (element instanceof Map) { throw new JsonLdError(Error.COLLIDING_KEYWORDS, expandedProperty + " already exists in result"); } + // jsonld 1.1: 12 in https://w3c.github.io/json-ld-api/#algorithm-3 + Object inputType = elem.get(JsonLdConsts.TYPE); // 7.4.3) if (JsonLdConsts.ID.equals(expandedProperty)) { if (value instanceof String) { @@ -645,11 +660,23 @@ else if (JsonLdConsts.GRAPH.equals(expandedProperty)) { } // 7.4.6) else if (JsonLdConsts.VALUE.equals(expandedProperty)) { - if (value != null && (value instanceof Map || value instanceof List)) { + // jsonld 1.1: 13.4.7.1 in https://w3c.github.io/json-ld-api/#algorithm-3 + if(JsonLdConsts.JSON.equals(inputType)) { + expandedValue = value; + if(opts.getProcessingMode().equals(JsonLdOptions.JSON_LD_1_0)) { + throw new JsonLdError(Error.INVALID_VALUE_OBJECT_VALUE, value); + } + } + // 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; @@ -766,6 +793,7 @@ else if (JsonLdConsts.REVERSE.equals(expandedProperty)) { } } } + // GK: Also, `@included`, `@graph`, and `@direction` // 7.4.11.4) continue; } @@ -780,13 +808,26 @@ else if (frameExpansion && (JsonLdConsts.EXPLICIT.equals(expandedProperty) } // 7.4.12) if (expandedValue != null) { + /* jsonld 1.1: 13.4.16 in https://w3c.github.io/json-ld-api/#algorithm-3 + if (!(expandedValue == null && JsonLdConsts.VALUE.equals(expandedProperty) + && (inputType == null || JsonLdConsts.JSON.equals(inputType)))) { */ result.put(expandedProperty, expandedValue); } // 7.4.13) continue; } + // jsonld 1.1: 13.5 in https://w3c.github.io/json-ld-api/#algorithm-3 + String containerMapping = activeCtx.getContainer(key); + // jsonld 1.1: 13.6 in https://w3c.github.io/json-ld-api/#algorithm-3 + if (activeCtx.getTermDefinition(key) != null + && JsonLdConsts.JSON.equals(activeCtx.getTermDefinition(key).get(JsonLdConsts.TYPE))) { + 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(); @@ -801,6 +842,10 @@ else if (JsonLdConsts.LANGUAGE.equals(activeCtx.getContainer(key)) } // 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, @@ -815,9 +860,12 @@ else if (JsonLdConsts.LANGUAGE.equals(activeCtx.getContainer(key)) } } // 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( @@ -865,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) @@ -937,8 +986,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 9de5b76b..f88be694 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 @@ -58,6 +59,13 @@ 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 static final String PROTECTED = "@protected"; + 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 static final String ANY = "@any"; 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..e5a82ad3 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdError.java @@ -102,10 +102,14 @@ 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"), - NOT_IMPLEMENTED("not implemnted"), + NOT_IMPLEMENTED("not implemented"), UNKNOWN_FORMAT("unknown format"), @@ -113,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/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 */ 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..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,13 +26,17 @@ 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) || "@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) || "@none".equals(key) || "@included".equals(key) + || "@nest".equals(key) || "@prefix".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); }