Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,7 @@ public List<Object> 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;
}
Expand Down
55 changes: 55 additions & 0 deletions core/src/test/java/com/github/jsonldjava/core/JsonLdToRdfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
5 changes: 1 addition & 4 deletions core/src/test/resources/custom/frame-0010-out.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
},
"@graph" : [ {
"@id" : "http://example.com/main/id",
"rdf:type" : {
"@id" : "http://example.com/rdf/id",
"rdf:label" : "someLabel"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we loose the label which is not good.
Look at the playground.
I think it's not possible to have a label for @type keyword in this way.
See also #242.

"@type" : "http://example.com/rdf/id"
}
]
}
4 changes: 1 addition & 3 deletions core/src/test/resources/json-ld.org/fromRdf-0020-out.jsonld
Original file line number Diff line number Diff line change
@@ -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"}],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... while your code seems to be good in this case - compare
without @type and with @type , there is no difference in the nquads.
See also #242 (comment) where this is reported to be the expected outcome.

"http://example.com/prop2": [
{"@value": "Plain"},
Expand Down