You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by Claude Warren <cl...@xenei.com> on 2025/10/29 12:00:11 UTC

Shortest Path query

Hello,

I have a simple case where I have a single property (call it pth) that I
want to traverse as a path to discover what the shortest path from 'A' to
'B' is.  Finding that there is such a path is fairly simple: "where A
(pth*) B"

But I can not figure out how to perform a query that will find the
shortest.  I did discover that P_Shortest is not implemented in the
PathEvaluator (not sure why).

Assuming there there are triples:
a pth  x
a pth y
x pth b
y pth b
TripleNode(a pth x) cost 5
TripleNode(x pth b) cost 5
TripleNode(a pth z) cost 5
TripleNode(z pth b) cost 4

Is there any way to query to find that a -> z -> b is the shortest path?

Does anyone know if there are any SPARQL plans to support such a query?

Thanks in advance,
Claude
-- 
LinkedIn: http://www.linkedin.com/in/claudewarren

Re: Shortest Path query

Posted by Andy Seaborne <an...@apache.org>.

On 29/10/2025 12:00, Claude Warren wrote:
> Hello,
> 
> I have a simple case where I have a single property (call it pth) that I
> want to traverse as a path to discover what the shortest path from 'A' to
> 'B' is.  Finding that there is such a path is fairly simple: "where A
> (pth*) B"
> 
> But I can not figure out how to perform a query that will find the
> shortest.  I did discover that P_Shortest is not implemented in the
> PathEvaluator (not sure why).
> 
> Assuming there there are triples:
> a pth  x
> a pth y
> x pth b
> y pth b
> TripleNode(a pth x) cost 5
> TripleNode(x pth b) cost 5
> TripleNode(a pth z) cost 5
> TripleNode(z pth b) cost 4
> 
> Is there any way to query to find that a -> z -> b is the shortest path?

Not directly in standard SPARQL.

As well as no "shortest", your case uses weights, which aren't handled.

> Does anyone know if there are any SPARQL plans to support such a query?
> 
> Thanks in advance,
> Claude