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) {
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();
Margi source
share