is there any way to generate a SPARQL query in a dynamic way? what I'm trying to do is some thing like this: if I have a DBpedia resource r1 and another DBpedia resource r2, this query
SELECT * WHERE { <r1> ?pre <r2> }
will return the predicate between the 2 resources and this query
SELECT * WHERE { <r1> ?pre1 ?obj1 . ?obj1 ?pre2 <r2> }
will return all the predicates and object between these two resources ( in two steps) and so on I'm trying to build this query in such a way that it will automatically increase the number of objects and predicates between the two resources (for example in 4 steps)?