Java Code Examples for org.eclipse.rdf4j.query.BooleanQuery#evaluate()
The following examples show how to use
org.eclipse.rdf4j.query.BooleanQuery#evaluate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SAILFederatedService.java From CostFed with GNU Affero General Public License v3.0 | 6 votes |
@Override public boolean ask(Service service, BindingSet bindings, String baseUri) throws QueryEvaluationException { RepositoryConnection conn = endpoint.getConn(); try { BooleanQuery query = conn.prepareBooleanQuery(QueryLanguage.SPARQL, service.getAskQueryString(), baseUri); Iterator<Binding> bIter = bindings.iterator(); while (bIter.hasNext()) { Binding b = bIter.next(); if (service.getServiceVars().contains(b.getName())) query.setBinding(b.getName(), b.getValue()); } return query.evaluate(); } catch(Throwable e) { throw new QueryEvaluationException(e); } finally { conn.close(); } }
Example 2
Source File: TripleSourceBase.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean hasStatements(ExclusiveTupleExpr group, BindingSet bindings) throws RepositoryException, MalformedQueryException, QueryEvaluationException { monitorRemoteRequest(); String preparedAskQuery = QueryStringUtil.askQueryString(group, bindings, group.getQueryInfo().getDataset()); try (RepositoryConnection conn = endpoint.getConnection()) { BooleanQuery query = conn.prepareBooleanQuery(QueryLanguage.SPARQL, preparedAskQuery); configureInference(query, group.getQueryInfo()); applyMaxExecutionTimeUpperBound(query); return query.evaluate(); } }
Example 3
Source File: SailRepositoryConnectionTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testPrepareBooleanQuery_not_bypassed() throws Exception { Optional<TupleExpr> response = Optional.empty(); when(sailConnection.prepareQuery(any(), eq(Query.QueryType.BOOLEAN), any(), any())).thenReturn(response); when(sailConnection.evaluate(any(), any(), any(), anyBoolean())).thenReturn(new EmptyIteration<>()); BooleanQuery query = subject.prepareBooleanQuery("ASK WHERE { ?s ?p ?o }"); query.evaluate(); // check that evaluation is still called, and not with an empty TupleExpr verify(sailConnection).evaluate(any(TupleExpr.class), any(), any(), anyBoolean()); }
Example 4
Source File: SailRepositoryConnectionTest.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testPrepareBooleanQuery_bypassed() throws Exception { TupleExpr expr = mock(TupleExpr.class); Optional<TupleExpr> response = Optional.of(expr); when(sailConnection.prepareQuery(any(), eq(Query.QueryType.BOOLEAN), any(), any())).thenReturn(response); when(sailConnection.evaluate(eq(expr), any(), any(), anyBoolean())).thenReturn(new EmptyIteration<>()); BooleanQuery query = subject.prepareBooleanQuery("ASK WHERE { ?s ?p ?o }"); query.evaluate(); // check that the TupleExpr implementation created by the underlying sail was passed to the evaluation verify(sailConnection).evaluate(eq(expr), any(), any(), anyBoolean()); }
Example 5
Source File: SPARQLConnection.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean isEmpty() throws RepositoryException { try { BooleanQuery query; if (isQuadMode()) { query = prepareBooleanQuery(SPARQL, SOMETHING_WITH_GRAPH); } else { query = prepareBooleanQuery(SPARQL, SOMETHING); } return !query.evaluate(); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } }
Example 6
Source File: SPARQLConnection.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean hasStatement(Resource subj, IRI pred, Value obj, boolean includeInferred, Resource... contexts) throws RepositoryException { try { BooleanQuery query = prepareBooleanQuery(SPARQL, SOMETHING, ""); setBindings(query, subj, pred, obj, contexts); return query.evaluate(); } catch (MalformedQueryException | QueryEvaluationException e) { throw new RepositoryException(e); } }
Example 7
Source File: BooleanQueryResultView.java From semagrow with Apache License 2.0 | 5 votes |
protected void renderInternal(Map model, HttpServletRequest request, HttpServletResponse response) throws IOException { BooleanQueryResultWriterFactory brWriterFactory = (BooleanQueryResultWriterFactory)model.get("factory"); BooleanQueryResultFormat brFormat = brWriterFactory.getBooleanQueryResultFormat(); response.setStatus(200); this.setContentType(response, brFormat); this.setContentDisposition(model, response, brFormat); boolean headersOnly = ((Boolean)model.get("headersOnly")).booleanValue(); if(!headersOnly) { ServletOutputStream out = response.getOutputStream(); try { BooleanQueryResultWriter e = brWriterFactory.getWriter(out); BooleanQuery query = ((BooleanQuery)model.get("queryResult")); boolean value = query.evaluate(); e.handleBoolean(value); } catch (QueryResultHandlerException var13) { if(var13.getCause() != null && var13.getCause() instanceof IOException) { throw (IOException)var13.getCause(); } throw new IOException(var13); } finally { out.close(); } } this.logEndOfRequest(request); }
Example 8
Source File: RepositoryModel.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean sparqlAsk(String query) throws ModelRuntimeException { assertModel(); try { BooleanQuery prepared = this.connection.prepareBooleanQuery(QueryLanguage.SPARQL, query); return prepared.evaluate(); } catch (MalformedQueryException | RepositoryException | UnsupportedQueryLanguageException | QueryEvaluationException e) { throw new ModelRuntimeException(e); } }
Example 9
Source File: RepositoryModelSet.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public boolean sparqlAsk(String queryString) throws ModelRuntimeException { this.assertModel(); BooleanQuery booleanQuery; try { booleanQuery = this.connection.prepareBooleanQuery(QueryLanguage.SPARQL, queryString); boolean result = booleanQuery.evaluate(); return result; } catch(RDF4JException e) { throw new ModelRuntimeException(e); } }
Example 10
Source File: QueryEvaluator.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void evaluateBooleanQuery(final TupleResultBuilder builder, final BooleanQuery query) throws QueryEvaluationException, QueryResultHandlerException { final boolean result = query.evaluate(); builder.link(Arrays.asList(INFO)); builder.bool(result); }