Search in sources :

Example 21 with BindingBuilder

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();
}
Also used : BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node)

Example 22 with BindingBuilder

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;
}
Also used : BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder)

Example 23 with BindingBuilder

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;
}
Also used : BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder)

Example 24 with BindingBuilder

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);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Iterator(java.util.Iterator) SolverLib.nodeTopLevel(org.apache.jena.sparql.engine.main.solver.SolverLib.nodeTopLevel) Triple(org.apache.jena.graph.Triple) SolverLib.tripleHasEmbTripleWithVars(org.apache.jena.sparql.engine.main.solver.SolverLib.tripleHasEmbTripleWithVars) BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Graph(org.apache.jena.graph.Graph) Objects(java.util.Objects) SolverLib.sameTermAs(org.apache.jena.sparql.engine.main.solver.SolverLib.sameTermAs) Substitute(org.apache.jena.sparql.core.Substitute) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) ExtendedIterator(org.apache.jena.util.iterator.ExtendedIterator) Iter(org.apache.jena.atlas.iterator.Iter) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) Triple(org.apache.jena.graph.Triple) Var(org.apache.jena.sparql.core.Var)

Example 25 with BindingBuilder

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();
}
Also used : BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder)

Aggregations

BindingBuilder (org.apache.jena.sparql.engine.binding.BindingBuilder)30 Node (org.apache.jena.graph.Node)19 Var (org.apache.jena.sparql.core.Var)16 Binding (org.apache.jena.sparql.engine.binding.Binding)14 ArrayList (java.util.ArrayList)6 Iterator (java.util.Iterator)4 Iter (org.apache.jena.atlas.iterator.Iter)4 Triple (org.apache.jena.graph.Triple)4 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)4 Predicate (java.util.function.Predicate)3 Graph (org.apache.jena.graph.Graph)3 List (java.util.List)2 Objects (java.util.Objects)2 Function (java.util.function.Function)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 Quad (org.apache.jena.sparql.core.Quad)2 Substitute (org.apache.jena.sparql.core.Substitute)2 SolverLib.nodeTopLevel (org.apache.jena.sparql.engine.main.solver.SolverLib.nodeTopLevel)2 SolverLib.sameTermAs (org.apache.jena.sparql.engine.main.solver.SolverLib.sameTermAs)2 SolverLib.tripleHasEmbTripleWithVars (org.apache.jena.sparql.engine.main.solver.SolverLib.tripleHasEmbTripleWithVars)2