0

I am trying to filter through the start date and end date using multiple filters within one query.

I want to find how many terms are within 3 months of ending, so the SPARQL query I am trying to recreate is:

SELECT (COUNT(?term) AS ?count) WHERE { \
    ?term a :Term . \
    ?term :startDate ?startDate . \
    ?term :endDate ?endDate . \
    FILTER(?endDate < NOW() + "P3M"^^xsd:duration && ?endDate >= NOW() && ?startDate < NOW()) }

This is what I have so far, and I'm also not sure how to include the +3months within the query. The graph pattern and other variables have been initialised and are not causing a problem.

Variable count = SparqlBuilder.var("count");
Aggregate countAgg = Expressions.count(contract);
Projection select = SparqlBuilder.select(countAgg.as(count));
Expression<?> nowFunc = Expressions.function(SparqlFunction.NOW );



SelectQuery activeQuery = Queries.SELECT().prefix(lg).
                select(countAgg.as(count)).
                where((activePattern.filter(Expressions.gte(endDate, nowFunc))).and(activePattern.filter(Expressions.lt(startDate, nowFunc))));

I get a "java.lang.StackOverflowError". I thought I'd try to include the +3 months by using the expression below, but it doesn't work as it is the function that returns the month of an argument.

Expression<?> threeMonths = Expressions.fucntion(SparqlFunction.MONTH):

EDIT (20/05/2020): The stack overflow error is not the problem, and has been tested. It is being thrown because the query is not being built properly, and both filters are not being applied. The main issue is I can't figure out how to apply two filters within one query. This is the code that has been included:

SelectQuery activeQuery = Queries.SELECT().prefix(lg).select(countAgg.as(count)).where(activePattern.filter(Expressions.gt(endDate, nowFunc)), activePattern.filter(Expressions.lt(startDate, nowFunc)));

and this is query that shows up:

SELECT ( COUNT( ?term ) AS ?count )
WHERE { ?term a Term .
?term :contractEndDate ?endDate .
?term :contractStartDate ?startDate .
FILTER ( ?startDate < NOW() ) }
vaishalir
  • 55
  • 3
  • 1
    showing full code that triggers the exception as well as the full error stacktrace would be useful – UninformedUser May 19 '21 at 15:51
  • Does this answer your question? [How to use the MONTH() function from SPARQL to extract the month of a date in rdf4j?](https://stackoverflow.com/questions/67674465/how-to-use-the-month-function-from-sparql-to-extract-the-month-of-a-date-in-rd) – Jeen Broekstra May 25 '21 at 23:18
  • Yes it does, thank you! – vaishalir May 27 '21 at 08:03

0 Answers0