python - SPARQL 查询给出意外结果

标签 python rdf sparql rdflib

我希望有人能帮助我解决这个可能完全容易解决的问题:

我想针对以下 RDF 运行 SPARQL 查询(在 N3 中注明,RDF/XMl 位于 here )。这是一篇期刊文章的描述以及期刊、作者和出版商的描述:

 @prefix bibo: <http://purl.org/ontology/bibo/> .
 @prefix dc: <http://purl.org/dc/elements/1.1/> .
 @prefix ex: <http://example.org/thesis/> .
 @prefix foaf: <http://xmlns.com/foaf/0.1/> .
 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<ex:XY>     a bibo:Article;
     dc:creator ex:umstaetter;
     dc:date "2008-11-01";
     dc:isPartOf ex:bibdienst;
     dc:title "DDC in Europa"@de;
     bibo:endPage "1221";
     bibo:issue "11";
     bibo:language "de";
     bibo:pageStart "1194";
     bibo:uri <http://www.zlb.de/Erschliessung020309BD.pdf>;
     bibo:volume "42" .

<ex:bibdienst>     a bibo:Journal;
     dc:publisher ex:zlb;
     dc:title "Bibliotheksdienst"@de;
     bibo:issn "00061972" .

<ex:umstaetter>     a foaf:person;
     foaf:birthday "1941-06-12";
     foaf:gender "Male";
     foaf:givenName "Walther";
     foaf:homepage <http://www.ib.hu-berlin.de/~wumsta/index.html>;
     foaf:img "http://libreas.eu/ausgabe7/pictures/wumstaetter1.jpg";
     foaf:name "Walther Umst\u00E4tter";
     foaf:surname "Umst\u00E4tter";
     foaf:title "Prof. Dr. rer. nat." .

<ex:zlb>     a foaf:Organization;
     foaf:homepage <http://www.zlb.de>;
     foaf:name "Zentral- und Landesbibliothek Berlin"@de .

出于测试目的,我想读出 ex:zlbfoaf:homepage - 我想运行的 SPARQL 是:

PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX bibo: <http://purl.org/ontology/bibo/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX ex: <http://example.org/thesis/>

SELECT ?article ?publisher ?publisher_url
WHERE 
{
    ?article dc:isPartOf ?journal .
    ?journal dc:publisher ?publisher .
    ?publisher foaf:homepage ?publisher_url
}

(再次声明:这将仅用于测试,因为文章只有一个实体。)

使用 Python 和 RDflib 在我的本地机器上运行它没有给我结果。在线 Redland SPARQL 查询演示也没有。

有人看到了解决方案吗?我在正确的道路上还是完全错误的?

最佳答案

我认为您不能在 XML 属性值中使用 QName;例如rdf:about 的值。因此,请考虑您的 RDF/XML 文件中的这一行:

 <bibo:Journal rdf:about="ex:bibdienst">

我认为这实际上是在说主题 URI 是“ex:bibdienst”。这是一个语法上有效的 URI,但它与显示为对应于此行的三元组对象的 URI 不同:

 <dc:isPartOf rdf:resource="http://example.org/thesis/bibdienst" />

尝试用相应的 URI 替换 XML 属性值中的 QName,看看是否能解决您的问题。

关于python - SPARQL 查询给出意外结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1594518/

相关文章:

python - 这个 Python 技巧会不会有任何不明显的错误?

Python tkinter : Countdown Timer not accurate

rdf - 使 OWL 数据和对象属性成为同一属性的子属性

rdf - 按标题在 DBpedia 上进行强大的搜索

java - 检索空白节点映射

Python 三角函数返回意外值

python postgis ST_Contains 查询失败

java - 使用 Jung 去除 RDF 图死胡同

sparql - 如何在 OpenRefine 中通过 Wikipedia 文章标题进行协调?

sparql - 计数时如何获取 SPARQL 查询的默认返回值