My data which simply denotes two paths from :a
to :v
and k
respectively is as follows:
@prefix : <http://m/questions/19587520/sparql-path-between-two-instance/> .
:a :z :d.
:d :p :e .
:e :g :f .
:f :l :g .
:g :m :h .
:h :p :k .
:k :p :c .
:c :p :v .
:a :p :x.
:x :q :y.
:y :z :c.
:a :l :g .
:g :m :h .
:h :p :k .
The SPARQL queries that I tried are
String querygraph=
"PREFIX : <http://m/questions/19587520/sparql-path-between-two-instance/>" +
"SELECT ?start ?end (count(?mid) as ?length)" +
"WHERE {" +
" values (?start ?end) { (:a :c) " +
" } " +
" ?start (: |!:)+ ?mid . " +
" ?mid (: | !:)* ?end . " +
" } " +
" group by ?start ?end " +
" ORDER BY ASC(?length)";
String querygraph1=
"PREFIX : <http://monika/questions/19587520/sparql-path-between-two-instance/>" +
"select (count(?m) as ?length) " +
"WHERE {" +
" values (?s ?d) { (:a :c) " +
" } " +
"?s (:|!:)+ ?m ."+
" ?m (: | !:)* ?d . " +
"}" ;
In this I need to print and calculate length of path but the problem is there are two paths from :a
to :c
. My code is not able to differentiate between them, it calculates it as one. Please help me to print both paths separately with their length.