use of org.apache.jena.sparql.engine.binding.BindingMap in project jena by apache.
the class splitIRI method subjectIsIRI.
private QueryIterator subjectIsIRI(Node subject, PropFuncArg argObject, Binding binding, ExecutionContext execCxt) {
String namespace = subject.getNameSpace();
String localname = subject.getLocalName();
Node namespaceNode = argObject.getArg(0);
Node localnameNode = argObject.getArg(1);
// New binding to return.
BindingMap b = null;
if (Var.isVar(namespaceNode) || Var.isVar(localnameNode))
b = BindingFactory.create(binding);
if (// .isVariable() )
Var.isVar(namespaceNode)) {
b.add(Var.alloc(namespaceNode), NodeFactory.createURI(namespace));
// but it's possible for strange URI schemes.
if (localnameNode.isVariable() && namespaceNode.getName() == localnameNode.getName())
localnameNode = NodeFactory.createURI(namespace);
} else {
String ns = null;
// Allow both IRIs and plain literals in the namespace position.
if (namespaceNode.isURI())
ns = namespaceNode.getURI();
if (namespaceNode.isLiteral())
ns = NodeUtils.stringLiteral(namespaceNode);
if (ns == null || !ns.equals(namespace))
return IterLib.noResults(execCxt);
// Fall through and proceed to localname
}
if (Var.isVar(localnameNode))
b.add(Var.alloc(localnameNode), NodeFactory.createLiteral(localname));
else {
// Only string literals (plain strings or datatype xsd:string)
String lc = NodeUtils.stringLiteral(localnameNode);
if (lc == null || !lc.equals(localname))
return IterLib.noResults(execCxt);
}
Binding b2 = (b == null) ? binding : b;
return IterLib.result(b, execCxt);
}
use of org.apache.jena.sparql.engine.binding.BindingMap in project jena by apache.
the class listIndex method findIndexMember.
private static QueryIterator findIndexMember(Graph graph, Binding binding, Node listNode, Var varIndex, Var varMember, ExecutionContext execCxt) {
// Iterate over list
List<Node> members = GraphList.members(new GNode(graph, listNode));
List<Binding> bindings = new ArrayList<>();
for (int i = 0; i < members.size(); i++) {
Node idx = NodeFactoryExtra.intToNode(i);
Node member = members.get(i);
BindingMap b = BindingFactory.create(binding);
b.add(varIndex, idx);
b.add(varMember, member);
bindings.add(b);
}
return new QueryIterPlainWrapper(bindings.iterator(), execCxt);
}
use of org.apache.jena.sparql.engine.binding.BindingMap in project jena by apache.
the class QueryTest method convertToStrings.
private ResultSetRewindable convertToStrings(ResultSetRewindable resultsActual) {
List<Binding> bindings = new ArrayList<>();
while (resultsActual.hasNext()) {
Binding b = resultsActual.nextBinding();
BindingMap b2 = BindingFactory.create();
for (String vn : resultsActual.getResultVars()) {
Var v = Var.alloc(vn);
Node n = b.get(v);
String s;
if (n == null)
s = "";
else if (n.isBlank())
s = "_:" + n.getBlankNodeLabel();
else
s = NodeFunctions.str(n);
b2.add(v, NodeFactory.createLiteral(s));
}
bindings.add(b2);
}
ResultSet rs = new ResultSetStream(resultsActual.getResultVars(), null, new QueryIterPlainWrapper(bindings.iterator()));
return ResultSetFactory.makeRewindable(rs);
}
use of org.apache.jena.sparql.engine.binding.BindingMap in project jena by apache.
the class TestQueryIterSort method randomBinding.
private Binding randomBinding(Var[] vars) {
BindingMap binding = BindingFactory.create();
binding.add(vars[0], NodeFactory.createBlankNode());
binding.add(vars[1], NodeFactory.createURI(randomURI()));
binding.add(vars[2], NodeFactory.createURI(randomURI()));
binding.add(vars[3], NodeFactory.createLiteral(randomString(20)));
binding.add(vars[4], NodeFactory.createBlankNode());
binding.add(vars[5], NodeFactory.createURI(randomURI()));
binding.add(vars[6], NodeFactory.createURI(randomURI()));
binding.add(vars[7], NodeFactory.createLiteral(randomString(5)));
binding.add(vars[8], NodeFactory.createLiteral("" + random.nextInt(), XSDDatatype.XSDinteger));
binding.add(vars[9], NodeFactory.createBlankNode());
return binding;
}
use of org.apache.jena.sparql.engine.binding.BindingMap in project jena by apache.
the class TestSortedDataBag method randomBinding.
private Binding randomBinding(Var[] vars) {
BindingMap binding = BindingFactory.create();
binding.add(vars[0], NodeFactory.createBlankNode());
binding.add(vars[1], NodeFactory.createURI(randomURI()));
binding.add(vars[2], NodeFactory.createURI(randomURI()));
binding.add(vars[3], NodeFactory.createLiteral(randomString(20)));
binding.add(vars[4], NodeFactory.createBlankNode());
binding.add(vars[5], NodeFactory.createURI(randomURI()));
binding.add(vars[6], NodeFactory.createURI(randomURI()));
binding.add(vars[7], NodeFactory.createLiteral(randomString(5)));
binding.add(vars[8], NodeFactory.createLiteral("" + random.nextInt(), XSDDatatype.XSDinteger));
binding.add(vars[9], NodeFactory.createBlankNode());
return binding;
}
Aggregations