我试图使用从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
遵循以下代码:
<?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>谢谢。
发布于 2018-04-21 19:55:40
你把SPARQL 1.1协议和SPARQ1.1.1图形存储HTTP协议混为一谈。
不同之处在于,后者不使用SPARQL查询对RDF图执行操作。
对于每个协议,Fuseki都公开两个URI:用于读操作和写操作。

因此,如果您想使用SPARQ1.1GraphStoreHTTPProtocol,您应该编写:
$gs = new EasyRdf_GraphStore('http://localhost:3030/test/data');而不是
$gs = new EasyRdf_GraphStore('http://localhost:3030/test/update');如果您需要使用SPARQ1.1Protocol,请编写如下内容:
<?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();
?>资料来源:
有关一些详细信息,请参见这个答案。
https://stackoverflow.com/questions/49958702
复制相似问题