Finding shortest path with SPARQL query

后端 未结 2 670
后悔当初
后悔当初 2021-01-01 00:25

I am trying to understand the computational limitations of the SPARQL query, and I would like know how to write a query that will determine if there is a directed path betwe

相关标签:
2条回答
  • 2021-01-01 00:30

    AndyS gave all the elements to answer this question, but there are some typos that might make it hard to apply them. As he says:

    SPARQL 1.1 has property path which includes the * operator for any number of.

    It does not tell you what the path is nor the length of the shortest path - only whether there is such a path.

    The way to do this (based on AndyS, but with two little fixes) is:

    PREFIX : <http://graphtheory/>
    PREFIX node: <http://graphtheory/node/>
    
    ASK { node:1 :hasNeighbor* node:2 }
    

    As far as I can tell, there is no way to do this without using property paths.

    0 讨论(0)
  • 2021-01-01 00:40

    SPARQL 1.1 has property paths which include the * operator for “any number of”.

    It does not tell you what the path is nor the length of the shortest path—only whether there is such a path.

    PREFIX : <http://graphtheory/node/>
    PREFIX node: <http://graphtheory/node/>
    
    ASK { node:1 :hasNeighbor* node:2 }
    

    (You don't need the ?a = and ?d =, you can write the values into the query.)

    Adding a path datatype into the language is a place for future work—a few experimental systems have taken a look at the problem.

    0 讨论(0)
提交回复
热议问题