2013-08-01 94 views
0

我正在構建一個查詢本地n3三重文件並使用rdfstore-js的小型Node應用程序。我使用文檔使用的示例工作正常,但這是遠程三重存儲。文檔混淆了哪些參數要傳遞給本地文件的rdfstore.create()。也許這樣?rdfstore-js創建/加載本地文件

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

    }); 
}) 

任何使用rdfstore-js並已加載本地文件?

謝謝!

回答

0

從源代碼的角度看,rdfstore-js似乎不支持加載SPARQL更新中引用的本地文件(例如:LOAD <file:///myfile.ttl>)。 但是,你可以自己閱讀文件,並直接傳遞數據:

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

這裏是我的代碼示例,它允許您使用的文件的路徑來加載在Node.js的文件(這裏的選項。路徑可能是/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