Joep van Genuchten
Joep van Genuchten

Reputation: 93

How stop property path on a certain condition?

I would like to be able to find all the resources that are an arbitrary path length removed from the resource I'm interested in, until there is a resource that meets a certain condition.

This question is very similar to this one but extends it to the situation where the property is reflexive.

As an example, take the following triples:

@prefix : <https://www.example.com#> .

:0 a :node ;
   :path :3 . 

:1 :path :2 ;
   a :node .
   
:2 a :node ;   
   :path :1, :3 , :4 .

:3 a :node ;
   :path :2 , :0 ;
   :value true . 

:4 a :node ;
   :path :2, :5 . 

:5 a :node ;
   :path :4 , :6 ;
   :value  true .

:6 a :node ;
   :path :5 , :7 .

:7 a :node ;
   :path :6 , :8 ; 
   :value true . 

:8 a :node ;
   :path :7 , :9 . 

:9 a :node ;
   :path :8.

Starting at :1, I would like to find all resources that have a :path* property path to it, but not any have :value true or any resource that sits 'behind' those resources.To visualize:

graph

So I'm looking for the query that returns:

The solution proposed here will not work because it relies on the fact that the properties in the example only go in one direction.

I have tried (many... more than I can recount here unfortunately) variations of

prefix : <https://www.example.com#>

select distinct ?o 
    where {
        :1 :path* ?o .
        minus {?s :value true.} 
        minus {?o :value true. } 
}

But this of course will only remove the resources with :value true, not stop 'tracing' from there.

I also figured I could try working with sub queries, first removing the resources with :value true and then running the property path on the remaining triples, but I didn't get that to work in the sense that the proprty path would still return resources sitting 'behind' resources with :value true (probably due to a lack of sparql wizardry on my part)

Any help or hints would be much appreciated!

Upvotes: 3

Views: 64

Answers (0)

Related Questions