rdfstore js创建/加载本地文件

rdfstore js创建/加载本地文件,rdf,sparql,rdfstore,Rdf,Sparql,Rdfstore,我正在构建一个查询本地n3三重文件的小节点应用程序,并使用rdfstore js。我对文档使用的示例的所有操作都正常,但这是一个远程三重存储。对于要传递给本地文件的rdfstore.create()的参数,文档很混乱。也许是这样的 rdfstore.create(function(store) { store.execute('LOAD /Users/Ben/Desktop/MET/triple_SPARQL/triples.n3 text/n3 ', functio

我正在构建一个查询本地n3三重文件的小节点应用程序,并使用rdfstore js。我对文档使用的示例的所有操作都正常,但这是一个远程三重存储。对于要传递给本地文件的rdfstore.create()的参数,文档很混乱。也许是这样的

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

    });
})
有人使用rdfstore js并加载了本地文件吗


谢谢

从源代码看,rdfstore js似乎不支持加载SPARQL更新中引用的本地文件(例如:
LOAD
)。 但是,您可以自己读取文件并直接传入数据:

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);
    });
  });
});

下面是我的代码示例,它允许您使用文件的a路径在Node.js中加载文件(这里options.path可以是/uploads/123.owl)

rdfstore.create(function(err, store) {    
      if (err) 
          console.log("There was an error creating the store", err);                    
      else    
      {
          //replace / with \ 
          var syncPath = __dirname + options.path;      //local but not enough 
          var re = new RegExp('/', 'g');
          syncPath = syncPath.replace(re, '\\'); //update path        

          //set full path from filesystem of the ontology        
          var ontology = fs.readFileSync(__dirname + options.path).toString();

                      //LOCAL
                     store.load("application/ld+json" , ontology, "graph", function(err, results) {           

                        if (err)
                          console.log("There was an error loading the store", err);
                        else
                        {
                          store.graph("graph", function(err, graph) {

                             if (err)
                             {
                                console.log("There was an error creating the graph", err);  
                             }
                             else
                             {
                                var triples = graph.toArray();
                                console.log("Constructing triples sync... ");
                                console.log("There are ", triples.length, "triples");   

                                if (triples.length !== 0) 
                                {                  
                                  cb(triples);                                 }    
                            }

                          }); //graph                            
                       }
                    });

                    store.close(); //done
      }//err