1

I am looking for a way to return both the parent and child in a transitive SPARQL query, and only the relations that make up the path.

The following query returns the parents and intermediate object pairs leading up to http://example.com/child, but if any of the ?parents have other containment statements then those are returned as well. This can make for a very large result set.

PREFIX  ex:   <http://example.com/>

SELECT ?parent ?child
WHERE {
    ?parent ex:contains+ <http://example.com/child> .
    ?parent ex:contains ?child
}

Is there a way to both bind the terminal object in a transitive query to a specific resource, and also return the object in each relation, but not all the other ex:contains relations for each parent?

For example, with the following graph:

ex:root ex:contains ex:rootchild1
ex:root ex:contains ex:rootchild2
ex:rootchild1 ex:contains ex:intermed
ex:intermed ex:contains ex:child

The result would be:

ex:root ex:rootchild1
ex:rootchild1 ex:intermed
ex:intermed ex:child

I am running this query with Jena and Fuseki. Thanks!

Ben Pennell
  • 449
  • 1
  • 3
  • 13

0 Answers0