简体   繁体   English

在SPARQL查询中遵循名称空间

[英]Following namespaces in SPARQL query

Given this data structure 给定这种数据结构

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

If I run 如果我跑步

select * where {?s ?p ?o . 
                    <http://www.w3.org/2004/02/skos/core#notation> 1 . }

then only the first 2 triples ( :hasID and :hasTime ) are returned. 那么仅返回前两个三元组( :hasID:hasTime )。 Is there a sparql query (preferably not using a regex filter for matching the id) to return all triples from the child namespaces too? 是否有一个sparql查询(最好不使用正则表达式过滤器来匹配ID)也要从子名称空间返回所有三元组?

I'm hoping I can achieve a result something along the lines of 希望我可以达到以下目标

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

It always helps if you provide data that we can actually load and property formed queries that you've tried. 如果您提供了我们可以实际加载的数据以及您尝试过的属性形式的查询,那么它总是有帮助的。 The data that you've shown isn't actually legal, nor is the query that you provided. 您显示的数据实际上并不合法,您提供的查询也不合法。 Here's some sample data that's actually loadable: 以下是一些实际可加载的示例数据:

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

If I understand you, you want to follow the :item1_DateTime object's properties too. 如果您了解我的话,那么您也想遵循:item1_DateTime对象的属性。 You can do that with a property path that follows :item1's properties and value, and so on. 您可以通过遵循:item1的属性和值等的属性路径来实现。 In this query, I use (:|!:) as a wildcard, since every property is either : or it isn't. 在此查询中,我将(:|!:)用作通配符,因为每个属性都是或不是。 The * at the end means to follow paths of arbitrary length. 末尾的*表示遵循任意长度的路径。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM