Search in sources :

Example 1 with BindingHashMap

use of org.apache.jena.sparql.engine.binding.BindingHashMap 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) {
        BindingHashMap bindingFull = new BindingHashMap();
        BindingHashMap bindingPart = new BindingHashMap();
        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);
        pData.add(bindingPart);
    }
}
Also used : BindingHashMap(org.apache.jena.sparql.engine.binding.BindingHashMap) Before(org.junit.Before)

Example 2 with BindingHashMap

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

the class LinearIndex method toBinding.

static Binding toBinding(HashIndexTable.Key key, Map<Var, Integer> mappings) {
    Node[] values = key.getNodes();
    BindingHashMap b = new BindingHashMap();
    for (Map.Entry<Var, Integer> mapping : mappings.entrySet()) {
        Node value = values[mapping.getValue()];
        if (value != null)
            b.add(mapping.getKey(), value);
    }
    return b;
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) BindingHashMap(org.apache.jena.sparql.engine.binding.BindingHashMap) Map(java.util.Map) BindingHashMap(org.apache.jena.sparql.engine.binding.BindingHashMap)

Example 3 with BindingHashMap

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

the class ValuesHandler method build.

@Override
public void build() {
    // remove all the vars that have been set
    List<Var> vars = new ArrayList<Var>(valuesTable.keySet());
    vars.removeAll(valueMap.keySet());
    if (vars.isEmpty()) {
        return;
    }
    List<Binding> bindings = new ArrayList<Binding>();
    int count = valuesTable.get(vars.get(0)).size();
    for (int i = 0; i < count; i++) {
        BindingHashMap b = new BindingHashMap();
        for (Var var : vars) {
            List<Node> lst = valuesTable.get(var);
            // must be square
            if (lst.size() != count) {
                throw new QueryBuildException(String.format("The number of data items for %s (%s) is not the same as for %s (%s)", var, lst.size(), vars.get(0), count));
            }
            Node n = lst.get(i);
            if (n != null) {
                if (valueMap.containsKey(n)) {
                    n = valueMap.get(n);
                }
                b.add(var, n);
            }
        }
        if (!b.isEmpty()) {
            bindings.add(b);
        }
    }
    if (!bindings.isEmpty()) {
        query.setValuesDataBlock(vars, bindings);
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) QueryBuildException(org.apache.jena.query.QueryBuildException) ArrayList(java.util.ArrayList) BindingHashMap(org.apache.jena.sparql.engine.binding.BindingHashMap)

Example 4 with BindingHashMap

use of org.apache.jena.sparql.engine.binding.BindingHashMap 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) {
    BindingHashMap retval = new BindingHashMap();
    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;
        retval.add(v, n);
    }
    return retval;
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) BindingHashMap(org.apache.jena.sparql.engine.binding.BindingHashMap)

Aggregations

BindingHashMap (org.apache.jena.sparql.engine.binding.BindingHashMap)4 Node (org.apache.jena.graph.Node)3 Var (org.apache.jena.sparql.core.Var)3 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 QueryBuildException (org.apache.jena.query.QueryBuildException)1 Binding (org.apache.jena.sparql.engine.binding.Binding)1 Before (org.junit.Before)1