Search in sources :

Example 16 with BindingBuilder

use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.

the class QueryIteratorMapped method moveToNextBinding.

@Override
protected Binding moveToNextBinding() {
    Binding b = super.moveToNextBinding();
    if (this.varMapping == null)
        return b;
    // Apply remapping
    BindingBuilder builder = Binding.builder();
    Iterator<Var> vs = b.vars();
    while (vs.hasNext()) {
        Var v = vs.next();
        Node value = b.get(v);
        // Only remap non-null variables for which there is a mapping
        if (value == null)
            continue;
        if (this.varMapping.containsKey(v)) {
            builder.add(this.varMapping.get(v), value);
        }
    }
    return builder.build();
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node)

Example 17 with BindingBuilder

use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.

the class TransformFilterInequality method buildTable.

private static Table buildTable(Map<Var, Set<NodeValue>> possibleValues) {
    if (possibleValues.size() == 0)
        return TableFactory.createEmpty();
    Table table = TableFactory.create();
    // Although each filter condition must apply for a row to be accepted
    // they are actually independent since only one condition needs to fail
    // for the filter to reject the row. Thus for each unique variable/value
    // combination a single row must be produced
    BindingBuilder builder = Binding.builder();
    for (Var v : possibleValues.keySet()) {
        for (NodeValue value : possibleValues.get(v)) {
            Binding b = builder.reset().add(v, value.asNode()).build();
            table.addBinding(b);
        }
    }
    return table;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Var(org.apache.jena.sparql.core.Var)

Example 18 with BindingBuilder

use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.

the class SolverLibTDB method convToBinding.

static Binding convToBinding(BindingNodeId bindingNodeIds, NodeTable nodeTable) {
    if (true)
        return new BindingTDB(bindingNodeIds, nodeTable);
    else {
        // Makes nodes immediately. Causing unnecessary NodeTable accesses
        // (e.g. project)
        BindingBuilder builder = Binding.builder();
        for (Var v : bindingNodeIds) {
            NodeId id = bindingNodeIds.get(v);
            Node n = nodeTable.getNodeForNodeId(id);
            builder.add(v, n);
        }
        return builder.build();
    }
}
Also used : BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb2.store.NodeId)

Example 19 with BindingBuilder

use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.

the class NodeTransformLib method transform.

public static Binding transform(Binding b, NodeTransform transform) {
    BindingBuilder b2 = Binding.builder();
    List<Var> vars = Iter.toList(b.vars());
    for (Var v : vars) {
        Var v2 = (Var) transform.apply(v);
        b2.add(v2, b.get(v));
    }
    return b2.build();
}
Also used : BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder)

Example 20 with BindingBuilder

use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.

the class AbstractRewriter method rewrite.

/**
 * Rewrite a binding.
 *
 * @param binding The binding to rewrite
 * @return The rewritten binding.
 */
protected final Binding rewrite(Binding binding) {
    BindingBuilder builder = Binding.builder();
    Iterator<Var> iter = binding.vars();
    while (iter.hasNext()) {
        Var v = iter.next();
        Node n = changeNode(binding.get(v));
        n = n.equals(v) ? binding.get(v) : n;
        builder.add(v, n);
    }
    return builder.build();
}
Also used : BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node)

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