use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class container method execEvaluatedCalc.
// Ask by finding all the rdf:_N + rdf:type
private QueryIterator execEvaluatedCalc(Binding binding, Node containerNode, Node predicate, Node member, ExecutionContext execCxt) {
Graph graph = execCxt.getActiveGraph();
if (!containerNode.isVariable()) {
// Container a ground term.
if (!GraphContainerUtils.isContainer(execCxt.getActiveGraph(), containerNode, typeNode))
return IterLib.noResults(execCxt);
return oneContainer(binding, containerNode, member, execCxt);
}
// Container a variable.
Collection<Node> c = null;
if (member.isVariable())
c = findContainers(graph, typeNode);
else
c = findContainingContainers(graph, typeNode, member);
QueryIterConcat cIter = new QueryIterConcat(execCxt);
Var cVar = Var.alloc(containerNode);
for (Node cn : c) {
//Binding the container node.
Binding b = BindingFactory.binding(binding, cVar, cn);
Node m = member;
// Special case of ?x rdfs:member ?x
if (Var.isVar(member) && member.equals(cVar)) {
m = cn;
}
cIter.add(oneContainer(b, cn, m, execCxt));
}
return cIter;
//throw new QueryFatalException(Utils.className(this)+": Arg 1 is too hard : "+containerNode) ;
}
use of org.apache.jena.sparql.engine.binding.Binding 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.Binding in project jena by apache.
the class strSplit method execEvaluated.
@Override
public QueryIterator execEvaluated(final Binding binding, final Node subject, final Node predicate, final PropFuncArg object, final ExecutionContext execCxt) {
if (!Var.isVar(subject))
throw new ExprEvalException("Subject is not a variable (" + subject + ")");
if (object.getArgListSize() != 2)
throw new ExprEvalException("Object list must contain exactly two arguments, the string to split and a regular expression");
String s = object.getArg(0).getLiteralLexicalForm();
String regex = object.getArg(1).getLiteralLexicalForm();
final Var subjectVar = Var.alloc(subject);
// StrUtils will also trim whitespace
String[] tokens = StrUtils.split(s, regex);
Iterator<Binding> it = Iter.map(Arrays.asList(tokens).iterator(), item -> BindingFactory.binding(binding, subjectVar, NodeFactory.createLiteral(item)));
return new QueryIterPlainWrapper(it, execCxt);
}
use of org.apache.jena.sparql.engine.binding.Binding 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.Binding in project jena by apache.
the class QueryTest method unique.
private static ResultSetRewindable unique(ResultSetRewindable results) {
// VERY crude. Utilises the fact that bindings have value equality.
List<Binding> x = new ArrayList<>();
Set<Binding> seen = new HashSet<>();
for (; results.hasNext(); ) {
Binding b = results.nextBinding();
if (seen.contains(b))
continue;
seen.add(b);
x.add(b);
}
QueryIterator qIter = new QueryIterPlainWrapper(x.iterator());
ResultSet rs = new ResultSetStream(results.getResultVars(), ModelFactory.createDefaultModel(), qIter);
return ResultSetFactory.makeRewindable(rs);
}
Aggregations