use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class Algebra method merge.
/**
* This is the SPARQL merge rule.
*/
public static Binding merge(Binding bindingLeft, Binding bindingRight) {
// Test to see if compatible: Iterate over variables in left
boolean matches = compatible(bindingLeft, bindingRight);
if (!matches)
return null;
// If compatible, merge. Iterate over variables in right but not in left.
BindingBuilder b = Binding.builder(bindingLeft);
for (Iterator<Var> vIter = bindingRight.vars(); vIter.hasNext(); ) {
Var v = vIter.next();
Node n = bindingRight.get(v);
if (!bindingLeft.contains(v))
b.add(v, n);
}
return b.build();
}
use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class SolverRX4 method matchQuad.
/**
* Match data "qData" against "tGraphNode, tPattern", including RDF-star terms.
*/
public static Binding matchQuad(Binding input, Quad qData, Node tGraphNode, Triple tPattern) {
BindingBuilder bb = Binding.builder(input);
boolean r = matchQuad(bb, qData, tGraphNode, tPattern);
return r ? bb.build() : null;
}
use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class SolverRX3 method matchTriple.
public static Binding matchTriple(Binding input, Triple tData, Triple tPattern) {
BindingBuilder bb = Binding.builder(input);
boolean r = bindTriple(bb, tData, tPattern);
return r ? bb.build() : null;
}
use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class SolverRX3 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 bindTriple(bb, tData, tPattern);
}
use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class TestDistinctDataNet 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();
}
Aggregations