use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class TestQueryIterSort method randomBinding.
private Binding randomBinding(Var[] vars) {
BindingBuilder builder = Binding.builder();
builder.add(vars[0], NodeFactory.createBlankNode());
builder.add(vars[1], NodeFactory.createURI(randomURI()));
builder.add(vars[2], NodeFactory.createURI(randomURI()));
builder.add(vars[3], NodeFactory.createLiteral(randomString(20)));
builder.add(vars[4], NodeFactory.createBlankNode());
builder.add(vars[5], NodeFactory.createURI(randomURI()));
builder.add(vars[6], NodeFactory.createURI(randomURI()));
builder.add(vars[7], NodeFactory.createLiteral(randomString(5)));
builder.add(vars[8], NodeFactory.createLiteral("" + random.nextInt(), XSDDatatype.XSDinteger));
builder.add(vars[9], NodeFactory.createBlankNode());
return builder.build();
}
use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class TestIndexTable method setup.
@Before
public void setup() {
vars = new Var[] { Var.alloc("a"), Var.alloc("b"), Var.alloc("c") };
order1 = new LinkedHashSet<>();
order2 = new LinkedHashSet<>();
for (int i = 0; i < vars.length; i++) {
order1.add(vars[i]);
order2.add(vars[vars.length - i - 1]);
}
fData = new ArrayList<>();
pData = new ArrayList<>();
for (int i = 10; i <= 100; i += 10) {
BindingBuilder bindingFull = Binding.builder();
BindingBuilder bindingPart = Binding.builder();
for (int b = 0; b < vars.length; b++) {
// 10,11,12 - 20,21,22 - 30,31,32 ... 100,101,102
bindingFull.add(vars[b], makeIntNode(i + b));
// skips 21, 42, 70, 91
if ((i + b) % 7 != 0)
bindingPart.add(vars[b], makeIntNode(i + b));
}
fData.add(bindingFull.build());
pData.add(bindingPart.build());
}
}
use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class SolverRX4 method match.
// RDF term matcher - may recurse and call matchTriple is a triple term is in the pattern.
private static boolean match(BindingBuilder bb, Node nData, Node nPattern) {
if (nPattern == null)
return true;
if (nData == Node.ANY)
return true;
// Deep substitute. This happens anyway as we walk structures.
// nPattern = Substitute.substitute(nPattern, input);
// Shallow substitute
nPattern = Var.lookup(v -> bb.get(v), nPattern);
// nPattern.isConcrete() : either nPattern is an RDF term or is <<>> with no variables.
if (nPattern.isConcrete()) {
// Term comparison.
return sameTermAs(nData, nPattern);
}
// Easy case - nPattern is a variable.
if (Var.isVar(nPattern)) {
Var var = Var.alloc(nPattern);
bb.add(var, nData);
return true;
}
// nPattern is <<>> with variables. Is the data a <<>>?
if (!nData.isNodeTriple())
return false;
// nData is <<>>, nPattern is <<>>
// Unpack, match components.
Triple tPattern = nPattern.getTriple();
Triple tData = nData.getTriple();
return SolverRX3.bindTriple(bb, tData, tPattern);
}
use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class StageMatchTriple method accessTriple.
private static Iterator<Binding> accessTriple(Binding binding, Graph graph, Triple pattern, Predicate<Triple> filter, ExecutionContext execCxt) {
Node s = substituteFlat(pattern.getSubject(), binding);
Node p = substituteFlat(pattern.getPredicate(), binding);
Node o = substituteFlat(pattern.getObject(), binding);
BindingBuilder resultsBuilder = Binding.builder(binding);
Node s2 = tripleNode(s);
Node p2 = tripleNode(p);
Node o2 = tripleNode(o);
ExtendedIterator<Triple> graphIter = graph.find(s2, p2, o2);
ExtendedIterator<Binding> iter = graphIter.mapWith(r -> mapper(resultsBuilder, s, p, o, r)).filterDrop(Objects::isNull);
return iter;
}
use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class StageMatchData method accessQuad.
static Iterator<Binding> accessQuad(Binding binding, Node graphName, Triple pattern, Predicate<Quad> filter, boolean anyGraph, ExecutionContext execCxt) {
// Assumes if anyGraph, then graphName ==ANY.
// graphName == null for triples.
Node g = graphName;
Node s = pattern.getSubject();
Node p = pattern.getPredicate();
Node o = pattern.getObject();
Node[] matchConst = new Node[4];
Var[] vars = new Var[4];
boolean b = prepareQuad(binding, graphName, pattern, matchConst, vars);
if (!b)
return Iter.nullIterator();
Node gm = matchConst[QG];
Node sm = matchConst[QS];
Node pm = matchConst[QP];
Node om = matchConst[QO];
DatasetGraph dsg = execCxt.getDataset();
// Union -> findNG - do not include default graph.
Iterator<Quad> iterMatches = anyGraph ? dsg.findNG(gm, sm, pm, om) : dsg.find(gm, sm, pm, om);
if (false) {
// Debug
List<Quad> x = Iter.toList(iterMatches);
System.out.println(x);
iterMatches = x.iterator();
}
// ** Allow a triple or quad filter here.
if (filter != null)
iterMatches = Iter.filter(iterMatches, filter);
// Assumes that tuples are not shared.
if (anyGraph) {
iterMatches = Iter.map(iterMatches, quadsToUnion);
// Guaranteed
iterMatches = Iter.distinct(iterMatches);
// This depends on the way indexes are chosen and
// the indexing pattern. It assumes that the index
// chosen ends in G so same triples are adjacent
// in a union query.
//
// If any slot is defined, then the index will be X??G.
// If no slot is defined, then the index will be ???G.
// Must be guaranteed.
//
// iterMatches = Iter.distinctAdjacent(iterMatches);
}
BindingBuilder bindingBuilder = BindingFactory.builder(binding);
Function<Quad, Binding> binder = quad -> quadToBinding(bindingBuilder, quad, matchConst, vars);
return Iter.iter(iterMatches).map(binder).removeNulls();
}
Aggregations