I wish to replicate the following filter from SPARQL in java using rdf4j but I'm not quite sure how to.
FILTER(?endDate > NOW() && ?startDate < NOW() && MONTH(?endDate) = MONTH(NOW()))I have initialised expressions for MONTH() and NOW() as follows, and a graph pattern called 'pattern', but don't know how to use them to extract the month from variable ?endDate and from the NOW() function
Expression<?> nowFunc = Expressions.function(SparqlFunction.NOW );The query I have so far is as follows, but I can't figure out how to implement the final part (****) of the filter into the query.
SelectQuery query = Queries.SELECT().prefix(ex).select(letter).where(pattern.filter(Expressions. and(endDateGreaterThan, startDateLessThan, ****)I wish to replicate the following filter from SPARQL in java using rdf4j but I'm not quite sure how to.FILTER(?endDate > NOW() && ?startDate < NOW() && MONTH(?endDate) = MONTH(NOW()))I have initialised expressions for MONTH() and NOW() as follows, and a graph pattern called 'pattern', but don't know how to use them to extract the month from variable ?endDate and from the NOW() function
Expression<?> nowFunc = Expressions.function(SparqlFunction.NOW );Expression<?> month = Expressions.function(SparqlFunction.MONTH);Expression<?> endDateGreaterThan = Expressions.gt(endDate, nowFunc);Expression<?> startDateLessThan = Expressions.lt(startDate, nowFunc);The query I have so far is as follows, but I can't figure out how to implement the final part (****) of the filter into the query.
SelectQuery query = Queries.SELECT().prefix(ex).select(letter).where(pattern.filter(Expressions. and(endDateGreaterThan, startDateLessThan, ****)Any help would be appreciated! Thank you so much :)
--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 rdf4j-users...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/rdf4j-users/09b304f6-0934-4f3b-961b-916fbdd4b72fn%40googlegroups.com.
Hey Jeen,Thanks for the reply, I really appreciate it. Again though, there is still an error, completely my fault as I'm still quite new to java, so I'm sorry about all the questions.
ValueFactory x = SimpleValueFactory.getInstance();
Literal threeMonths = x.createLiteral("P3M", XSD.DURATION);Variable endDate = SparqlBuilder.var("endDate");
Expression<?> nowFunc = Expressions.function(SparqlFunction.NOW);Expression<?> endDateGreaterEqual = Expressions.gte(endDate, nowFunc);Expression<?> endDateThreeMonths = Expressions.add(nowFunc, threeMonths);And I now get the following error: 'add(org.eclipse.rdf4j.sparqlbuilder.constraint.Operand...)' in 'org.eclipse.rdf4j.sparqlbuilder.constraint.Expressions' cannot be applied to '(org.eclipse.rdf4j.sparqlbuilder.constraint.Expression<capture<?>>, org.eclipse.rdf4j.model.Literal)'From what I understand, the threeMonths expression has not been initialised properly. What I am trying to achieve is to add 3 months on to NOW() whenever the SPARQL query is sent.