鉴于此数据结构
@prefix core <http://www.w3.org/2004/02/skos/core#>
<http://localhost/myvocab/1> core#notation 1 .
<http://localhost/myvocab/1> <http://www.w3.org/2006/time#inDateTime> <http://localhost/myvocab/item1#DateDescription> .
<http://localhost/myvocab/item1#DateDescription> <http://www.w3.org/2006/time#year> 2016 ;
<http://www.w3.org/2006/time#month> "June"
如果我跑
select * where {?s ?p ?o .
<http://www.w3.org/2004/02/skos/core#notation> 1 . }
然后只返回前两个三元组(:hasID
和:hasTime
)。是否存在sparql查询(最好不使用正则表达式过滤器来匹配id)以从子命名空间返回所有三元组?
我希望我可以达到某种结果
-------------------------------------------------------------------------------------------------------------------------------------------------------
| s | p | o |
=======================================================================================================================================================
| <http://localhost/myvocab/item1> | <http://www.w3.org/2006/time#inDateTime> | <http://localhost/myvocab/item1#DateDescription |
| <http://localhost/myvocab/item1> | <http://www.w3.org/2004/02/skos/core#notation> | 1 |
| <http://localhost/myvocab/item1#DateDescription> | <http://www.w3.org/2006/time#month> | "June" |
| <http://localhost/myvocab/item1#DateDescription> | <http://www.w3.org/2006/time#year> | 2016 |
-------------------------------------------------------------------------------------------------------------------------------------------------------
答案 0 :(得分:2)
如果您提供我们可以实际加载的数据以及您尝试过的属性形成的查询,这总是有帮助的。您显示的数据实际上并不合法,您提供的查询也不合法。以下是一些实际可加载的示例数据:
@prefix core: <http://www.w3.org/2004/02/skos/core#>
<http://localhost/myvocab/1> core:notation 1 ;
<http://www.w3.org/2006/time#inDateTime> <http://localhost/myvocab/item1#DateDescription> .
<http://localhost/myvocab/item1#DateDescription> <http://www.w3.org/2006/time#year> 2016 ;
<http://www.w3.org/2006/time#month> "June"
如果我理解你,你也想要遵循:item1_DateTime对象的属性。您可以使用以下属性路径执行此操作:item1&#39; s属性和值,依此类推。在此查询中,我使用(:|!:)作为通配符,因为每个属性都是:或者它不是。最后的 * 表示遵循任意长度的路径。
prefix core: <http://www.w3.org/2004/02/skos/core#>
select ?s ?p ?o where {
?s_ core:notation 1 ;
(<>|!<>)* ?s .
?s ?p ?o .
}
--------------------------------------------------------------------------------------------------------------------------------------------------
| s | p | o |
==================================================================================================================================================
| <http://localhost/myvocab/1> | <http://www.w3.org/2006/time#inDateTime> | <http://localhost/myvocab/item1#DateDescription> |
| <http://localhost/myvocab/1> | core:notation | 1 |
| <http://localhost/myvocab/item1#DateDescription> | <http://www.w3.org/2006/time#month> | "June" |
| <http://localhost/myvocab/item1#DateDescription> | <http://www.w3.org/2006/time#year> | 2016 |
--------------------------------------------------------------------------------------------------------------------------------------------------