I'm trying to get a EasyRdf_Graph
object from a query sent via EasyRdf_Sparql_Client::query
.
SELECT
andASK
queries will return an object of typeEasyRdfSparqlResult
.
CONSTRUCT
andDESCRIBE
queries will return an object of typeEasyRdf_Graph
.
Here is my code :
<?php
require APPPATH .'third_party/vendor/autoload.php';
$endpointUrl = "http://data.bnf.fr/sparql";
$dummyConstructQueryString = "construct { ?s ?q ?r } where { ?s ?p ?o . ?o ?q ?r } limit 1";
$endPoint = new EasyRdf_Sparql_Client($endpointUrl);
$result = $endPoint->query($dummyConstructQueryString);
var_dump($result);
echo $result;
?>
And here is the output, which is EasyRdf_Sparql_Result
as you can see :
object(**EasyRdf_Sparql_Result**)#47 (6) {
["type":"EasyRdf_Sparql_Result":private]=>
string(8) "bindings"
["boolean":"EasyRdf_Sparql_Result":private]=>
NULL
["ordered":"EasyRdf_Sparql_Result":private]=>
NULL
["distinct":"EasyRdf_Sparql_Result":private]=>
NULL
["fields":"EasyRdf_Sparql_Result":private]=>
array(3) {
[0]=>
string(1) "s"
[1]=>
string(1) "p"
[2]=>
string(1) "o"
}
["storage":"ArrayIterator":private]=>
array(1) {
[0]=>
object(stdClass)#48 (3) {
["s"]=>
object(EasyRdf_Resource)#49 (2) {
["uri":protected]=>
string(56) "http://www.w3.org/ns/sparql-service-description#endpoint"
["graph":protected]=>
NULL
}
["p"]=>
object(EasyRdf_Resource)#50 (2) {
["uri":protected]=>
string(47) "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
["graph":protected]=>
NULL
}
["o"]=>
object(EasyRdf_Resource)#51 (2) {
["uri":protected]=>
string(42) "http://www.w3.org/2000/01/rdf-schema#Class"
["graph":protected]=>
NULL
}
}
}
}
+-------------+----------+------------+
| ?s | ?p | ?o |
+-------------+----------+------------+
| sd:endpoint | rdf:type | rdfs:Class |
Also tried with different endpoints (http://dbpedia.org/sparql and http://localhost:3030/testFuseki) because I saw this issue : https://github.com/njh/easyrdf/issues/226, but it's the same.
Infos about install
EasyRDF version 0.9.1 installed with Composer
PHP Version 7.0.30-0+deb9u1 + Apache/2.4.25 (Debian)
Any clue would be appreciated, thanks in advance.
EDIT
Actually it works with my local install of Fuseki. Since http://data.bnf/fr/sparql and http://dbpedia.org/sparql are both Virtuoso endpoints, I wonder if the problem is only with Virtuoso.
Thanks to Ted's suggestion about the headers and updating EasyRDF, I found a solution after reading a bit more about EasyRDF issue #226. The problem is that it requires to re-write php code to use the new namespaces, etc. If anyone knows a solution with 0.9.1 version, it would be very helpful!
It seems that the returned object type (
EasyRdf_Graph
/EasyRdf_Sparql_Result
) depends on theAccept
parameter of the headers. I tried to modify it (added different content-types listed in Virtuoso doc ) via Firebug and re-send the request, but didn't get anyEasyRdf_Graph
object yet with Virtuoso.As Ted asked, here is the relevant part of request headers (with above php code and EasyRDF 0.0.1) :
In order to get the endpoint response headers, I added this line :
Here are the response headers for Fuseki (which gives an
EasyRdf_Graph
object) :And for Virtuoso (http://data.bnf.fr)
N.B. : for data.bnf.fr the code is 302 (redirection), but it doesn't seem to make any difference, see dbpedia response :
So here is the solution with new php code and composer update to get EasyRDF dev-master :
1) Edit composer.json :
2) run
3) rewrite php code :
EDIT
Finally I'm not sure that the http request headers parameter "Accept" is the condition to get an
EasyRdf_Graph
object. Here are the headers for request and response with updated Easyrdf code ("dev-master" version). Maybe EasyRDF parses the query and the result to build aEasyRdf_Graph
object.Request
Response from http://data.bnf.fr/sparql/ (obtained with
print_r(get_headers($endpointUrl));
)