首页 文章

EasyRDF - SPARQL查询DBpedia - “未定义的名称空间前缀”错误

提问于
浏览
0

这是我的第一个问题 . 我正在制作一个简单的程序来查询DBpedia . 我使用PHP API EasyRdf RDF Library for PHP .

SPARQL查询是正确的;它在http://dbpedia.org/snorql上工作正常 . 我可以使用查询API示例;这也是对的 . 我 prefixdbofoafrdfs ......

但是,当我使用此查询 ?person dbo:birthPlace :Berlin . 时,我有这个错误:

致命错误:未捕获异常'EasyRdf_Exception',消息'SPARQL查询的HTTP请求失败:Virtuoso 37000错误SP030:SPARQL编译器,第4行:''之前'未定义的名称空间前缀 . ' SPARQL查询:定义sql:big-data-const 0 PREFIX foaf:PREFIX rdfs:PREFIX dbo:SELECT?name?person WHERE {?person a dbo:MusicalArtist . 人dbo:birthPlace:柏林 . ?人员:名字?姓名 . ?人rdfs:评论?描述 . ORDER BY?name'在D:\ xampp \ htdocs \ HelloComposer \ lib \ EasyRdf \ Sparql \ Client.php:290堆栈跟踪:#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?'名字?p ...')#290 在第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>

请帮我 .

2 回答

  • 0

    通过DBpedia SNORQL interface进行测试时,会自动预定义几个前缀,以使CURI更容易 -

    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相同的定义,以列出您列出的所有前缀和.1140879_列出的所有前缀 .

    对于此查询,您只需要三个来自SNORQL 's list (but including all ten won' t导致任何问题),加上 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/');
    
  • 0

    好 . 错误结束了 . 什么时候可以使用PHP和EasyRDF来查询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/');
    

相关问题