ChrisW
ChrisW

Reputation: 5068

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

Upvotes: 1

Views: 561

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85813

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

Upvotes: 2

Related Questions