Search in sources :

Example 1 with BindingMap

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);
}
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 2 with BindingMap

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

Example 3 with BindingMap

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);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) Var(org.apache.jena.sparql.core.Var) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) ResultSet(org.apache.jena.query.ResultSet) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 4 with BindingMap

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

Example 5 with BindingMap

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

Aggregations

BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)29 Node (org.apache.jena.graph.Node)18 Var (org.apache.jena.sparql.core.Var)12 Binding (org.apache.jena.sparql.engine.binding.Binding)10 ArrayList (java.util.ArrayList)8 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)5 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)4 ResultSet (org.apache.jena.query.ResultSet)3 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)3 SQLException (java.sql.SQLException)2 SqlNode (org.apache.jena.sdb.core.sqlnode.SqlNode)2 BuilderResultSet (org.apache.jena.sparql.sse.builders.BuilderResultSet)2 ResultSet (java.sql.ResultSet)1 List (java.util.List)1 Function (java.util.function.Function)1 CSVParser (org.apache.jena.atlas.csv.CSVParser)1 IteratorDelayedInitialization (org.apache.jena.atlas.iterator.IteratorDelayedInitialization)1 JsonArray (org.apache.jena.atlas.json.JsonArray)1 JsonObject (org.apache.jena.atlas.json.JsonObject)1 JsonValue (org.apache.jena.atlas.json.JsonValue)1