Is it possible to count the number of the edges that connect two instance with a SPARQL query? I want to find a path.
相关问题
- Creating a SPARQL parameterized query using append
- Getting list of persons using SPARQL dbpedia
- Getting list of persons using SPARQL dbpedia
- How can I optimize a SPARQL query that returns opt
- Calculate the depth of subclass in the OWL ontolog
相关文章
- The difference between blank nodes and variables i
- How to display alert box when no json value is giv
- How to turn a SPARQL/SPIN query/rule into an RDF s
- Meaning of owl:hasValue?
- boundary for arbitrary property path in SPARQL 1.1
- sparql complete tree from subject
- Jena Fuseki assembler file + TDB + OWL reasoner
- How to get abstract and thumbnail of a Wikipedia a
You count the number of edges in a unique path using SPARQL's property paths and aggregate functions. For instance, with data like this, which contains two paths that we care about (a to c with two edges, and d to g with three edges):
you can use a query like the following one. Notice that I've used the specific property
:p
, rather than a variable. This is necessary, because 9.1 Property Path Syntax from the SPARQL 1.1 specification doesn't allow variables in property paths.and get results like this:
A fuller description of what's happening here can be found in:
The basic idea, though, is that if you have a path from
?start
to?end
, then you've also got, for a bunch of different values of?mid
, a path from?start
to?mid
and a path from?mid
to?end
. The number of different values that you can pick for?mid
(if you allow one of the endpoints, and disallow the other) is exactly the length of the path.