Search in sources :

Example 6 with QuerySolutionMap

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;
}
Also used : Node(org.apache.jena.graph.Node) QuerySolutionMap(org.apache.jena.query.QuerySolutionMap)

Example 7 with QuerySolutionMap

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"));
    }
}
Also used : Query(org.apache.jena.query.Query) Dataset(org.apache.jena.query.Dataset) QueryExecution(org.apache.jena.query.QueryExecution) QuerySolutionMap(org.apache.jena.query.QuerySolutionMap) Test(org.junit.Test)

Example 8 with QuerySolutionMap

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"));
}
Also used : QuerySolutionMap(org.apache.jena.query.QuerySolutionMap) Test(org.junit.Test)

Example 9 with QuerySolutionMap

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"));
    }
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) ResultSet(org.apache.jena.query.ResultSet) QueryExecution(org.apache.jena.query.QueryExecution) QuerySolutionMap(org.apache.jena.query.QuerySolutionMap) Test(org.junit.Test)

Example 10 with QuerySolutionMap

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);
    }
}
Also used : Query(org.apache.jena.query.Query) Model(org.apache.jena.rdf.model.Model) QueryExecution(org.apache.jena.query.QueryExecution) QuerySolutionMap(org.apache.jena.query.QuerySolutionMap) Test(org.junit.Test)

Aggregations

QuerySolutionMap (org.apache.jena.query.QuerySolutionMap)17 QueryExecution (org.apache.jena.query.QueryExecution)13 Test (org.junit.Test)10 Query (org.apache.jena.query.Query)8 Model (org.apache.jena.rdf.model.Model)7 QuerySolution (org.apache.jena.query.QuerySolution)3 ResultSet (org.apache.jena.query.ResultSet)3 Node (org.apache.jena.graph.Node)2 Dataset (org.apache.jena.query.Dataset)2 Property (org.apache.jena.rdf.model.Property)2 ArrayList (java.util.ArrayList)1 SortCondition (org.apache.jena.query.SortCondition)1 ResourceImpl (org.apache.jena.rdf.model.impl.ResourceImpl)1 ShaclException (org.apache.jena.shacl.ShaclException)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 Var (org.apache.jena.sparql.core.Var)1 Expr (org.apache.jena.sparql.expr.Expr)1