Get all nodes in a transitive relation - Extension

Viewed 242

This is an extension of Get all nodes in a transitive relation

Is it possible to get all transitive nodes between two transitive nodes using SPARQL? I tried to dig it out from this site and answer-semanticweb, but it seems that it's currently not possible if the length of the path is not defined as suggested in Can JENA ARQ show property path details. But I see a ray of hope from the Joshua Taylor answer to the first question.

[Edited] I provide the picture of my data sample to show the extent of the problem:

Data Sample

[Edited] I wanted to find the path between :a and :h, which should be resulted in four results:
a -> b -> c -> d -> h.
a -> b -> c -> e -> h.
a -> f -> h.
a -> g -> h.

[Edited] Using the solution from Joshua Taylor in the comment, I got every node grouped into single result, which is the closest solution that I got for this problem so far.

2 Answers

In case anyone else bumped into this question later, after sometime (almost 10 years!), there is a solution as an extension for path findings developed by OntoText (for GraphDB triplestore).

They extend the SPARQL property path with a few capabilities, e.g., searching for all paths (path:allPaths), shortest path (path:shortestPath), and distance (path:distance), where you can find it in the following link GraphDB path search.

Quoting from their website:

GraphDB solves this problem by extending SPARQL with the Graph Path Search functionality that allows you to not only find complex relationships between resources but also explore them and use them as filters to identify graph patterns. It includes features for Shortest path and All paths search, which enable you to explore the connecting edges (RDF statements) between resources for the shortest property paths and subsequently for all connecting paths. Other supported features include finding the shortest distance between resources and discovering cyclical dependencies in a graph.

Related