GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #242

New issue
Copy link
New issue
Copy link
Closed
Closed
rdf:type with other fields and framing produces wrong output#242
Copy link

Description

@umbreak
umbreak
opened on Sep 27, 2018
Issue body actions

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.

Activity

  1. dr0i
    added a commit that references this issue on Oct 27, 2018

    Provide test for jsonld-java#242

    47f7cb4
  2. dr0i commented on Oct 27, 2018

    @dr0i
    dr0i
    on Oct 27, 2018
    Member
    More actions

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

  3. umbreak commented on Oct 27, 2018

    @umbreak
    umbreak
    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.

  4. umbreak commented on Nov 6, 2018

    @umbreak
    umbreak
    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.

  5. ansell
    closed this as completedin #245on Nov 7, 2018
  6. hmichopoulos commented on Jul 26, 2021

    @hmichopoulos
    hmichopoulos
    on Jul 26, 2021
    More actions

    @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

  7. dr0i commented on Mar 4, 2022

    @dr0i
    dr0i
    on Mar 4, 2022
    Member
    More actions

    Thx @hmichopoulos for your report. It has become a new issue: #329.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.