@Override protected boolean ask(final String askQuery) throws RepositoryException, MalformedQueryException, QueryEvaluationException { final BooleanQuery q = connection.prepareBooleanQuery(QueryLanguage.SPARQL, askQuery); final boolean result = q.evaluate(); return result; }
public void booleanQuery() throws QueryEvaluationException, RepositoryException, MalformedQueryException { // /query repo String queryString = "PREFIX : \n<http://it.unibz.krdb/obda/ontologies/test/translation/onto2.owl#>\n " + "ASK { :Lisa a :Person} "; BooleanQuery boolQuery = (con).prepareBooleanQuery(QueryLanguage.SPARQL, queryString); boolean result = boolQuery.evaluate(); System.out.println(result); }
public static BooleanQuery getQuery( RepositoryConnection connection, ParsedBooleanQuery booleanQueryModel, boolean includeInferred) { try { QUERY_HOLDER.set(booleanQueryModel); BooleanQuery booleanQuery = connection.prepareBooleanQuery(DirectQuery.DIRECTQUERY, ""); booleanQuery.setIncludeInferred(includeInferred); return booleanQuery; } catch (MalformedQueryException e) { throw new RepositoryException(e); } catch (org.openrdf.repository.RepositoryException e) { throw new RepositoryException(e); } }
public String query(String queryString) throws RepositoryException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, RDFHandlerException, IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); RepositoryConnection con = getRepository().getConnection(); SPARQLParser parser = new SPARQLParser(); ParsedQuery parsedQuery = parser.parseQuery(queryString, null); if (parsedQuery instanceof ParsedTupleQuery) { SPARQLResultsXMLWriter writer = new SPARQLResultsXMLWriter(bout); TupleQuery query = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString); query.evaluate(writer); } else if (parsedQuery instanceof ParsedGraphQuery) { RDFXMLPrettyWriter writer = new RDFXMLPrettyWriter(bout); GraphQuery query = con.prepareGraphQuery(QueryLanguage.SPARQL, queryString); query.evaluate(writer); } else if (parsedQuery instanceof ParsedBooleanQuery) { BooleanQuery query = con.prepareBooleanQuery(QueryLanguage.SPARQL, queryString); boolean result = query.evaluate(); String resultString = BOOLEAN_RESULT_RESULT_PREFIX + result + BOOLEAN_RESULT_RESULT_SUFFIX; bout.write(resultString.getBytes()); } con.close(); return bout.toString(); }