I have an SPARQL query that mimics a zick-zack pattern like following.
?p1 :infector ?p.
?p2 :infector ?p1.
?p3 :infector ?p2.
?p4 :infector ?p3.
?p5 :infector ?p4
.................
Basically, in the pattern subject of one triple using as an object for next one. Is there any way to generalize this pattern? Therefore, I do not need to use a long list of variables (?p-?p5) in the pattern. Also, I do not know how many of such variables I need before running the query for multiple times. Hence, I can not come up with a defined set of variables. I need something generic. If you have any idea to make this query generic then please let me know. I will highly appreciate any help.
Clarification:
I have an RDF graph like following.
<http://ndssl.bi.vt.edu/chicago/dendrogram/experiment_id#7385/cell_id#86304/infectee_pid#446734805/iteration#0> <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_infector_pid> <http://ndssl.bi.vt.edu/chicago/person/pid#449563560>.
<http://ndssl.bi.vt.edu/chicago/dendrogram/experiment_id#7385/cell_id#86304/infectee_pid#446734805/iteration#0> <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_infectee_pid> <http://ndssl.bi.vt.edu/chicago/person/pid#446734805>
<http://ndssl.bi.vt.edu/chicago/dendrogram/experiment_id#7385/cell_id#86304/infectee_pid#446753456/iteration#0> <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_infector_pid> <http://ndssl.bi.vt.edu/chicago/person/pid#446734805>.
<http://ndssl.bi.vt.edu/chicago/dendrogram/experiment_id#7385/cell_id#86304/infectee_pid#446753456/iteration#0> <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_infectee_pid> <http://ndssl.bi.vt.edu/chicago/person/pid#446753456>.
.......................................................................
Following SPARQL query can fetch existing chain mentioned above RDF graph.
select * from <http://ndssl.bi.vt.edu/chicago/> where
where {
{
?s <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_infector_pid> ?o1.
?s <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_infectee_pid> ?o2
}
{
?s1 <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_infector_pid> ?o2.
?s1 <http://ndssl.bi.vt.edu/chicago/vocab/dendrogram_infectee_pid> ?o3
}
..........................................................................
}
This chain type of query contains two parts where infectee ID from first part of the query using as an infector for second part. In my query, I have lots of parts. Is there any way to generalize it? So that insetad of using so many parts I can just use one part and get the result. BTW I need path length and intermediate node information as well.