use of org.apache.jena.query.QuerySolutionMap in project jena by apache.
the class EvalSparql method parametersToPreBinding.
private static QuerySolutionMap parametersToPreBinding(Model data, Node node, List<Parameter> params) {
QuerySolutionMap qsm = new QuerySolutionMap();
params.forEach(param -> {
Node path = param.getParameterPath();
// Full path not supported (needs string-syntax rewrite)
Node v = G.getOneSP(data.getGraph(), node, path);
qsm.add(param.getSparqlName(), ModelUtils.convertGraphNodeToRDFNode(v, data));
});
return qsm;
}
use of org.apache.jena.query.QuerySolutionMap in project jena by apache.
the class TestAPI method testInitialBindings7.
@Test
public void testInitialBindings7() {
// JENA-1354
Query query = QueryFactory.create("SELECT DISTINCT ?x WHERE {}");
Dataset ds = DatasetFactory.create();
QuerySolutionMap initialBinding = new QuerySolutionMap();
initialBinding.add("a", ResourceFactory.createTypedLiteral(Boolean.TRUE));
try (QueryExecution qexec = QueryExecutionFactory.create(query, ds, initialBinding)) {
assertFalse(qexec.execSelect().next().contains("a"));
}
}
use of org.apache.jena.query.QuerySolutionMap in project jena by apache.
the class TestAPI method testInitialBindings0.
@Test
public void testInitialBindings0() {
QuerySolutionMap smap1 = new QuerySolutionMap();
QuerySolutionMap smap2 = new QuerySolutionMap();
smap1.add("o", m.createLiteral("y1"));
smap2.addAll(smap1);
assertTrue(smap2.contains("o"));
smap2.clear();
assertFalse(smap2.contains("o"));
assertTrue(smap1.contains("o"));
QuerySolutionMap smap3 = new QuerySolutionMap();
smap2.addAll((QuerySolution) smap1);
assertTrue(smap2.contains("o"));
}
use of org.apache.jena.query.QuerySolutionMap in project jena by apache.
the class TestAPI method testInitialBindings3.
@Test
public void testInitialBindings3() {
QuerySolutionMap init = new QuerySolutionMap();
init.add("z", m.createLiteral("zzz"));
String qs = "SELECT * {?s ?p 'x1'}";
try (QueryExecution qExec = QueryExecution.model(m).query(qs).initialBinding(init).build()) {
ResultSet rs = qExec.execSelect();
QuerySolution qSoln = rs.nextSolution();
assertTrue("Initial setting not set correctly now", qSoln.getLiteral("z").getLexicalForm().equals("zzz"));
}
}
use of org.apache.jena.query.QuerySolutionMap in project jena by apache.
the class TestAPI method testInitialBindings6.
/**
* Initial binding substitution happens before optimization so initial bindings can make a semantically always false query into one that can return true
*/
@Test
public void testInitialBindings6() {
// From JENA-500
Query query = QueryFactory.create("ASK\n" + "WHERE {\n" + " FILTER (?a = ?b) .\n" + "}");
// System.out.println(Algebra.optimize(Algebra.compile(query)).toString());
Model model = ModelFactory.createDefaultModel();
model.add(OWL.Thing, RDF.type, OWL.Class);
QuerySolutionMap initialBinding = new QuerySolutionMap();
initialBinding.add("a", ResourceFactory.createTypedLiteral(Boolean.TRUE));
initialBinding.add("b", ResourceFactory.createTypedLiteral(Boolean.TRUE));
try (QueryExecution qExec = QueryExecution.model(model).query(query).initialBinding(initialBinding).build()) {
boolean result = qExec.execAsk();
assertTrue(result);
}
}
Aggregations