Convert sparql endpoint json remote results to JSON-LD

I have a Sparql endpoint (openrdf sesame) on my local machine. I can get the results of queries (6) in json (using the sparql-client node module). Now I need to convert this json to json-ld so that I can easily display it in a jade file. How can I do this without using rdfstore-js in my node.js application? I read about the jsonld node module. The json data is quite large, so I cannot specify the context for it.

Problem with rdfstore-js: Since the endpoint is on my local machine, I ran into a cross-domain problem. So, I tried to load data from remote sparql endpoints into the repository, but it does not work. https://github.com/antoniogarrote/rdfstore-js/issues/20

Alternatively, I am open to suggestions in which I can display data without json-ld.

Edit: After reading Gregg's suggestion, I tried using the CONSTRUCT query. However, the sesame server returns the response of the request as text / plain. I tried content negotiation by providing an accept header for json-ld. But it will not succeed - it gives me "No suitable file format was found."

Thank!


Now I am using the nodejs http module as shown below. I get the answer as text / plain. Is there a way to convert plain text to json-ld?

var queryString = syllPrefix+" CONSTRUCT { ?uri ?p ?o } where  { ?uri a syll:Person . ?uri ?p ?o}";
var encodedquerystring = encodeURIComponent(queryString);
var options = {
        host: 'localhost',
        port: 8080,
        path: '/openrdf-sesame/repositories/myrepo?query=' +encodedquerystring,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': 'text/plain',
        },
      };


var req = http.get(options, function(res) {
  //  console.log("Got response: " + res.statusCode);
   // console.log('HEADERS: ' + JSON.stringify(res.headers));
    var data = "";
    res.on('data', function (chunk) {
      data += chunk;
    });
    res.on('end', function () {
      console.log (data);
    });
  }).on('error', function(e) {
    console.log("Got error: " + e.message);
  });
  req.end();
+3
source share
2 answers

Sesame does not support JSON-LD format out of the box. You will need to install a SESame compatible JSON-LD message library (e.g. jsonld-java ) in your existing Sesame installation .

, jar jsonld-java jsonld-java-sesame ( , , , Apache Jackson, - : Maven Central) Sesame Tomcat. - [TOMCAT_DIR]/webapps/openrdf-sesame/WEB-INF/lib. , Tomcat , .

, Accept ( application/ld+json) JSON-LD .

RDF 1.1 JSON Alternate Serialization, , JSON-LD, Sesame. application/rdf+json.

+4

JSON-LD sparql- ( , Ruby), CONSTRUCT DESCRIBE, SELECT ASK. , JSON-LD ( , , , Python, Ruby Java), , HTTP- /ld + json.

SELECT ASK JSON-LD , . /sparql + json

+4

All Articles