简体   繁体   中英

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. Is there a sparql query (preferably not using a regex filter for matching the id) to return all triples from the child namespaces too?

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. You can do that with a property path that follows :item1's properties and value, and so on. 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                                             |
--------------------------------------------------------------------------------------------------------------------------------------------------

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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