GeezerVison is showing github.com — rdf:type with other fields and framing produces wrong output · Issue #242 · jsonld-java/jsonld-java
rdf:type with other fields and framing produces wrong output #242DescriptionThis is a simplified version of the problem I'm facing.
Having the following json A:
{
"@context": {
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
},
"@id": "http://example.com/main/id",
"rdf:type": {
"@id": "http://example.com/rdf/id",
"rdf:label": "someLabel"
}
}
And the following framing B:
{
"@context" : {
"rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
},
"@id" : "http://example.com/main/id"
}
And here is the code I am using to make the apply the framing (it is in Scala, but the conversion to Java should be Trivial).
// the original Json (A) converted to a Jena Model
val jsonModel: Model = ???
// the context of the original Json (A)
val contextJson: String = ???
// the framing (B)
val frame: String = ???
val g = DatasetFactory.wrap(jsonModel).asDatasetGraph
val out = new ByteArrayOutputStream()
val w = RDFDataMgr.createDatasetWriter(RDFFormat.JSONLD_FRAME_FLAT)
val pm = RiotLib.prefixMap(g)
val ctx = new JsonLDWriteContext()
ctx.setJsonLDContext(contextJson)
ctx.setFrame(frame)
Try {
w.write(out, g, pm, null, ctx)
}.flatMap(_ => parse(out.toString).toTry)
The output generated is wrong:
{
"@context" : {
"rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
},
"@graph" : [
{
"@id" : "http://example.com/main/id",
"@type" : "http://example.com/rdf/id"
}
]
}
...because it is omitting the label. I'm expecting the output to be as the input. That's also the behaviour in the Json-LD Playground.
More weirdly, when using a different predicate than rdf:type, the output is correct. So I guess is something related to the special way rdf:type (@type) is being treated when framing. Activitydr0i commented on Oct 27, 2018 @umbreak I created a test using 0.12.2-SNAPSHOT as base and your json input and frame.
The result seems to be ok - it has the label included.
Please have a look if I am missing something. umbreak commented on Oct 27, 2018 ContributorAuthor More actions Yes, your test works. However, the way the variable in in generated is different in your test than it is in Jena
//Your test
final Object in = JsonUtils.fromString(jsonString);
//Jena
Object in = (new JsonLdApi(opts)).fromRDF(jsonldDataset, true);
Jena uses a RDFDataset which then is converted using jsonld-java JsonLdApi into the in variable.
If you change this line in your test with the following:
RDFDataset ds = new RDFDataset();
ds.addTriple("http://example.com/main/id", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://example.com/rdf/id");
ds.addTriple("http://example.com/rdf/id", "http://www.w3.org/1999/02/22-rdf-syntax-ns#label", "someLabel", null, null);
Object in = new JsonLdApi(opts).fromRDF(ds, true);
It still fails. umbreak commented on Nov 6, 2018 ContributorAuthor More actions The issue is related to the logic to convert rdf:type into @type defined here.
This can only be done in the case the @id of the rdf:type does not contain any other field. Right now the logic is doing the conversion without checking that condition. hmichopoulos commented on Jul 26, 2021 @umbreak , could you please explain why we need to add the condition !nodes.containsKey(object.getValue()) ?
The specification https://www.w3.org/TR/json-ld-api/#serialize-rdf-as-json-ld-algorithm doesn't mention such thing.
The result is that when I am trying to convert the following from ttl to json-ld
@prefix masterData: <http://example.com/masterData#> .
@prefix exampleModel: <http://example.com/exampleModel#> .
@prefix example: <http://example.com/example#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
<http://example.com/masterData>
rdf:type owl:Ontology ;
owl:imports <http://www.w3.org/2004/02/skos/core> ;
owl:versionInfo "Created with TopBraid Composer" ;
.
<http://example.com/FirstClass>
rdf:type owl:Ontology ;
.
exampleModel:FirstClass
rdf:type owl:Class ;
rdfs:subClassOf owl:Thing ;
.
exampleModel:FirstClass
skos:prefLabel "Deliverable Descriptor" ;
.
example:oneTwoThree
rdf:type exampleModel:FirstClass ;
rdf:type exampleModel:SecondClass ;
exampleModel:entityStatus "Deprecated" ;
exampleModel:priority 1 ;
skos:prefLabel "An element" ;
.
it returns
{
"@graph" : [ {
"@id" : "http://example.com/FirstClass",
"@type" : "owl:Ontology"
}, {
"@id" : "example:oneTwoThree",
"@type" : "exampleModel:SecondClass",
"entityStatus" : "Deprecated",
"exampleModel:priority" : 1,
"rdf:type" : {
"@id" : "exampleModel:FirstClass"
},
"prefLabel" : "An element"
}, {
"@id" : "exampleModel:FirstClass",
"@type" : "owl:Class",
"subClassOf" : "owl:Thing",
"prefLabel" : "Deliverable Descriptor"
}, {
"@id" : "http://example.com/masterData",
"@type" : "owl:Ontology",
"imports" : "http://www.w3.org/2004/02/skos/core",
"versionInfo" : "Created with TopBraid Composer"
} ],
"@context" : {
"versionInfo" : {
"@id" : "http://www.w3.org/2002/07/owl#versionInfo"
},
"imports" : {
"@id" : "http://www.w3.org/2002/07/owl#imports",
"@type" : "@id"
},
"prefLabel" : {
"@id" : "http://www.w3.org/2004/02/skos/core#prefLabel"
},
"subClassOf" : {
"@id" : "http://www.w3.org/2000/01/rdf-schema#subClassOf",
"@type" : "@id"
},
"priority" : {
"@id" : "http://example.com/exampleModel#priority",
"@type" : "http://www.w3.org/2001/XMLSchema#integer"
},
"entityStatus" : {
"@id" : "http://example.com/exampleModel#entityStatus"
},
"masterData" : "http://example.com/masterData#",
"owl" : "http://www.w3.org/2002/07/owl#",
"rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"skos" : "http://www.w3.org/2004/02/skos/core#",
"rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
"exampleModel" : "http://example.com/exampleModel#",
"example" : "http://example.com/example#"
}
}
but both https://www.easyrdf.org/converter and http://rdfvalidator.mybluemix.net/ convert it in a way where both types of example:oneTwoThree are returned into @type dr0i commented on Mar 4, 2022
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|