profile
viewpoint

Ask questionsjsonld wrong handling of default graph

I am experimenting with the rdflib and the hydra jsonld API.

myTestcode.ts

import * as rdf from "rdflib"

const store: rdf.IndexedFormula = rdf.graph();
const fetcher: rdf.Fetcher = new rdf.Fetcher(store);
const updateMgr: rdf.UpdateManager = new rdf.UpdateManager(store);
const MY_DOMAIN = rdf.Namespace("https://my-domain.de/vocab#");
const docNode = rdf.sym("https://localhost:8443/companions");
const context = "http://www.w3.org/ns/hydra/context.jsonld";

const jsonDoc ={
    "@context": "http://www.w3.org/ns/hydra/context.jsonld",
    "@id": `${docNode.uri}`,
    "title": "A companion container.",
    "description": "Companions can be managed with ldp container.",
    "operation": [
        {
        "@type": "Operation",
        "method": "POST"
        }
    ]
};

const asNquads = `<https://localhost:8443/companions> <http://www.w3.org/ns/hydra/core#description> "This issue can be deleted with an HTTP DELETE request" .
<https://localhost:8443/companions> <http://www.w3.org/ns/hydra/core#operation> _:b0 .
<https://localhost:8443/companions> <http://www.w3.org/ns/hydra/core#title> "An exemplary issue representation" .
_:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/hydra/core#Operation> .
_:b0 <http://www.w3.org/ns/hydra/core#method> "DELETE" .
`
rdf.parse(JSON.stringyfi(jsonldDoc), store, docNode.uri, 'application/ld+json', (err, res) => {
      if (err) {
          throw new Error();
      } else {
          rdf.serialize(docNode, store, docNode.uri, 'application/ld+json', (err, res) => {
              if (err) {
                  throw new Error();
              } else {
                  console.log(res);
              }
          });
     }
});

If i am not mistaken, all nodes should belong to the default graph. If I parse a turtle document, rdflib uses the base-parameter of the parse function as the graph name. But if I parse the jsonld-document rdflib sets nodeobjects as the graph names. In a result I get a rdf dataset with two different graphs instead of one. The line of code where the why (graphname) gets set is in indexed-formular.js lines 270-273:

if (!why) {
        // system generated
        why = this.fetcher ? this.fetcher.appNode : this.sym(defaultGraphURI);
      }
}

Thus the serializing of docNode does only print 3 rdf-triples instead of 5.

If this behavior is not intended, I could write a fix. I think there must just be a check for the default graph be included in parser.js. If the default graph is detected, why will be set to base.

linkeddata/rdflib.js

Answer questions bourgeoa

resolved #509

useful!

Related questions

No questions were found.
source:https://uonfu.com/
Github User Rank List