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..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()))) { + (!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 7586c1c6..8fdefa4b 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,59 @@ public void testIssue301() throws JsonLdError { out2.toString()); } + @Test + public void testIssue329() throws JsonLdError { + 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()); + } + + @Test + public void testIssue329_blankNode() throws JsonLdError { + 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()); + } } 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"},