Search in sources :

Example 66 with Node

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);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Node(org.apache.jena.graph.Node) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

Example 67 with Node

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);
    }
}
Also used : Node(org.apache.jena.graph.Node)

Example 68 with Node

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));
}
Also used : Path(org.apache.jena.sparql.path.Path) Node(org.apache.jena.graph.Node)

Example 69 with Node

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.
}
Also used : Path(org.apache.jena.sparql.path.Path) P_Mod(org.apache.jena.sparql.path.P_Mod) Node(org.apache.jena.graph.Node)

Example 70 with Node

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);
}
Also used : Node(org.apache.jena.graph.Node)

Aggregations

Node (org.apache.jena.graph.Node)681 Test (org.junit.Test)191 Triple (org.apache.jena.graph.Triple)98 BaseTest (org.apache.jena.atlas.junit.BaseTest)85 Var (org.apache.jena.sparql.core.Var)84 ArrayList (java.util.ArrayList)55 Graph (org.apache.jena.graph.Graph)46 Binding (org.apache.jena.sparql.engine.binding.Binding)40 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)36 Quad (org.apache.jena.sparql.core.Quad)35 LabelToNode (org.apache.jena.riot.lang.LabelToNode)28 RDFNode (org.apache.jena.rdf.model.RDFNode)25 HashMap (java.util.HashMap)22 Model (org.apache.jena.rdf.model.Model)18 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)18 NodeId (org.apache.jena.tdb.store.NodeId)18 NodeWritable (org.apache.jena.hadoop.rdf.types.NodeWritable)16 Token (org.apache.jena.riot.tokens.Token)16 BasicPattern (org.apache.jena.sparql.core.BasicPattern)16 NodeValue (org.apache.jena.sparql.expr.NodeValue)16