4

I would like to get all the paths between two nodes (subjects).

Lets say my RDF graph is:

@prefix : <urn:ex:>.

:a :relatedTo :b .
:b :relatedTo :c .
:c :relatedTo :d .

:a :relatedTo :e .
:e :relatedTo :f .
:f :relatedTo :d .

:a :relatedTo :i .
:i :relatedTo :j .
:j :relatedTo :d .

I want to get the paths between a & d.

As per the above data there are 3 paths between a & d which are.

a - b - c - d
a - e - f - d
a - i - j - d

Is it possible to achieve this using SPARQL or CTS query?

Dixit Singla
  • 2,540
  • 3
  • 24
  • 39
  • Was asked here several times. Please use the search function... – UninformedUser Jun 25 '18 at 12:01
  • @AKSW I got few but all were for if there is only `one path` between two nodes, for multiple paths I did not find any answer. It would be a great help if you please refer few answers. – Dixit Singla Jun 25 '18 at 12:16
  • Possible duplicate of [Finding all steps in property path](https://stackoverflow.com/questions/18024413/finding-all-steps-in-property-path) – RobV Jun 27 '18 at 09:26
  • @DixitSingla Does https://stackoverflow.com/questions/18024413/finding-all-steps-in-property-path/18032019#18032019 not do what you need? – RobV Jun 27 '18 at 09:26
  • this one works perfect when there is only one path between start - end node, if there are multiple paths not getting the correct results. – Dixit Singla Jun 27 '18 at 09:42
  • What output are you expecting? The only way to have one binding per step and one result per path is if you know how many bindings to attempt (i.e. you know the length or max length of the paths). If you want arbitrarily long paths, then SPARQL will necessarily only return you the components of those paths. In which case, the linked answer should work, but you'll need to do some post-processing to reconstruct the subgraph and then traverse it to read out the paths. – BenW Jun 27 '18 at 23:16

0 Answers0