首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在PHP中插入Jena Fuseki SPARQL (EasyRDF库)

在PHP中插入Jena Fuseki SPARQL (EasyRDF库)
EN

Stack Overflow用户
提问于 2018-04-21 17:59:00
回答 1查看 1.1K关注 0票数 2

我试图使用从EasyRDF库运行示例代码,但是当将数据输入数据库时会发生以下错误:

致命错误:在D:\Files\xampp\htdocs\test\easyrdf-0.9.0\lib\EasyRdf\GraphStore.php:152堆栈跟踪:#0D:\xampp\\D:\Files\xampp\htdocs\test\easyrdf-0.9.0\lib\EasyRdf\GraphStore.php:152堆栈跟踪中,带有消息' HTTP :// EasyRdf_Exception失败:必须是application/sparql或application/xampp form-urlencoded (got application/n-triples)‘的未命名异常'EasyRdf_Exception’。htdocs\test\easyrdf-0.9.0\lib\EasyRdf\GraphStore.php(217):EasyRdf_GraphStore->发送图(‘POST’,对象(EasyRdf_Graph)、'time.rdf‘、'ntriples') #1 D:\Files\xampp\htdocs\test\graphstore.php(34):EasyRdf_GraphStore->insert(Object(EasyRdf_Graph),'time.rdf') #2 {main}抛入第152行的D:\Files\xampp\htdocs\test\easyrdf-0.9.0\lib\EasyRdf\GraphStore.php

遵循以下代码:

代码语言:javascript
复制
<?php
    set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
    require_once "easyrdf-0.9.0/lib/EasyRdf.php";
?>
<html>
<head>
  <title>GraphStore example</title>
</head>
<body>

<?php
  // Use a local SPARQL 1.1 Graph Store (eg RedStore)
  $gs = new EasyRdf_GraphStore('http://localhost:3030/test/update');

  // Add the current time in a graph
  $graph1 = new EasyRdf_Graph();
  $graph1->add('http://example.com/test', 'rdfs:label', 'Test');
  $graph1->add('http://example.com/test', 'dc:date', time());
  $gs->insert($graph1, 'time.rdf');

  // Get the graph back out of the graph store and display it
  $graph2 = $gs->get('time.rdf');
  print $graph2->dump();
?>

</body>
</html>

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-21 19:55:40

你把SPARQL 1.1协议SPARQ1.1.1图形存储HTTP协议混为一谈。

不同之处在于,后者不使用SPARQL查询对RDF图执行操作。

对于每个协议,Fuseki都公开两个URI:用于读操作和写操作。

因此,如果您想使用SPARQ1.1GraphStoreHTTPProtocol,您应该编写:

代码语言:javascript
复制
$gs = new EasyRdf_GraphStore('http://localhost:3030/test/data');

而不是

代码语言:javascript
复制
$gs = new EasyRdf_GraphStore('http://localhost:3030/test/update');

如果您需要使用SPARQ1.1Protocol,请编写如下内容:

代码语言:javascript
复制
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . 'easyrdf-0.9.0/lib/');
require_once "EasyRdf.php";

$endpoint = new EasyRdf_Sparql_Client('http://localhost:3030/test/query',
                                      'http://localhost:3030/test/update');

function insert_data() {
    global $endpoint;
    $result = $endpoint->update("
        PREFIX : <http://example.org/> 
        INSERT DATA {:alice :knows :bob. :alice :name 'alice'. :bob :name 'bob'}"
    );
}
function insert_where() {
    global $endpoint;
    $result = $endpoint->update ("
        PREFIX : <http://example.org/> 
        INSERT {?s :loves ?o}
        WHERE {?s :name 'bob'. ?o :name 'alice'}"
    );
}
function select_where() {
    global $endpoint;
    $result = $endpoint->query("
        SELECT * WHERE {?s ?p ?o}"
    );
    print ($result->numRows()); 
}

insert_data();   select_where();
insert_where();  select_where();

?>

资料来源:

有关一些详细信息,请参见这个答案

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49958702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档