Refine search
private TupleQueryResult query ( RepositoryConnection rc, String qs ) throws RepositoryException, MalformedQueryException, QueryEvaluationException { return rc.prepareTupleQuery ( QueryLanguage.SPARQL, qs ).evaluate () ; }
private boolean evaluateSparql(String qry) throws RepositoryException, MalformedQueryException, QueryEvaluationException { TupleQuery query = con.prepareTupleQuery(QueryLanguage.SPARQL, qry); TupleQueryResult evaluate = query.evaluate(); try { return evaluate.hasNext(); } finally { evaluate.close(); } } }
protected double checkIfSimilar(RepositoryConnection conn, String contribA, String contribB) throws RepositoryException, MalformedQueryException, QueryEvaluationException { String zeroQueryString = "" + "Select distinct jour \n" + "from \n" + "{doc} <"+RelConstants.RL_HAS_CONTRIBUTOR+"> {<"+contribA+">}, \n" + "{doc} <"+RelConstants.RL_JOURNAL+"> {jour}, \n" + "{doc2} <"+RelConstants.RL_HAS_CONTRIBUTOR+"> {<"+contribB+">}, \n" + "{doc2} <"+RelConstants.RL_JOURNAL+"> {jour} \n" + ""; TupleQuery query = null; TupleQueryResult res = null; query = conn.prepareTupleQuery(QueryLanguage.SERQL, zeroQueryString); res = query.evaluate(); if(res.hasNext()){ res.close(); return 1; } return 0; } }
String queryString = "SELECT ..."; RepositoryConnection conn = repo.getConnection(); try { TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); TupleQueryResult result = tq.evaluate(); } finally { conn.close(); }
protected long countSolutions(final String query) throws QueryEvaluationException, RepositoryException, MalformedQueryException { TupleQueryResult result = con.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate(); try { long n = 0; while (result.hasNext()) { final BindingSet bset = result.next(); n++; if (logger.isInfoEnabled()) logger.info(bset.toString()); } return n; } finally { result.close(); } }
public RepositoryQueryResultTable(String queryString, QueryLanguage language, RepositoryConnection connection) throws ModelRuntimeException { try { this.query = connection.prepareTupleQuery(language, queryString); this.queryResult = this.query.evaluate(); } catch(OpenRDFException e) { throw new ModelRuntimeException(e); } }
@Test public void testInComparison2() throws Exception { loadTestData("/testdata-query/dataset-ses1913.trig"); StringBuilder query = new StringBuilder(); query.append(" PREFIX : <http://example.org/>\n"); query.append(" SELECT ?y WHERE { :a :p ?y. FILTER(?y in (:c, :d, 1/0)) } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); TupleQueryResult result = tq.evaluate(); assertNotNull(result); assertFalse(result.hasNext()); }
@Override protected boolean matchesSPARQL(RepositoryConnection con) throws RepositoryException, QueryEvaluationException, MalformedQueryException { final TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, query, baseUri); final TupleQueryResult result = tupleQuery.evaluate(); final List<BindingSet> bindingSets = QueryResults.asList(result); // FIXME: test this! return matcher.matches(bindingSets); }
@Test public void testInComparison2() throws Exception { loadTestData("/testdata-query/dataset-ses1913.trig"); StringBuilder query = new StringBuilder(); query.append(" PREFIX : <http://example.org/>\n"); query.append(" SELECT ?y WHERE { :a :p ?y. FILTER(?y in (:c, :d, 1/0)) } "); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query.toString()); TupleQueryResult result = tq.evaluate(); assertNotNull(result); assertFalse(result.hasNext()); }
public RepositoryQueryResultTable(String queryString, QueryLanguage language, RepositoryConnection connection) throws ModelRuntimeException { try { queryResult = connection.prepareTupleQuery(language, queryString).evaluate(); } catch (OpenRDFException e) { throw new ModelRuntimeException(e); } }
protected void assertNoQueryResult(String literal) throws Exception { // fire a query for all subjects with a given term String queryString = "SELECT Resource " + "FROM {Resource} <" + MATCHES + "> {} " + " <" + QUERY + "> {\"" + literal + "\"} "; TupleQuery query = connection.prepareTupleQuery(QueryLanguage.SERQL, queryString); TupleQueryResult result = query.evaluate(); try { // check the result assertFalse("query for literal '" + literal + " did return results, which was not expected.", result.hasNext()); } finally { result.close(); } }
@Override protected boolean matchesSPARQL(RepositoryConnection con) throws RepositoryException, QueryEvaluationException, MalformedQueryException { final TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, query, baseUri); final TupleQueryResult result = tupleQuery.evaluate(); final List<BindingSet> bindingSets = QueryResults.asList(result); // FIXME: test this! return matcher.matches(bindingSets); }
public interface Factory { SPARQLSyntaxTest createSPARQLSyntaxTest(String testURI, String testName, String testAction, boolean positiveTest); }
RepositoryConnection conn = rep.getConnection(); try { // prepare the query String queryString = "SELECT * WHERE {?s ?p ?o . }"; TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); // open a file to write the result to it in JSON format OutputStream out = new FileOutputStream("/path/to/output.json"); TupleQueryResultHandler writer = new SPARQLResultJSONWriter(out); // execute the query and write the result directly to file query.evaluate(writer); } finally { conn.close(); }
@Test public void testSES713() throws Exception { String queryString = "SELECT * { ?sub ?pred ?obj . FILTER ( 'not a number' + 1 = ?obj )}"; TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL, queryString); TupleQueryResult tqr = query.evaluate(); try { assertFalse("Query should not return any results", tqr.hasNext()); } finally { tqr.close(); } }
private TupleQueryResult query ( RepositoryConnection rc, String qs ) throws RepositoryException, MalformedQueryException, QueryEvaluationException { return rc.prepareTupleQuery ( QueryLanguage.SPARQL, qs ).evaluate () ; }
// open a connection to the Sesame repository containing your statements RepositoryConnection conn = repository.getConnection(); try { // create a prepared query object from your query string TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); // evaluate the query on the repository TupleQueryResult result = query.evaluate(); // iterate over the results and do something with each result while (result.hasNext()) { BindingSet s = result.next(); Value subject = s.getValue("subject"); Value object = s.getValue("object"); System.out.println("value of ?subject: " + subject); System.out.println("value of ?object: " + object); } } finally { conn.close(); }
@Test public void testIdenticalVariablesInStatementPattern() throws Exception { conn.add(alice, f.createURI("http://purl.org/dc/elements/1.1/publisher"), bob); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("SELECT ?publisher "); queryBuilder.append("{ ?publisher <http://purl.org/dc/elements/1.1/publisher> ?publisher }"); conn.prepareTupleQuery(QueryLanguage.SPARQL, queryBuilder.toString()).evaluate( new TupleQueryResultHandlerBase() { public void handleSolution(BindingSet bindingSet) { fail("nobody is self published"); } }); }
protected long debugPrintSolutions(final String query) throws QueryEvaluationException, RepositoryException, MalformedQueryException { TupleQueryResult result = con.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate(); try { long n = 0; while (result.hasNext()) { System.err.println("==> NEXT SOLUTION"); final BindingSet bset = result.next(); for (final String bindingName : bset.getBindingNames()) { final Binding b = bset.getBinding(bindingName); System.err.println(bindingName + " -> " + b); } n++; } return n; } finally { result.close(); } } }
@Test public void testIdenticalVariablesInStatementPattern() throws Exception { conn.add(alice, f.createIRI("http://purl.org/dc/elements/1.1/publisher"), bob); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("SELECT ?publisher "); queryBuilder.append("{ ?publisher <http://purl.org/dc/elements/1.1/publisher> ?publisher }"); conn.prepareTupleQuery(QueryLanguage.SPARQL, queryBuilder.toString()).evaluate( new AbstractTupleQueryResultHandler() { public void handleSolution(BindingSet bindingSet) { fail("nobody is self published"); } }); }