use of org.apache.jena.graph.Node 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.graph.Node in project jena by apache.
the class PathEngineN method doOneOrMore.
@Override
protected void doOneOrMore(Path path, Node node, Collection<Node> output) {
Set<Node> visited = visitedAcc();
// Do one step without including.
Iterator<Node> iter1 = eval(path, node);
for (; iter1.hasNext(); ) {
Node n1 = iter1.next();
ALP(n1, path, visited, output);
}
}
use of org.apache.jena.graph.Node in project jena by apache.
the class PathEngineN method doSeq.
@Override
protected void doSeq(Path pathStepLeft, Path pathStepRight, Node node, Collection<Node> output) {
Path part1 = forwardMode ? pathStepLeft : pathStepRight;
Path part2 = forwardMode ? pathStepRight : pathStepLeft;
// Feed one side into the other
Iter<Node> iter = eval(part1, node);
iter.forEachRemaining((n) -> eval(part2, n, output));
}
use of org.apache.jena.graph.Node in project jena by apache.
the class PathEngineN method doMultiLengthPath.
@Override
protected void doMultiLengthPath(Path pathStep, Node node, long min1, long max1, Collection<Node> output) {
if (min1 == P_Mod.UNSET)
// {,N}
min1 = 0;
if (min1 == 0)
output.add(node);
if (max1 == 0)
return;
// The next step
long min2 = dec(min1);
long max2 = dec(max1);
// TODO Rewrite
Path p1 = pathStep;
Path p2 = new P_Mod(pathStep, min2, max2);
if (!forwardMode) {
// Reverse order. Do the second bit first.
Path tmp = p1;
p1 = p2;
p2 = tmp;
// This forces execution to be in the order that it's written, when
// working backwards.
// {N,*} is {*} then {N} backwards != do {N} then do {*} as
// cardinality of the
// two operations is different.
}
// ****
// One step.
Iterator<Node> iter = eval(p1, node);
// Moved on one step
for (; iter.hasNext(); ) {
Node n2 = iter.next();
Iterator<Node> iter2 = eval(p2, n2);
fill(iter2, output);
}
// If no matches, will not call eval and we drop out.
}
use of org.apache.jena.graph.Node in project jena by apache.
the class PathEngineSPARQL method ALP_N.
// This is the worker function for path{*} /counting (non_SPARQL) semantics.
private void ALP_N(Node node, Path path, Set<Node> visited, Collection<Node> output) {
if (visited.contains(node))
return;
// "visited" is nodes on this path (see the matching .remove).
if (!output.add(node))
return;
visited.add(node);
Iterator<Node> iter1 = eval(path, node);
// For each step, add to results and recurse.
for (; iter1.hasNext(); ) {
Node n1 = iter1.next();
ALP_N(n1, path, visited, output);
}
visited.remove(node);
}
Aggregations