Length of path between nodes, allowing for multiple relation types (SPARQL) -
i have write sparql query returns length of path between 2 nodes (:persa , :persd) connected these relationships:
@prefix : <http://www.example.org/> . :persa :knows :knowrelation1 . :knowrelation1 :hasperson :persb . :persb :knows :knowrelation2 . :knowrelation2 :hasperson :persc . :persc :knows :knowrelation3 . :knowrelation3 :hasperson :persd . i tried query:
prefix : <http://www.example.org/> select (count(?mid) ?length) { :persa (:knows | :hasperson)* ?mid . ?mid (:knows | :hasperson)+ :persd . } the result seems infinite loop.
any advice/examples of how can done?
after fixing syntax errors in initial post, provided triples , query work me in graphdb free 8.2 , blazegraph 2.1.1. have since applied these edits post itself.
- added trailing
/definition of empty prefix - added trailing
.prefix definition line (required if want start@) - fixed spelling of length (ok, that's cosmetic fix)
.
@prefix : <http://www.example.org/> . :persa :knows :knowrelation1 . :knowrelation1 :hasperson :persb . :persb :knows :knowrelation2 . :knowrelation2 :hasperson :persc . :persc :knows :knowrelation3 . :knowrelation3 :hasperson :persd . .
prefix : <http://www.example.org/> select (count(?mid) ?length) { :persa (:knows|:hasperson)* ?mid . ?mid (:knows|:hasperson)+ :persd } result:
length "6"^^xsd:integer 
Comments
Post a Comment