我想通过Nodejs将三元组插入到Virtuoso内的图形中。所以,首先我用CURL命令检查它,它正在工作。现在我想尝试使用nodejs代码,但它不工作,也没有显示任何错误.... 这是参考: 对于curl命令(以下网页中的示例2):
http://docs.openlinksw.com/virtuoso/rdfinsertmethodshttppost/
对于Node.js,代码为:
var triples =
"http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this>"+
"<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>"+
"<http://rdfs.org/sioc/ns#User> ."+
"<http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this>"+
"<http://www.w3.org/2000/01/rdf-schema#label>"+
"<Kingsley Uyi Idehen> ."+
"<http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this>"+
"<http://rdfs.org/sioc/ns#creator_of> <http://www.openlinksw.com/dataspace/kidehen@openlinksw.com/weblog/kidehen@openl"+"inksw.com%27s%20BLOG%20%5B127%5D/1300>";
var myData= JSON.stringify("INSERT IN GRAPH <http://mygraph.org> { "+triples+" }";
var header = {
'Content-Type': "application/sparql-query",
'Content-Length': Buffer.byteLength(myData)
};
var options = {
host: localhost,
port: 8890,
auth: 'dba:dba',
path: '/DAV/home/dba/rdf_sink/mydata',
method: 'POST',
headers: header
};
var req = http.request(options, function(res) {
res.setEncoding('utf-8');
var responseString = '';
res.on('data', function(data) {
console.log('On data:' + data);
});
res.on('end', function() {});
});
req.on('error', function(e) {
console.log('On Error:' + e);
});
req.write(myData);
req.end();
&#13;
代码没有显示错误,但也没有在virtuoso数据库中插入任何三元组。请建议..
答案 0 :(得分:1)
首先,内联数据中仍存在错误。你有 -
var triples =
"http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this>"+
"<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>"+
"<http://rdfs.org/sioc/ns#User> ."+
"<http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this>"+
"<http://www.w3.org/2000/01/rdf-schema#label>"+
"<Kingsley Uyi Idehen> ."+
"<http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this>"+
"<http://rdfs.org/sioc/ns#creator_of> <http://www.openlinksw.com/dataspace/kidehen@openlinksw.com/weblog/kidehen@openl"+"inksw.com%27s%20BLOG%20%5B127%5D/1300>";
文字包含在<>
而不是""
中;第一个URI缺少开头<
;一些可能在语法上重要的空白缺失...
应该成为(为了便于阅读而进行一些额外的空格调整) -
var triples =
"<http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this> "+
"<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> "+
"<http://rdfs.org/sioc/ns#User> . "+
"<http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this> "+
"<http://www.w3.org/2000/01/rdf-schema#label> "+
"\"Kingsley Uyi Idehen\" . "+
"<http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this> "+
"<http://rdfs.org/sioc/ns#creator_of> "+
"<http://www.openlinksw.com/dataspace/kidehen@openlinksw.com/weblog"+
"/kidehen@openlinksw.com%27s%20BLOG%20%5B127%5D/1300> . ";
我原本期望你的原始文件导致一些错误输出(可能在Virtuoso日志文件中找到,虽然它可能在node.js
交互中的某处被抑制/丢弃),而不是静默失败;不过,上述情况可能会解决问题。