Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all nodes in a transitive relation - Extension

Tags:

java

sparql

jena

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.

like image 688
FJE Avatar asked Dec 11 '13 12:12

FJE


Video Answer


1 Answers

I don't think this is possible in pure SPARQL. The key to the solutions to related questions is that there's something to group by that different rows of the results. In general, I don't know if there's something that would be unique to each path that you could group by so as to get one result row per path.

However, in your particular data (and this is a an attibute of your particular data, not graphs in general), there is an attribute that distinguishes the different paths: each path contains a node which is unique to that path. That is, for each of the nodes d, e, f, and g, there is exactly one path containing the node. That means that for this particular example, you might be able to do this, if you can find a way to identify the unique node in the query. I'm not confident that that's possible either, though, since it amounts to asking the same question: "how many paths are there between ?start and x (where x is one of d, e, f, and g in this case)?"

like image 113
Joshua Taylor Avatar answered Oct 20 '22 15:10

Joshua Taylor