Search in sources :

Example 1 with BooleanQuery

use of org.eclipse.rdf4j.query.BooleanQuery in project rdf4j by eclipse.

the class RepositoryFederatedService method ask.

/**
 * Evaluate the provided sparqlQueryString at the initialized {@link Repository} of this
 * {@link FederatedService}. Insert bindings, send ask query and return final result
 */
@Override
public boolean ask(Service service, BindingSet bindings, String baseUri) throws QueryEvaluationException {
    try {
        String sparqlQueryString = service.getAskQueryString();
        BooleanQuery query = getConnection().prepareBooleanQuery(QueryLanguage.SPARQL, sparqlQueryString, 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 (MalformedQueryException e) {
        throw new QueryEvaluationException(e);
    } catch (RepositoryException e) {
        throw new QueryEvaluationException("Repository for endpoint " + rep.toString() + " could not be initialized.", e);
    }
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) BooleanQuery(org.eclipse.rdf4j.query.BooleanQuery) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

Example 2 with BooleanQuery

use of org.eclipse.rdf4j.query.BooleanQuery in project rdf4j by eclipse.

the class SPARQLConnection method hasStatement.

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 e) {
        throw new RepositoryException(e);
    } catch (QueryEvaluationException e) {
        throw new RepositoryException(e);
    }
}
Also used : BooleanQuery(org.eclipse.rdf4j.query.BooleanQuery) SPARQLBooleanQuery(org.eclipse.rdf4j.repository.sparql.query.SPARQLBooleanQuery) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

Aggregations

BooleanQuery (org.eclipse.rdf4j.query.BooleanQuery)2 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)2 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)2 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)2 Binding (org.eclipse.rdf4j.query.Binding)1 SPARQLBooleanQuery (org.eclipse.rdf4j.repository.sparql.query.SPARQLBooleanQuery)1