這裏是我的代碼示例,它允許您使用的文件的路徑來加載在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