我正在构建一个小型Node应用程序,它可以查询本地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并加载了本地文件吗?
谢谢!
发布于 2013-08-01 21:33:20
从查看源代码来看,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);
});
});
});发布于 2015-08-13 13:04:26
下面是我的代码示例,它允许您使用文件的路径加载Node.js中的文件(在这里,options.path可以是/上载/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
}//errhttps://stackoverflow.com/questions/18002780
复制相似问题