I want to traverse graph starting from any "root" concept and getting down to its leaf concepts moving by reified predicates of certain type (e.g. hasChild
only).
I have a large graph in which Concepts C
are connected with named predicates R
.
Predicates are in turn attached to blank nodes B
which hold their meta data, including connection type CT
.
Essentially the pattern is:
root_concept -[^subject]-> blank -[object]-> concept -[^subject]-> blank -[object]-> concept -[^subject]-> blank -[object]-> ...
And I want to get all downstream concepts.
So normally you would do something like (1):
SELECT ?c
WHERE {
FILTER( ?root = <SomeValue> ) .
?root (^rdf:subject/rdf:object)* ?c .
}
But I need to get intermediate blank node B
and filter on its CT
!
For a single step this looks like (2):
SELECT ?c
WHERE {
FILTER( ?root = <SomeValue> ) .
?root ^rdf:subject ?blank .
?blank rdf:object ?c .
?blank :hasRelationType "hasChild" .
}
Question: How to merry (1) and (2)?
Additional info:
Each blank node has at least these triples:
1 blank1 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://some/ontology/terms/Relationship
3 blank1 http://www.w3.org/1999/02/22-rdf-syntax-ns#object C2
4 blank1 http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate R
5 blank1 http://www.w3.org/1999/02/22-rdf-syntax-ns#subject C1
6 blank1 http://some/ontology/terms/hasRelationType NotHasChild (!)
Predicates represented by blank
nodes B actually have their own IDs, but they are completely uninformative (i.e. rdf:predicate
from blank nodes leads to something like R0134235
)
I have tried modeling my query based on arbitrary length property paths, and general recipe for getting all child properties, but couldn't figure that out.