Multiple filters in one query

瀏覽次數:90 次
跳到第一則未讀訊息

Vaishali R

未讀,
2021年5月20日 上午11:36:072021/5/20
收件者:RDF4J Users
Hi,

I am trying to filter through the start date and end date using multiple filters within one query. I want to find out how many terms are within 6 months of ending, so the SPARQL query I am trying to recreate is this:

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


This is what I have so far, 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))));



The query is not being built properly, as only one of the filters goes through, this is how I have currently tried to build the query:

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 the query that shows up: 

SELECT ( COUNT( ?term ) AS ?count ) WHERE { ?term a Term . ?term :contractEndDate ?endDate . ?term :contractStartDate ?startDate . FILTER ( ?startDate < NOW() ) }



As you can see, the end date filter is not included in the query. I also don't know how to include the +5 months in duration and was hoping I could get some help with that.


Any help would be much appreciated!
Thanks,
Vaishali
回覆所有人
回覆作者
轉寄
0 則新訊息