1

I would like to determine the shortest length between the nodes and the nearest node linked to a "true" statment, and then CONSTRUCT new graph that represents the shortest length for each node. For instance (see picture below):

-----------------
| start | end   |
=================
| :1    | :1    |
| :2    | :4    |
| :5    | :5    |

nodes

Also, if I have two properties, I would like to weight one property.

For instance, the "is similar to" property is priorized on "part of". If there is no answer with the first level of similar nodes (green), look at a higher level (orange) and then look for similar "true" nodes, then higher level (red) etc.

-----------------
| start | end   |
=================
| :1    | :1    |
| :2    | :4    |
| :3    | :6    |
| :4    | :4    |
| :5    | :5    |
| :6    | :6    |
| :7    | :7    |

enter image description here

And now, if there is no solution through the first level, see the second level enter image description here

-----------------
| start | end   |
=================
| :1    | :6    |
| :3    | :6    |
| :6    | :6    |
| :7    | :7    |

Is it possible to get this result with one sparql request? For the moment, I used a quite long sparql<->python algorithm. I calculate the distance between nodes and keep the shortest lengh to create a new triple. It is clearly not optimized.

Cyril
  • 485
  • 4
  • 15
  • You already read [this](https://stackoverflow.com/questions/19587520/path-between-two-resources) ? It probbaly already contains the answer, you just have to transform it into a CONSTRUCT query. – UninformedUser Oct 02 '17 at 19:48
  • I read this. But it gives the length and not keep the shortest. If I use query as subquery to measure the length and another to select the max, I lose the id of the node that is in the shortest position. If we reuse the example you provided, if there is several group beginning by :a, and others beginning with :d etc., I would like just keeping the couples ?start ?end with the shortest length for each ?start node. For the moment, I use a python script to select the couples. – Cyril Oct 02 '17 at 21:39
  • Hm, can you please share the query with the subquery? – UninformedUser Oct 03 '17 at 02:04
  • I reuse the example from https://stackoverflow.com/questions/18024413/finding-all-steps-in-property-path/18032019#18032019 `prefix : select ?begin ?end min(?length) where { { select ?begin ?end (count(*) as ?length) where { # start a path ?begin :relatedTo* ?midI . FILTER NOT EXISTS { [] :relatedTo ?begin } # grab next edge ?midI :relatedTo ?midJ . # get to the end of the path. ?midJ :relatedTo* ?end . FILTER NOT EXISTS { ?end :relatedTo [] } } group by ?begin ?end} }` – Cyril Oct 03 '17 at 07:40
  • If I use `select ?begin ?end min(?length)`, there is no filter, and if I use `select ?begin min(?length)` obviously I get the right number of results but without the ?end node with the shortest length. I searched for a FILTER, but I don't know how to filter on all result by ?begin node, and keep the ?end node with the minimum ?length. – Cyril Oct 03 '17 at 07:43

0 Answers0