You could use federated queries to return the sub query -- this is probably not efficient but might provide a starting point for futher investigation.
If you are doing this in code you could use the QueryBuilder ( https://jena.apache.org/documentation/extras/querybuilder/) and pass the sub query to the outer query. Claude On Mon, Apr 24, 2017 at 1:02 AM, Simon Schäfer <m...@antoras.de> wrote: > Hello, > > I have complex SPARQL queries, which I would like to divide into several > parts (like function definitions), in order to reuse these parts among > different SPARQL queries and in order to make a single SPARQL query easier > to understand. What are my options to achieve this? > > I had a look at Jenas built in functionality to support user defined > function definitions. The problem with them is that it seems that they can > be used only for simple functionality like calculating the max of two > integers. But I have quite complex functionality, which I don't want to > rewrite in Java. Example: > > ------------------------------------------------------------ > ------------------------------------ > select * where { > ?s a ?tpe . > filter not exists { > ?sub rdfs:subClassOf ?tpe . > filter (?sub != ?tpe) > } > } > ------------------------------------------------------------ > ------------------------------------ > > It would be great if that could be separated into: > > ------------------------------------------------------------ > ------------------------------------ > public class MyFunc extends FunctionBase1 { > public NodeValue exec(NodeValue v) { > return NodeValue.fromSparql("filter not exists {" > + " ?sub rdfs:subClassOf ?tpe ." > + " filter (?sub != ?tpe)" > + "}") ; > } > } > // and then later > FunctionRegistry.get().put("http://example.org/function#myFunc", > MyFunc.class) ; > ------------------------------------------------------------ > ------------------------------------ > > and then: > > ------------------------------------------------------------ > ------------------------------------ > prefix fun:<http://example.org/function#> > select * where { > ?s a ?tpe . > filter(fun:myFunc(?tpe)) > } > ------------------------------------------------------------ > ------------------------------------ > > Basically I'm looking for a way to call a SPARQL query from within a > SPARQL query. Is that possible? > > > -- I like: Like Like - The likeliest place on the web <http://like-like.xenei.com> LinkedIn: http://www.linkedin.com/in/claudewarren