Search code examples
rdfsparqlrdfstore

rdfstore-js create/load local file


I'm building a small Node app that queries an local n3 triple file, and using rdfstore-js. I have everything working OK with the example that the documentation uses, but thats a remote triple store. Documentation is confusing as to what parameters to pass in to rdfstore.create() for a local file. Perhaps something like this?

    rdfstore.create(function(store) {
    store.execute('LOAD /Users/Ben/Desktop/MET/triple_SPARQL/triples.n3 text/n3 ',       function() {

    });
})

Anyone used rdfstore-js and has loaded in local files?

Thanks!


Solution

  • From glancing at the source code, rdfstore-js doesn't seem to support loading local files referenced in SPARQL Updates (eg: LOAD <file:///myfile.ttl> ). However, you can read the file yourself and pass the data in directly:

    var rdfstore = require('rdfstore')
    , fs = require('fs');
    
    rdfstore.create(function(store){
      var rdf = fs.readFileSync('/var/foo/bar.ttl').toString();
      store.load('text/turtle', rdf, function(s,d){
        console.log(s,d);
        store.execute("SELECT * WHERE { ?s ?p ?o } LIMIT 10", function(success, results){
          console.log(success, results);
        });
      });
    });