use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class TestExpressions3 method evalExpr.
// From algebra/SSE
private static void evalExpr(String exprString, String bindingStr, boolean expected) {
Binding binding = binding(bindingStr);
Expr expr = SSE.parseExpr(exprString);
NodeValue nv = expr.eval(binding, FunctionEnvBase.createTest());
boolean b = XSDFuncOp.booleanEffectiveValue(nv);
assertEquals(exprString, expected, b);
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class ValuesHandlerTest method oneVarOneData.
@Test
public void oneVarOneData() {
Node n = NodeFactory.createLiteral("hello");
Var v = Var.alloc("x");
handler.addValueVar(v, Arrays.asList(n));
handler.build();
List<Var> vars = query.getValuesVariables();
assertEquals(1, vars.size());
assertEquals(v, vars.get(0));
assertNotNull(query.getValuesData());
List<Binding> lb = query.getValuesData();
assertEquals(1, lb.size());
Binding b = lb.get(0);
assertTrue(b.contains(v));
assertEquals(n, b.get(v));
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class ValuesHandlerTest method testAddNotSquare.
@Test
public void testAddNotSquare() {
Node n = NodeFactory.createLiteral("hello");
Node nn = NodeFactory.createLiteral("hola");
Node n2 = NodeFactory.createLiteral("there");
Node nn2 = NodeFactory.createLiteral("aqui");
Var v = Var.alloc("x");
Var v2 = Var.alloc("y");
Var v3 = Var.alloc("z");
handler.addValueVar(v, Arrays.asList(n, n2));
handler.addValueVar(v2, Arrays.asList(nn, nn2));
ValuesHandler handler2 = new ValuesHandler(new Query());
Node n3 = NodeFactory.createLiteral("why");
Node nn3 = NodeFactory.createLiteral("quando");
handler2.addValueVar(v2, Arrays.asList(n3));
handler2.addValueVar(v3, Arrays.asList(nn3));
handler.addAll(handler2);
handler.build();
List<Var> vars = query.getValuesVariables();
assertEquals(3, vars.size());
assertTrue(vars.contains(v));
assertTrue(vars.contains(v2));
assertTrue(vars.contains(v3));
assertNotNull(query.getValuesData());
List<Binding> lb = query.getValuesData();
assertEquals(3, lb.size());
for (Binding b : lb) {
assertTrue(b.contains(v2));
Node node = b.get(v2);
if (node.equals(nn)) {
assertEquals(n, b.get(v));
assertFalse(b.contains(v3));
} else if (node.equals(nn2)) {
assertEquals(n2, b.get(v));
assertFalse(b.contains(v3));
} else if (node.equals(n3)) {
assertFalse(b.contains(v));
assertEquals(nn3, b.get(v3));
} else {
fail("Wrong data in table");
}
}
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class ValuesHandlerTest method oneVarTwoData.
@Test
public void oneVarTwoData() {
Node n = NodeFactory.createLiteral("hello");
Node n2 = NodeFactory.createLiteral("there");
Var v = Var.alloc("x");
handler.addValueVar(v, Arrays.asList(n, n2));
handler.build();
List<Var> vars = query.getValuesVariables();
assertEquals(1, vars.size());
assertEquals(v, vars.get(0));
assertNotNull(query.getValuesData());
List<Binding> lb = query.getValuesData();
assertEquals(2, lb.size());
List<Node> ln = new ArrayList<Node>();
ln.add(n);
ln.add(n2);
for (Binding b : lb) {
assertTrue(b.contains(v));
assertTrue(ln.contains(b.get(v)));
ln.remove(b.get(v));
}
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class LibSDB method findTriples.
/** Find triples, in the default graph or a named graph. */
public static Iterator<Triple> findTriples(DatasetGraph dsg, Node g, Node s, Node p, Node o) {
if (Var.isVar(g))
throw new InternalErrorException("Graph node is a variable : " + g);
final Node vs = varOrConst(s, "s");
final Node vp = varOrConst(p, "p");
final Node vo = varOrConst(o, "o");
// Evaluate as an algebra expression
Triple triple = new Triple(vs, vp, vo);
BasicPattern pattern = new BasicPattern();
pattern.add(triple);
Op op = (g != null) ? new OpQuadPattern(g, pattern) : new OpBGP(pattern);
Plan plan = QueryEngineSDB.getFactory().create(op, dsg, BindingRoot.create(), null);
QueryIterator qIter = plan.iterator();
Iterator<Binding> iter;
if (SDB.getContext().isTrue(SDB.streamGraphAPI)) {
// Assumes iterator closed properly.
iter = qIter;
} else {
// ---- Safe version:
List<Binding> x = Iter.toList(qIter);
Iterator<Binding> qIter2 = x.iterator();
qIter.close();
iter = qIter2;
}
return Iter.map(iter, (b) -> bindingToTriple(vs, vp, vo, b));
}
Aggregations