duanfen9090 2014-11-10 17:27 采纳率: 100%
浏览 141
已采纳

带有ARC2 PHP库的SPARQL INSERT

I am trying to execute an INSERT on a SPARQL endpoint in PHP using the ARC2 library. This fails with the error "Could not properly handle " PREFIX dc:"

The SPARQL UPDATE query is taken from the W3C specification and works just fine on my Jena-Fuseki control panel:

$query = '
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
    INSERT DATA
    { 
        <http://example/book007> dc:title "A new book" ;
                         dc:creator "A.N.Other" .
    }
';

But even variations of the query without a PREFIX statement just result in a similar error "Could not properly handle " INSERT DATA {" in my PHP code.

My PHP code is as follows:

include_once('./lib/arc2/ARC2.php');

$config = array(
  //db
  'db_name' => 'arc2',
  'db_user' => 'root',
  'db_pwd' => '-',
  //store
  'store_name' => 'arc_tests'
);
$store = ARC2::getStore($config);
if (!$store->isSetUp())
  $store->setUp();

$res = $store->query($query);
echo var_dump($store->getErrors());
echo "<br><br>executed INSERT, returned: ";
echo var_dump($res);

This version is using a native ARC2 store to reduce potential error sources. I am actually trying to interact with a remote store:

$config = array( 'remote_store_endpoint' => 'http://localhost:3030/data/update', );
$store = ARC2::getRemoteStore($config);

Both give me the same error, however.


In the end I want to connect to the remote SPARQL endpoint of my Jena Fuseki server and interactively insert and retrieve data with that in PHP. If you have any other libraries or clean solutions how to interact through the SPARQL protocol in PHP, I am happy to change my approach.

  • 写回答

1条回答 默认 最新

  • dongnu4254 2014-11-10 17:50
    关注

    It seems, ARC2 does not support SPARQL 1.1 parsing.

    Instead it only supports a simplified SPARQL+ for UPDATE queries. The following query successfully inserts a new triple into the ARC2 store:

    $query = 'INSERT DATA
    { 
      <http://example/book1> dc:title "A new book" ;
                         dc:creator "A.N.Other" .
    }';
    

    Unfortunately, with this limited SPARQL+ it seems impossible to do UPDATEs through a remote store on my Jena Fuseki instance. Either ARC2 is complaining about the SPARQL 1.1 conform query syntax as given in the question, or Jena Fuseki is complaining about the SPARQL+ query syntax that seems specific to ARC2.

    Any advice? I posted a new question about this: https://stackoverflow.com/questions/26858594/php-sparql-1-1-library-for-semantic-web-stack-php-sparql-jena-fuseki

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料