SparqlBuilder for Construct query with Union

94 views
Skip to first unread message

F Amer

unread,
Jan 19, 2021, 1:31:33 AM1/19/21
to RDF4J Users
Can someone point me to some examples of using SparqlBuilder to formulate Construct query of the type below ? My eventual goal is to be able to dynamically union multiple named graphs depending upon request.

construct {?s ?p ?o} where {
   { graph <http://www.example1.com> {?s ?p ?o} }
   union
   { graph <http://www.example2.com> {?s ?p ?o} }
 }

Thanks

Jeen Broekstra

unread,
Jan 19, 2021, 4:10:06 AM1/19/21
to RDF4J Users
The code should be something like this:

Variable s = var("s"), p = var("p"), o = var("o");

TriplePattern spo = s.has(p, o);
ConstructQuery q = Queries.CONSTRUCT(spo)
    .where(GraphPatterns.union(
        and(spo).from(Rdf.iri("http://example1.com")),
        and(spo).from(Rdf.iri("http://example2.com"))
    )
);


Unfortunately, there appears to be a bug in the SparqlBuilder: the above produces a syntactically illegal query (the builder neglects to put curly braces around the union arguments). This is a known bug (https://github.com/eclipse/rdf4j/issues/2614) that we haven't gotten around to fixing yet.

Cheers,

Jeen
--
You received this message because you are subscribed to the Google Groups "RDF4J Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdf4j-users...@googlegroups.com.

F Amer

unread,
Jan 20, 2021, 3:06:30 PM1/20/21
to rdf4j...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages