这是我的代码示例,它允许您使用文件路径在 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