Search in sources :

Example 86 with Var

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

the class BuilderNode method buildVars.

public static List<Var> buildVars(ItemList list) {
    list = BuilderLib.skipTag(list, Tags.tagVars);
    List<Var> x = new ArrayList<>();
    for (int i = 0; i < list.size(); i++) {
        Item item = list.get(i);
        Var var = BuilderNode.buildVar(item);
        x.add(Var.alloc(item.getNode()));
    }
    return x;
}
Also used : Item(org.apache.jena.sparql.sse.Item) Var(org.apache.jena.sparql.core.Var) ArrayList(java.util.ArrayList)

Example 87 with Var

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

the class BuilderNode method buildVarList.

public static List<Var> buildVarList(ItemList list) {
    if (list.size() > 0 && list.getFirst().isSymbol(Tags.tagVars))
        list = list.cdr();
    List<Var> vars = new ArrayList<>();
    for (Item x : list) {
        Var v = buildVar(x);
        vars.add(v);
    }
    return vars;
}
Also used : Item(org.apache.jena.sparql.sse.Item) Var(org.apache.jena.sparql.core.Var) ArrayList(java.util.ArrayList)

Example 88 with Var

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

the class UpdateBuilderTest method testInsertAndDeleteWithVar.

@Test
public void testInsertAndDeleteWithVar() {
    UpdateBuilder builder = new UpdateBuilder();
    Var v = Var.alloc("v");
    builder.addInsert(new Quad(g, s, v, o));
    builder.addDelete(new Triple(s, v, o));
    builder.addWhere(null, v, "foo");
    builder.setVar(v, p);
    Update update = builder.build();
    assertTrue(update instanceof UpdateModify);
    UpdateModify um = (UpdateModify) update;
    List<Quad> quads = um.getInsertQuads();
    assertEquals(1, quads.size());
    Quad q = quads.get(0);
    assertEquals(g, q.getGraph());
    assertEquals(s, q.getSubject());
    assertEquals(p, q.getPredicate());
    assertEquals(o, q.getObject());
    quads = um.getDeleteQuads();
    assertEquals(1, quads.size());
    q = quads.get(0);
    assertEquals(Quad.defaultGraphNodeGenerated, q.getGraph());
    assertEquals(s, q.getSubject());
    assertEquals(p, q.getPredicate());
    assertEquals(o, q.getObject());
    Element e = um.getWherePattern();
    assertTrue(e instanceof ElementGroup);
    ElementGroup eg = (ElementGroup) e;
    assertEquals(1, eg.getElements().size());
    ElementPathBlock epb = (ElementPathBlock) eg.getElements().get(0);
    Triple t = epb.getPattern().get(0).asTriple();
    assertEquals(Node.ANY, t.getSubject());
    assertEquals(p, t.getPredicate());
    assertEquals(builder.makeNode("foo"), t.getObject());
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) UpdateModify(org.apache.jena.sparql.modify.request.UpdateModify) Var(org.apache.jena.sparql.core.Var) Element(org.apache.jena.sparql.syntax.Element) UpdateBuilder(org.apache.jena.arq.querybuilder.UpdateBuilder) Update(org.apache.jena.update.Update) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 89 with Var

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

the class SelectClauseTest method testAddVarNode.

@ContractTest
public void testAddVarNode() throws Exception {
    Var v = Var.alloc("one");
    SelectClause<?> selectClause = getProducer().newInstance();
    selectClause.addVar("one");
    Query query = getQuery(selectClause.addVar(NodeFactory.createVariable("one")));
    VarExprList expr = query.getProject();
    assertEquals(1, expr.size());
    assertTrue(expr.contains(v));
}
Also used : Query(org.apache.jena.query.Query) Var(org.apache.jena.sparql.core.Var) VarExprList(org.apache.jena.sparql.core.VarExprList) ContractTest(org.xenei.junit.contract.ContractTest)

Example 90 with Var

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

the class SelectClauseTest method testAddVarString.

@ContractTest
public void testAddVarString() throws Exception {
    Var v = Var.alloc("one");
    SelectClause<?> selectClause = getProducer().newInstance();
    selectClause.addVar("one");
    Query query = getQuery(selectClause.addVar("one"));
    VarExprList expr = query.getProject();
    assertEquals(1, expr.size());
    assertTrue(expr.contains(v));
}
Also used : Query(org.apache.jena.query.Query) Var(org.apache.jena.sparql.core.Var) VarExprList(org.apache.jena.sparql.core.VarExprList) ContractTest(org.xenei.junit.contract.ContractTest)

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