SPARQL 查询给出意外结果

发布于 2024-08-08 12:39:18 字数 2230 浏览 7 评论 0原文

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

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

 @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 查询演示也没有。

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

I hope someone can help me on this probably totally easy-to-solve problem:

I want to run a SPARQL query against the following RDF (noted in N3, the RDF/XMl sits here). This is the desription of a journal article and descriptions of the journal, author and publisher:

 @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 .

For testing purposes I wanted to read out the foaf:homepage of ex:zlb - the SPARQL I want to run is:

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
}

(Again: This is gonna be for testing only since there is only one entity of article.)

Running it on my local machine with Python and RDflib doesn't give me a result. Neither does the Online Redland SPARQL Query Demo.

Anyone out there who sees a solution? Am I on the right path or totally wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七度光 2024-08-15 12:39:18

我认为您不能在 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 属性值中的 QNames,看看是否可以解决您的问题。

I don't think that you can use a QName in an XML attribute value; e.g. the value of rdf:about. So consider this line from your RDF/XML file:

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

I think that this is actually saying that the subject URI is "ex:bibdienst". That is a syntactically valid URI, but it is not the same URI as appears as the object of the triple corresponding to this line:

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

Try replacing the QNames in XML attribute values with the corresponding URIs and see if that fixes your problem.

破晓 2024-08-15 12:39:18

是的,Stephen C 是完全正确的,您不能在 XML 属性中使用 QName,您可以使用 XML 实体,而不是您在文档顶部的 DTD 块中定义的实体,如下所示

<!DOCTYPE rdf:RDF[
    <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
    <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
    <!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>
    <!ENTITY ex 'http://example.org/thesis/'>
    <!ENTITY dc 'http://purl.org/dc/elements/1.1/'>
    <!ENTITY foaf 'http://xmlns.com/foaf/0.1/'>
    <!ENTITY bibo 'http://purl.org/ontology/bibo/'>
]>

然后你可以像这样定义属性:

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

Yep Stephen C is totally correct that you can't use QNames in XML attributes, you can use XML entities instead which you define in a DTD block at the top of your document like so:

eg.

<!DOCTYPE rdf:RDF[
    <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
    <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
    <!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>
    <!ENTITY ex 'http://example.org/thesis/'>
    <!ENTITY dc 'http://purl.org/dc/elements/1.1/'>
    <!ENTITY foaf 'http://xmlns.com/foaf/0.1/'>
    <!ENTITY bibo 'http://purl.org/ontology/bibo/'>
]>

Then you can define attributes like so:

<bibo:Journal rdf:about="&ex;bibdienst">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文