1

I have RDF like this:

<companyA> <heldBy> "companyB" .
<companyA> <heldBy> "companyC" .
<companyB> <heldBy> "companyD" .

It's a stockholder relation, what I wanna do is to query all holders of companyA and mark them by level.

For example, companyB is level 1, companyD is level 2.

How can I do this with sparql? Or is it doable with sparql?

Thanks for the help!


According to the comment section, I think this might be doable with querying all holders with select ?holder where { <companyA> <heldBy>+ ?holder }.

Then calculate the length of the path to these nodes, sort them into levels.

Might even do this with SPARQL only, working on it.

Thanks again for the help!

Mage Front
  • 21
  • 3
  • 3
    Possible duplicate of [Calculate length of path between nodes?](https://stackoverflow.com/questions/5198889/calculate-length-of-path-between-nodes) – Jeen Broekstra Aug 17 '18 at 04:41
  • 1
    Recursive query is easy, just use a one-or-more property path expression: `{ + ?holder }`. To get the levels is more tricky though. See the related question (linked above) for a solution to that. – Jeen Broekstra Aug 17 '18 at 04:43
  • I notice that the predicates above are all literals. If that's accurate, you're going to run into trouble. You'll want those to be URIs instead. – TallTed Aug 17 '18 at 18:09
  • 1
    @JeenBroekstra That answer is very helpful, I think I can use `{ + ?holder }` to get all nodes first then calculate their length of path later. Thank you sir. – Mage Front Aug 18 '18 at 03:10

0 Answers0