Virtuoso 通过 nodejs 代码实现三倍插入

virtuoso triples insertion through nodejs code

我想通过 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();
         

代码没有显示错误,但也没有在 virtuoso 数据库中插入任何三元组..请建议..

首先,您的内联数据中仍然存在错误。你有--

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 日志文件中找到,尽管它可能 suppressed/dropped 在你的 node.js 交互中的某个地方),而是而不是无声的失败;不过,上述方法可能会解决问题。