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);
}
}
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;
}
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);
}
}
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;
}
Aggregations