Mag*_*rek 4 collections rdf semantic-web sparql
我有一个RDF文件rdf:collection.当我有一个作者的集合时,以下查询不返回任何内容.但是,该查询适用于两个或更多作者,但只返回两个作者.我能做些什么来写出所有作者?
<bibo:authorList rdf:parseType="Collection">
<rdf:Description rdf:about="http://openlibrary.org/authors/OL113143A"/>
<rdf:Description rdf:about="http://openlibrary.org/authors/OL6784959A"/>
</bibo:authorList>
Run Code Online (Sandbox Code Playgroud)
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dc: <http://purl.org/dc/terms/>
select ?title ?author ?author2
where {
?x dc:title ?title .
?x bibo:authorList ?object.
?object rdf:first ?name.
?name rdf:value ?author.
?object rdf:rest ?object2.
?object2 rdf:first ?name2.
?name2 rdf:value ?author2 .
}
Run Code Online (Sandbox Code Playgroud)
您的问题是您尝试半递归,因此您的结果会根据RDF列表的长度而有所不同.写入的查询仅适用于长度为2或更长的列表,长度为1的列表将不起作用,因为查询的第二部分将无法匹配.
如果要访问集合,最好的方法是使用类似的属性路径(需要SPARQL 1.1):
SELECT * WHERE
{
?list rdf:rest*/rdf:first ?member .
}
Run Code Online (Sandbox Code Playgroud)
您可以根据需要调整此常规模式以适合您的查询.
| 归档时间: |
|
| 查看次数: |
1088 次 |
| 最近记录: |