问题
The problem is how to calculate the distance between two nodes (concepts) in a Triple Store (RDF) using sparql queries without know the type of edges. Essencially, is to use Dijkstras_algorithm to find the shorter path between two concepts in a Triple Store.
It is possible if we know the type of egde: Calculate length of path between nodes?
One other solution is to use classes distances(do not work if concepts are not extended from the main classes): Measuring distances among classes in RDF/OWL graphs
Example:
Find the shorter distance between http://bioinformatics.ua.pt/coeus/resource/uniprot_P01008 and http://bioinformatics.ua.pt/coeus/resource/go_GO:0005576
回答1:
You can use the same technique that's used in Calculate length of path between nodes?, but you'll need to use a wildcard instead of a particular property. The pattern (<>|!<>)
is a wildcard, because every property is either <>
or it isn't. You could also use (:|!:)
, but that will only work if you have a :
prefix defined. (<>|!<>)
will always work. Here's an example:
@prefix : <urn:ex:>
:a :p :b .
:b :q :c .
:c :r :d .
:d :s :e .
prefix : <urn:ex:>
select ?start ?end (count(?mid) as ?length) {
?start (<>|!<>)* ?mid .
?mid (<>|!<>)+ ?end .
}
group by ?start ?end
------------------------
| start | end | length |
========================
| :a | :b | 1 |
| :a | :c | 2 |
| :a | :d | 3 |
| :a | :e | 4 |
| :b | :c | 1 |
| :b | :d | 2 |
| :b | :e | 3 |
| :c | :d | 1 |
| :c | :e | 2 |
| :d | :e | 1 |
------------------------
来源:https://stackoverflow.com/questions/31048247/calculate-length-of-path-betwen-nodes-with-unknown-edges