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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?