@Override public void setInitialBinding(QuerySolution binding) { decoratee.setInitialBinding(binding); }
/** Create a QueryExecution to execute over the Model. * * @param query Query string * @param initialBinding Any initial binding of variables * @return QueryExecution */ static public QueryExecution create(Query query, QuerySolution initialBinding) { checkArg(query) ; QueryExecution qe = make(query) ; if ( initialBinding != null ) qe.setInitialBinding(initialBinding) ; return qe ; }
/** Create a QueryExecution over a Dataset given some initial values of variables. * * @param query Query * @param dataset Target of the query * @param initialBinding Any initial binding of variables * @return QueryExecution */ static public QueryExecution create(Query query, Dataset dataset, QuerySolution initialBinding) { checkArg(query) ; QueryExecution qe = make(query, dataset) ; if ( initialBinding != null ) qe.setInitialBinding(initialBinding) ; return qe ; }
private static List<RDFNode> creatingAgentsFor(Resource r) { logger.fine("Finding creator of " + r); String queryStr = sparqlPrefixes + "SELECT ?agent WHERE { \n" + " { \n" + " ?r dct:creator [ \n" + " rdfs:member ?agent \n" + " ] \n" + " } UNION { \n" + " ?r dct:creator ?agent .\n " + " FILTER NOT EXISTS { ?agent rdfs:member ?member } \n" + " } \n" + "} \n"; logger.finer(QueryFactory.create(queryStr).toString()); QueryExecution qexec = QueryExecutionFactory.create(queryStr, r.getModel()); QuerySolutionMap binding = new QuerySolutionMap(); binding.add("r", r); qexec.setInitialBinding(binding); ResultSet select = qexec.execSelect(); List<RDFNode> agents = new ArrayList<>(); while (select.hasNext()) { RDFNode agent = select.next().get("agent"); logger.fine("Found: " + agent); agents.add(agent); } return agents; }
public <T> T resolve(Callable<T> callable) { if(decoratee instanceof QueryExecutionRetryDecorateeProxy) { this.proxy = (QueryExecutionRetryDecorateeProxy) decoratee; decoratee = supplier.get(); if (proxy.getInitialBinding() != null) decoratee.setInitialBinding(proxy.getInitialBinding()); if (proxy.getTimeout1() > -1L || proxy.getTimeout2() > -1L) decoratee.setTimeout(proxy.getTimeout1(), proxy.getTimeout2()); } try { return callable.call(); } catch(Exception e) { if(aborted) { throw new AbortRetryException(); } decoratee = this.proxy; this.proxy = null; throw new RuntimeException(e); } }
private static Resource mboxForAgent(Resource agentResource) { logger.fine("Finding mbox of " + agentResource); String queryStr = sparqlPrefixes + "SELECT ?mbox WHERE { \n" + " { ?agent foaf:mbox ?mbox } \n" + " UNION \n" + " { ?agent vcard:hasEmail ?mbox } \n" + " UNION \n" + " { ?agent vcard:email ?email . \n" + " BIND(IRI(CONCAT(\"mbox:\", ?email)) AS ?mbox) \n" // legacy + " } \n" + "} \n"; logger.finer(QueryFactory.create(queryStr).toString()); QueryExecution qexec = QueryExecutionFactory.create(queryStr, agentResource.getModel()); QuerySolutionMap binding = new QuerySolutionMap(); binding.add("agent", agentResource); qexec.setInitialBinding(binding); ResultSet select = qexec.execSelect(); if (select.hasNext()) { Resource mbox = select.next().getResource("mbox"); logger.fine("Found mbox: " + mbox); return mbox; } logger.fine("mbox not found"); return null; }
QuerySolutionMap binding = new QuerySolutionMap(); binding.add("agent", agentResource); qexec.setInitialBinding(binding); ResultSet select = qexec.execSelect(); if (select.hasNext()) {
queryExec.setInitialBinding(initialBinding);
queryExec.setInitialBinding(initialBinding);
queryExec.setInitialBinding(initialBinding);
QuerySolutionMap binding = new QuerySolutionMap(); binding.add("msg", new ResourceImpl(wonMessage.getMessageURI().toString())); qexec.setInitialBinding(binding); ResultSet rs = qexec.execSelect(); if (rs.hasNext()) {
@Test public void testInitialBindings2() { QueryExecution qExec = makeQExec("SELECT * {?s ?p ?o}") ; QuerySolutionMap init = new QuerySolutionMap() ; init.add("z", m.createLiteral("zzz")); qExec.setInitialBinding(init) ; int count = queryAndCount(qExec) ; assertEquals("Initial binding restricted query improperly", 3, count) ; }
@Test public void testInitialBindings1() { QueryExecution qExec = makeQExec("SELECT * {?s ?p ?o}") ; QuerySolutionMap init = new QuerySolutionMap() ; init.add("o", m.createLiteral("y1")); qExec.setInitialBinding(init) ; int count = queryAndCount(qExec) ; assertEquals("Initial binding didn't restrict query properly", 1, count) ; }
@Test public void testInitialBindings3() { try(QueryExecution qExec = makeQExec("SELECT * {?s ?p 'x1'}")) { QuerySolutionMap init = new QuerySolutionMap() ; init.add("z", m.createLiteral("zzz")); qExec.setInitialBinding(init) ; ResultSet rs = qExec.execSelect() ; QuerySolution qs = rs.nextSolution() ; assertTrue("Initial setting not set correctly now", qs.getLiteral("z").getLexicalForm().equals("zzz")) ; } }
@Test public void testInitialBindings4() { // Test derived from report by Holger Knublauch String queryString = "PREFIX : <"+ns+">\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + "SELECT * \n" + "WHERE { \n" + " ?x :p1 ?z ." + " NOT EXISTS { \n" + " ?x rdfs:label ?z . \n" + " }\n" + "}"; Query query = QueryFactory.create(queryString, Syntax.syntaxARQ); try(QueryExecution qexec = QueryExecutionFactory.create(query, m)) { QuerySolutionMap map = new QuerySolutionMap(); map.add("this", OWL.Thing); qexec.setInitialBinding(map); ResultSet rs = qexec.execSelect(); while(rs.hasNext()) { QuerySolution qs = rs.nextSolution(); //System.out.println("Result: " + qs); } } }
@Test public void testInitialBindingsConstruct1() { try(QueryExecution qExec = makeQExec("CONSTRUCT {?s ?p ?z} {?s ?p 'x1'}")) { QuerySolutionMap init = new QuerySolutionMap() ; init.add("z", m.createLiteral("zzz")); qExec.setInitialBinding(init) ; Model r = qExec.execConstruct() ; assertTrue("Empty model", r.size() > 0 ) ; Property p1 = m.createProperty(ns+"p1") ; assertTrue("Empty model", r.contains(null,p1, init.get("z"))) ; } }
@Test public void testInitialBindingsConstruct2() { try(QueryExecution qExec = makeQExec("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }")) { QuerySolutionMap init = new QuerySolutionMap() ; init.add("o", m.createLiteral("x1")); qExec.setInitialBinding(init) ; Model r = qExec.execConstruct() ; assertTrue("Empty model", r.size() > 0 ) ; Property p1 = m.createProperty(ns+"p1") ; assertTrue("Empty model", r.contains(null, p1, init.get("x1"))) ; } }