Two filters in one query & nested queries #3205
-
Hi, I've included both questions in one post, because both problems are related to the same set of code, so I thought it would be easier to include both in one discussion. Two filters in a SPARQL query [Block of code]
which gives me the following query:
However, the query I would like is this:
How can I achieve this? Nested queries Related to the above queries, if I would like to create a nested query that looks something like this:
The same [Block of code] referred to above can be used for this query, I just didn't know how to get it to work. I tried something below and it didn't achieve what I wanted it to (it is incomplete and only tackles the second part of the query, not the first):
Any help would be appreciated, sorry if the questions are tedious, I'm still getting familiar with rdf4j and am a beginner in coding! Thank you :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I am actually not entirely sure how you can create more than one filter clause in the same group graph pattern. It should be possible, but it looks as if the SparqlBuilder simply assumes that there will alway only one filter clause. I'm either overlooking something, or this is a bug (or at least a shortcoming). A workaround is just to put your constraints in the single filter clause: .filter(Expressions.and(endDateGreaterThan, startDateLessThan, Expressions.equals(otherPrice, price)))); Doesn't give you exact result you're after, but the meaning of the query is the same. As for your second question, assuming that what you're struggling with is getting the subselect to work, have a look at this code example: https://github.com/eclipse/rdf4j/blob/main/core/sparqlbuilder/src/test/java/org/eclipse/rdf4j/sparqlbuilder/examples/sparql11spec/Section12Test.java . As a matter of fact, the entire directory https://github.com/eclipse/rdf4j/blob/main/core/sparqlbuilder/src/test/java/org/eclipse/rdf4j/sparqlbuilder/examples/sparql11spec might be of interest to you. It shows usage example for all queries in the official SPARQL Recommendation (https://www.w3.org/TR/sparql11-query/), section by section. |
Beta Was this translation helpful? Give feedback.
I am actually not entirely sure how you can create more than one filter clause in the same group graph pattern. It should be possible, but it looks as if the SparqlBuilder simply assumes that there will alway only one filter clause. I'm either overlooking something, or this is a bug (or at least a shortcoming).
A workaround is just to put your constraints in the single filter clause:
Doesn't give you exact result you're after, but the meaning of the query is the same.
As for your second question, assuming that what you're struggling with is getting the subselect to work, have a look at…