1

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.

Sinbud
  • 40
  • 5
  • 1
    https://stackoverflow.com/q/38641984, https://stackoverflow.com/a/49352066 – Stanislav Kralin Jan 21 '23 at 07:33
  • I see, so I either need to introduce `tmp` predicates or use smth like SPARQL-BI. I would like to try the second approach, but the only tutorial for `~BI` I have found (http://virtuoso.openlinksw.com/DAV/virtuoso2.openlinksw.com/content/sparql-tutorials.html) does not load for some reason. – Sinbud Jan 21 '23 at 12:16
  • Also, I am not sure if adding `tmp` predicates would be more efficient (and safer) than just running queries recursively given that the subgraph is of decent size (millions of nodes) and is part of a much larger graph. – Sinbud Jan 21 '23 at 12:17

0 Answers0