Hi Zalan,

On 26/09/2020 06:35, Zalan Kemenczy wrote:
Hi,

I'm attempting to programmatically construct the various forms of sparql
queries using Jena.

I can construct SELECT queries easily enough by composing algebraic Ops
together. I convert them to queries using OpAsQuery, and then pass the
resulting Query object directly to QueryExecutionFactory. This produces the
expected results.

However, I've had a harder time understanding how to incorporate algebraic
Ops into CONSTRUCT and UPDATE queries. The only solution I've found so far
is via the various query builder classes (ConstructBuilder, UpdateBuilder,
etc...). After converting the Ops to a Query using OpAsQuery, I wrap the
Queries as a WhereHandler, and pass the WhereHandler into the the query
builder using builder.addALL(...) or builder.getWhereHandler().addAll(...).
I then add some construct, install or delete triples to get the final
Query. This Query is then run via QueryExecutionFactory.
>
MAIN QUESTION: What is the recommended way to add algebraic Ops (that
represent the where clause) to CONSTRUCT or UPDATE queries?

Another similar way is to create a SELECT query, use Query.getQueryPattern and then use Query.setQueryPattern on CONSTRUCT query you want or on a UpdateModify. The query structure isn't modified during execution so sharing is safe.

My approach produces queries that usually work, but I'm occasionally seeing
some odd behaviour. For example, certain more complex construct queries
don't always return the expected results: but serialize the Query object to
a sparql file, read it back, and then run via QueryExecutionFactory, and
suddenly it returns the expected construction.

Do you have an example, ideally reduced to a small example?

It is possible to build algebra structures that do not correspond to any query syntax and OpAsQuery only tries reverse legal queries. Also, OpAsQuery is a pragmatic process - it may be getting something wrong that outputs a string and reading it back in again unwittingly fixes up.

For these queries, is "Algebra.compile(query)" the same as the input algebra?

    Andy


Thanks for all your time and effort!

Zalan

Reply via email to