这是我的第一个问题我正在制作一个简单的程序来查询DBpedia。我使用PHP + PHP库EasyRdf。
SPARQL查询是正确的;它在http://dbpedia.org/snorql上运行良好。我可以对API示例使用查询;它也是正确的。我有prefix
和dbo
,foaf
,rdfs
..。
但是,当我将此查询与此条件?person dbo:birthPlace :Berlin .
一起使用时,会出现以下错误:
致命错误: 消息'HTTP for SPARQL查询的未命名异常'EasyRdf_Exception‘失败: Virtuoso 37000 Error SP030: SPARQL编译器,第4行:未定义的命名空间前缀在“.”之前SPARQL查询:定义sql:大数据-const 0前缀foaf:前缀rdfs:前缀dbo: SELECT ?name ?person其中{ ?person a dbo:MusicalArtist。?个人dbo:出生地:柏林。人名:姓名?姓名。?person rdfs:注释?描述。} D:\xampp\htdocs\HelloComposer\lib\EasyRdf\Sparql\Client.php:290堆栈跟踪中的ORDER ?name:#0 D:\xampp\htdocs\HelloComposer\lib\EasyRdf\Sparql\Client.php(120):EasyRdf_Sparql_Client->D:\xampp\htdocs\HelloComposer\lib\EasyRdf\Sparql\Client.php(120):(‘D:\xampp\htdocs\HelloComposer\lib\EasyRdf\Sparql\Client.php(120):’'SELECT ?name ?P…‘) #1 D:\xampp\htdocs\dbpedia\index.php(43):EasyRdf_Sparql_Client->查询(’SELECT ?name ?P.‘) #2 {main}抛入第290行的D:\xampp\htdocs\HelloComposer\lib\EasyRdf\Sparql\Client.php中
我的PHP代码--
<?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>
请..。帮帮我。
发布于 2017-05-01 14:18:18
在通过DBpedia SNORQL接口进行测试时,会自动预定义几个前缀,以使CURIes更容易--
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
当您尝试通过另一个工具或接口(包括但不限于EasyRDF )使用查询时,可能会出现混淆,因为大多数前缀都没有所有这些前缀的预定义--而且有些前缀字符串的扩展也可能不同!
您必须确保查询包含与SNORQL中从SNORQL列表中使用的任何前缀和所有前缀相同的定义。
对于这个查询,您只需要三个来自SNORQL的列表(但包括所有十个不会造成任何问题),再加上dbo:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
EasyRDF中的声明看起来有点不同,但是做的事情与上面在SPARQL/SNORQL中所做的一样。首先,查询所需的最低限度--
EasyRdf_Namespace::set('foaf', 'http://xmlns.com/foaf/0.1/');
EasyRdf_Namespace::set('', 'http://dbpedia.org/resource/');
EasyRdf_Namespace::set('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
EasyRdf_Namespace::set('dbo', 'http://dbpedia.org/ontology/');
-第二,你需要的全套--
EasyRdf_Namespace::set('owl', 'http://www.w3.org/2002/07/owl#');
EasyRdf_Namespace::set('xsd', 'http://www.w3.org/2001/XMLSchema#');
EasyRdf_Namespace::set('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
EasyRdf_Namespace::set('foaf', 'http://xmlns.com/foaf/0.1/');
EasyRdf_Namespace::set('dc', 'http://purl.org/dc/elements/1.1/');
EasyRdf_Namespace::set('', 'http://dbpedia.org/resource/');
EasyRdf_Namespace::set('dbpedia2', 'http://dbpedia.org/property/');
EasyRdf_Namespace::set('dbpedia', 'http://dbpedia.org/');
EasyRdf_Namespace::set('skos', 'http://www.w3.org/2004/02/skos/core#');
EasyRdf_Namespace::set('dbo', 'http://dbpedia.org/ontology/');
发布于 2017-05-01 10:40:44
好的。错误结束了。什么时候可以使用查询DBpedia,您应该记住键前缀。是PREFIX : <http://dbpedia.org/resource/>
。您可以使用这个简单的查询,只需一个声明- EasyRdf_Namespace::set('', 'http://dbpedia.org/resource/')
。但是更好的解决方案是使用一些额外的PREFIX
来执行更困难的任务。
对于EasyRDF,我建议使用以下代码:
EasyRdf_Namespace::set('owl', 'http://www.w3.org/2002/07/owl#');
EasyRdf_Namespace::set('xsd', 'http://www.w3.org/2001/XMLSchema#');
EasyRdf_Namespace::set('rdfs', 'http://www.w3.org/2000/01/rdf-schema#');
EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
EasyRdf_Namespace::set('foaf', 'http://xmlns.com/foaf/0.1/');
EasyRdf_Namespace::set('dc', 'http://purl.org/dc/elements/1.1/');
EasyRdf_Namespace::set('', 'http://dbpedia.org/resource/');
EasyRdf_Namespace::set('skos', 'http://www.w3.org/2004/02/skos/core#');
EasyRdf_Namespace::set('dbo', 'http://dbpedia.org/ontology/');
https://stackoverflow.com/questions/43710623
复制相似问题