Skip to content

rdf:type with other fields and framing produces wrong output #242

@umbreak

Description

@umbreak

This 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions