Search in sources :

Example 16 with QuerySolutionMap

use of org.apache.jena.query.QuerySolutionMap in project jena by apache.

the class TestAPI method testInitialBindings4.

@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);
    QuerySolutionMap map = new QuerySolutionMap();
    map.add("this", OWL.Thing);
    try (QueryExecution qExec = QueryExecution.model(m).query(queryString).initialBinding(map).build()) {
        ResultSet rs = qExec.execSelect();
        while (rs.hasNext()) {
            QuerySolution qs = rs.nextSolution();
        }
    }
}
Also used : Query(org.apache.jena.query.Query) 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 17 with QuerySolutionMap

use of org.apache.jena.query.QuerySolutionMap in project jena by apache.

the class TestAPI method testInitialBindingsConstruct1.

@Test
public void testInitialBindingsConstruct1() {
    QuerySolutionMap init = new QuerySolutionMap();
    init.add("z", m.createLiteral("zzz"));
    String qs = "CONSTRUCT {?s ?p ?z} {?s ?p 'x1'}";
    try (QueryExecution qExec = QueryExecution.model(m).query(qs).initialBinding(init).build()) {
        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")));
    }
}
Also used : Model(org.apache.jena.rdf.model.Model) Property(org.apache.jena.rdf.model.Property) 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