Search in sources :

Example 56 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class TestVarFinder method check.

private static void check(String[] varsExpected, Set<Var> varsFound) {
    Var[] vars = new Var[varsExpected.length];
    for (int i = 0; i < varsExpected.length; i++) {
        Var v = Var.alloc(varsExpected[i]);
        vars[i] = v;
    }
    List<Var> varList = Arrays.asList(vars);
    HashSet<Var> varSet = new HashSet<>();
    varSet.addAll(varList);
    assertEquals(varSet, varsFound);
}
Also used : Var(org.apache.jena.sparql.core.Var) HashSet(java.util.HashSet)

Example 57 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class TestOpVars method check.

private static void check(String[] varsExpected, Collection<Var> varsFound) {
    Var[] vars = new Var[varsExpected.length];
    for (int i = 0; i < varsExpected.length; i++) {
        Var v = Var.alloc(varsExpected[i]);
        vars[i] = v;
    }
    List<Var> varList = Arrays.asList(vars);
    HashSet<Var> varSet = new HashSet<>();
    varSet.addAll(varList);
    assertEquals(varSet, varsFound);
}
Also used : Var(org.apache.jena.sparql.core.Var) HashSet(java.util.HashSet)

Example 58 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class TestSyntaxTransform method testUpdate.

private void testUpdate(String input, String output, String varStr, String valStr) {
    UpdateRequest req1 = UpdateFactory.create(PREFIX + input);
    UpdateRequest reqExpected = UpdateFactory.create(PREFIX + output);
    Map<Var, Node> map = new HashMap<>();
    map.put(Var.alloc(varStr), SSE.parseNode(valStr));
    UpdateRequest reqTrans = UpdateTransformOps.transform(req1, map);
    // Crude.
    String x1 = reqExpected.toString().replaceAll("[ \n\t]", "");
    String x2 = reqTrans.toString().replaceAll("[ \n\t]", "");
    //assertEquals(reqExpected, reqTrans) ;
    assertEquals(x1, x2);
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) HashMap(java.util.HashMap) Var(org.apache.jena.sparql.core.Var) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node)

Example 59 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class TestSyntaxTransform method testQuery.

private void testQuery(String input, String output, String varStr, String valStr) {
    Query q1 = QueryFactory.create(PREFIX + input);
    Query qExpected = QueryFactory.create(PREFIX + output);
    Map<Var, Node> map = new HashMap<>();
    map.put(Var.alloc(varStr), SSE.parseNode(valStr));
    Query qTrans = QueryTransformOps.transform(q1, map);
    assertEquals(qExpected, qTrans);
}
Also used : Query(org.apache.jena.query.Query) HashMap(java.util.HashMap) Var(org.apache.jena.sparql.core.Var) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node)

Example 60 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class TestQuery method query_recursive_01.

@Test
public void query_recursive_01() {
    String query = "SELECT * WHERE { SERVICE <" + serviceQuery() + "> { ?s ?p ?o . BIND(?o AS ?x) } }";
    try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), query)) {
        ResultSet rs = qExec.execSelect();
        Var x = Var.alloc("x");
        while (rs.hasNext()) {
            Binding b = rs.nextBinding();
            Assert.assertNotNull(b.get(x));
        }
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Var(org.apache.jena.sparql.core.Var) ServerTest(org.apache.jena.fuseki.ServerTest) Test(org.junit.Test)

Aggregations

Var (org.apache.jena.sparql.core.Var)264 Node (org.apache.jena.graph.Node)83 ArrayList (java.util.ArrayList)53 Test (org.junit.Test)47 Binding (org.apache.jena.sparql.engine.binding.Binding)33 VarExprList (org.apache.jena.sparql.core.VarExprList)30 Op (org.apache.jena.sparql.algebra.Op)29 Expr (org.apache.jena.sparql.expr.Expr)28 Triple (org.apache.jena.graph.Triple)17 HashMap (java.util.HashMap)15 ContractTest (org.xenei.junit.contract.ContractTest)13 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)12 Query (org.apache.jena.query.Query)11 ExprList (org.apache.jena.sparql.expr.ExprList)11 SortCondition (org.apache.jena.query.SortCondition)10 ExprVar (org.apache.jena.sparql.expr.ExprVar)10 HashSet (java.util.HashSet)9 Pair (org.apache.jena.atlas.lib.Pair)9 SqlColumn (org.apache.jena.sdb.core.sqlexpr.SqlColumn)9 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)9