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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化