1
votes

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                                            |
-------------------------------------------------------------------------------------------------------------------------------------------------------
1
What do you mean by "child namespaces"? You mean that you want to follow the properties to get year 2016 and month June as well? - Joshua Taylor
@JoshuaTaylor yeh. (So, what's the correct generic term for those?) - ChrisW
The <.../item1#DateTime> is just another resource. You're trying to get the properties/values from that resource as well (and perhaps recursively to keep following these). I don't think there's a specific term for that,but in SPARQL you can use a property path to help retrieve it. You might be interested in the term concise bounded description, which is relevant, though not exactly what you're asking for here, since <.../item#DateTime> isn't a blank node. - Joshua Taylor
You've still got a raw #notation in that data. I'm not even sure that's legal. Even if it is, what is the fragment resolved against? - Joshua Taylor
But even so, I think that the solution I posted should work on this. - Joshua Taylor

1 Answers

2
votes

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