2013-08-01 2 views
0

로컬 n3 트리플 파일을 쿼리하고 rdfstore-js를 사용하여 작은 노드 응용 프로그램을 만들고 있습니다. 나는 문서가 사용하는 예제로 모든 것을 작동 시키지만, 원격 트리플 스토어는 그렇다. 로컬 파일에 대해 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