Nested Queries & two filters within one query

Skip to first unread message

Vaishali R

Jul 8, 2021, 11:20:43 AMJul 8
to RDF4J Users

Two filters within one query:
I have initialised a pattern for a query using GraphPattern, that looks something like this:

GraphPattern query3 = letter.isA(lsl.iri("letter")).
andHas(lsl.iri("field"), otherFieldStore).
filter(Expressions.and(endDateGreaterThan, startDateLessThan)).
filter(Expressions.equals(otherRent, rent));

This simply does not include the date filter and skips straight to the rent filter.

What I am trying to achieve is two separate filters like this: 
FILTER(?endDate < NOW() && ?startDate < NOW()) . 
FILTER(?otherRent = ?rent) . \

How can I achieve this?

Nested Queries:
I have initialised a number of patterns (similar to above) using GraphPattern, as I would like to write a nested query.

I have tried to do so like this:

SelectQuery combinedQuery = Queries.SELECT(field, lessCount, equalCount).where().
select(, field).

which gives me the following: SELECT ?fields ?lessCount ?equalCount ( COUNT( ?otherLetter ) AS ?equalCount ) ?field
WHERE { ?otherLetter a :Letter 

But what I am trying to achieve is this:

SELECT ?field ?lessCount ?equalCount WHERE {
            SELECT (COUNT(?otherLetter) AS ?equalCount) ?field WHERE 

How can I achieve this? I've viewed all of the above using a logger in my java code. Any help would be appreciated! :)


Jeen Broekstra

Jul 17, 2021, 2:26:06 AMJul 17
to RDF4J Users
Could you perhaps provide slightly more complete code examples? It's hard to understand what you're trying to do from the fragments you're providing.

What would be really helpful is that your code examples are complete enough for me to copy-paste into a main method and then just immediately run.



PS as indicated, we will be closing this mailinglist. Can I suggest that you post your question at the new Github Discussion board instead? See .
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

Reply all
Reply to author
0 new messages