From 9c0bb7b3c09ad19027cb1142b2e3e81a66d6dacf Mon Sep 17 00:00:00 2001 From: Tom Dalton Date: Wed, 16 Feb 2022 16:39:20 -0700 Subject: [PATCH 1/4] Fixed issue where expanded type IRI would be used rather than @type --- .../com/github/jsonldjava/core/JsonLdApi.java | 2 +- .../jsonldjava/core/JsonLdToRdfTest.java | 28 +++++++++++++++++++ .../resources/custom/frame-0010-out.jsonld | 5 +--- .../json-ld.org/fromRdf-0020-out.jsonld | 4 +-- 4 files changed, 31 insertions(+), 8 deletions(-) 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 2195d09a..01c7557c 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java @@ -2002,7 +2002,7 @@ public List fromRDF(final RDFDataset dataset, boolean noDuplicatesInData // 3.5.4) if (RDF_TYPE.equals(predicate) && (object.isIRI() || object.isBlankNode()) && !opts.getUseRdfType() && - (!nodes.containsKey(object.getValue()) || subject.equals(object.getValue()))) { + (!nodes.containsKey(object.getValue()) || subject.equals(object.getValue()) || object.isIRI())) { JsonLdUtils.mergeValue(node, JsonLdConsts.TYPE, object.getValue()); continue; } diff --git a/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java b/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java index 7586c1c6..59cb31f7 100644 --- a/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java +++ b/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java @@ -28,4 +28,32 @@ public void testIssue301() throws JsonLdError { out2.toString()); } + @Test + public void testIssue329() throws Exception { + final RDFDataset rdf = new RDFDataset(); + rdf.addTriple( + "http://test.com/ontology#Class1", + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", + "http://www.w3.org/2002/07/owl#Class"); + rdf.addTriple( + "http://test.com/ontology#Individual1", + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", + "http://test.com/ontology#Class1"); + final JsonLdOptions opts = new JsonLdOptions(); + opts.setUseRdfType(Boolean.FALSE); + opts.setProcessingMode(JsonLdOptions.JSON_LD_1_0); + + final Object out = new JsonLdApi(opts).fromRDF(rdf, true); + assertEquals("[{@id=http://test.com/ontology#Class1, @type=[http://www.w3.org/2002/07/owl#Class]}, " + + "{@id=http://test.com/ontology#Individual1, @type=[http://test.com/ontology#Class1]}]", + out.toString()); + + opts.setUseRdfType(Boolean.TRUE); + + final Object out2 = new JsonLdApi(opts).fromRDF(rdf, true); + assertEquals("[{@id=http://test.com/ontology#Class1, " + + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type=[{@id=http://www.w3.org/2002/07/owl#Class}]}," + + " {@id=http://test.com/ontology#Individual1, http://www.w3.org/1999/02/22-rdf-syntax-ns#type=[{@id=http://test.com/ontology#Class1}]}]", + out2.toString()); + } } diff --git a/core/src/test/resources/custom/frame-0010-out.jsonld b/core/src/test/resources/custom/frame-0010-out.jsonld index 491fa921..afdfe54a 100644 --- a/core/src/test/resources/custom/frame-0010-out.jsonld +++ b/core/src/test/resources/custom/frame-0010-out.jsonld @@ -4,10 +4,7 @@ }, "@graph" : [ { "@id" : "http://example.com/main/id", - "rdf:type" : { - "@id" : "http://example.com/rdf/id", - "rdf:label" : "someLabel" - } + "@type" : "http://example.com/rdf/id" } ] } \ No newline at end of file diff --git a/core/src/test/resources/json-ld.org/fromRdf-0020-out.jsonld b/core/src/test/resources/json-ld.org/fromRdf-0020-out.jsonld index 6f9d169f..6f16ccb5 100644 --- a/core/src/test/resources/json-ld.org/fromRdf-0020-out.jsonld +++ b/core/src/test/resources/json-ld.org/fromRdf-0020-out.jsonld @@ -1,9 +1,7 @@ [ { "@id": "http://example.com/Subj1", - "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : [{ - "@id": "http://example.com/Type" - }], + "@type" : ["http://example.com/Type"], "http://example.com/prop1": [{"@id": "http://example.com/Obj1"}], "http://example.com/prop2": [ {"@value": "Plain"}, From c065878c5016405acda1bf9e1e2192dd8b2cdcfe Mon Sep 17 00:00:00 2001 From: Tom Dalton Date: Wed, 16 Feb 2022 16:56:01 -0700 Subject: [PATCH 2/4] Handled blank node as type --- .../com/github/jsonldjava/core/JsonLdApi.java | 2 +- .../jsonldjava/core/JsonLdToRdfTest.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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 01c7557c..0159df16 100644 --- a/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java +++ b/core/src/main/java/com/github/jsonldjava/core/JsonLdApi.java @@ -2002,7 +2002,7 @@ public List fromRDF(final RDFDataset dataset, boolean noDuplicatesInData // 3.5.4) if (RDF_TYPE.equals(predicate) && (object.isIRI() || object.isBlankNode()) && !opts.getUseRdfType() && - (!nodes.containsKey(object.getValue()) || subject.equals(object.getValue()) || object.isIRI())) { + (!nodes.containsKey(object.getValue()) || subject.equals(object.getValue()) || !object.isLiteral())) { JsonLdUtils.mergeValue(node, JsonLdConsts.TYPE, object.getValue()); continue; } diff --git a/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java b/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java index 59cb31f7..c73c3b50 100644 --- a/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java +++ b/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java @@ -1,5 +1,6 @@ package com.github.jsonldjava.core; +import com.github.jsonldjava.utils.JsonUtils; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -56,4 +57,31 @@ public void testIssue329() throws Exception { + " {@id=http://test.com/ontology#Individual1, http://www.w3.org/1999/02/22-rdf-syntax-ns#type=[{@id=http://test.com/ontology#Class1}]}]", out2.toString()); } + + @Test + public void testIssue329_blankNode() throws Exception { + final RDFDataset rdf = new RDFDataset(); + rdf.addTriple( + "http://test.com/ontology#Individual1", + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", + "_:someThing"); + rdf.addTriple( + "_:someThing", + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", + "http://test.com/ontology#Class1"); + final JsonLdOptions opts = new JsonLdOptions(); + opts.setUseRdfType(Boolean.FALSE); + opts.setProcessingMode(JsonLdOptions.JSON_LD_1_0); + + final Object out = new JsonLdApi(opts).fromRDF(rdf, true); + assertEquals("[{@id=_:someThing, @type=[http://test.com/ontology#Class1]}, " + + "{@id=http://test.com/ontology#Individual1, @type=[_:someThing]}]", out.toString()); + + opts.setUseRdfType(Boolean.TRUE); + + final Object out2 = new JsonLdApi(opts).fromRDF(rdf, true); + assertEquals("[{@id=_:someThing, http://www.w3.org/1999/02/22-rdf-syntax-ns#type=[{@id=http://test.com/ontology#Class1}]}," + + " {@id=http://test.com/ontology#Individual1, http://www.w3.org/1999/02/22-rdf-syntax-ns#type=[{@id=_:someThing}]}]", + out2.toString()); + } } From 96efdd2a5bfbed1fc86d701839d25277fc27295b Mon Sep 17 00:00:00 2001 From: Tom Dalton Date: Wed, 16 Feb 2022 16:58:44 -0700 Subject: [PATCH 3/4] Removed unused import --- .../test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java b/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java index c73c3b50..7e2966bd 100644 --- a/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java +++ b/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java @@ -1,6 +1,5 @@ package com.github.jsonldjava.core; -import com.github.jsonldjava.utils.JsonUtils; import org.junit.Test; import static org.junit.Assert.assertEquals; From f67e9817e45a85f0ef789e2639430b815f18fbe1 Mon Sep 17 00:00:00 2001 From: Tom Dalton Date: Wed, 16 Feb 2022 16:59:17 -0700 Subject: [PATCH 4/4] Changed throw type --- .../test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java b/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java index 7e2966bd..8fdefa4b 100644 --- a/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java +++ b/core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java @@ -29,7 +29,7 @@ public void testIssue301() throws JsonLdError { } @Test - public void testIssue329() throws Exception { + public void testIssue329() throws JsonLdError { final RDFDataset rdf = new RDFDataset(); rdf.addTriple( "http://test.com/ontology#Class1", @@ -58,7 +58,7 @@ public void testIssue329() throws Exception { } @Test - public void testIssue329_blankNode() throws Exception { + public void testIssue329_blankNode() throws JsonLdError { final RDFDataset rdf = new RDFDataset(); rdf.addTriple( "http://test.com/ontology#Individual1",