It's my first question. I am making a simple program to query DBpedia. I use PHP API + EasyRdf RDF Library for PHP.
The SPARQL query is correct; it's working fine on http://dbpedia.org/snorql. I can use query for API example; it is also correct. I have prefix
with dbo
, foaf
, rdfs
...
But when I use this query with this condidion ?person dbo:birthPlace :Berlin .
, I have this error:
Fatal error:
Uncaught exception 'EasyRdf_Exception' with message 'HTTP request for SPARQL query failed:
Virtuoso 37000 Error SP030: SPARQL compiler, line 4: Undefined namespace prefix at '' before '.' SPARQL query: define sql:big-data-const 0 PREFIX foaf: PREFIX rdfs: PREFIX dbo: SELECT ?name ?person WHERE { ?person a dbo:MusicalArtist . ?person dbo:birthPlace :Berlin . ?person foaf:name ?name . ?person rdfs:comment ?description . } ORDER BY ?name' in D:\xampp\htdocs\HelloComposer\lib\EasyRdf\Sparql\Client.php:290 Stack trace: #0 D:\xampp\htdocs\HelloComposer\lib\EasyRdf\Sparql\Client.php(120): EasyRdf_Sparql_Client->request('query', 'SELECT ?name ?p...') #1 D:\xampp\htdocs\dbpedia\index.php(43): EasyRdf_Sparql_Client->query('SELECT ?name ?p...') #2 {main} thrown in D:\xampp\htdocs\HelloComposer\lib\EasyRdf\Sparql\Client.php on line 290
My PHP code --
<?php
require_once('D:\xampp\htdocs\HelloComposer\lib\EasyRdf.php');
require_once ('D:\xampp\htdocs\HelloComposer\lib\html_tag_helpers.php');
//PREFIX
EasyRdf_Namespace::set('category', 'http://dbpedia.org/resource/Category:');
EasyRdf_Namespace::set('dbpedia', 'http://dbpedia.org/resource/');
EasyRdf_Namespace::set('dbo', 'http://dbpedia.org/ontology/');
EasyRdf_Namespace::set('dbp', 'http://dbpedia.org/property/');
EasyRdf_Namespace::set('foaf', 'http://xmlns.com/foaf/0.1');
EasyRdf_Namespace::set('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
$sparql = new EasyRdf_Sparql_Client('http://dbpedia.org/sparql');
?>
<html>
<head>
<title>EasyRdf Basic Sparql Example</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>EasyRdf Basic Sparql Example</h1>
<h2>List of artists</h2>
<ul>
<?php
$result = $sparql->query(
'SELECT ?person ?name ?description WHERE {'.
' ?person a dbo:MusicalArtist .'.
' ?person dbo:birthPlace :Berlin .'.
' ?person foaf:name ?name .'.
' ?person rdfs:comment ?description . '.
' FILTER (LANG(?description) = "en") .'.
'} ORDER BY ?name'
);
foreach ($result as $row) {
echo "<li>".link_to($row->name, $row->person)."</li>\n";
}
?>
</ul>
<p>Total number of artists: <?= $result->numRows() ?></p>
</body>
</html>
Please... help me.
:
somewhere in your query? – UninformedUser:
– UninformedUser