Search in sources :

Example 26 with BindingBuilder

use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.

the class version method execEvaluated.

@Override
public QueryIterator execEvaluated(Binding binding, PropFuncArg subject, Node predicate, PropFuncArg object, ExecutionContext execCxt) {
    List<Binding> results = new ArrayList<>();
    Node subj = subject.getArg();
    Node obj = object.getArg();
    Iterator<SystemInfo> iter = SystemARQ.registeredSubsystems();
    for (; iter.hasNext(); ) {
        SystemInfo info = iter.next();
        if (!isSameOrVar(subj, info.getIRI()))
            continue;
        Node version = NodeFactory.createLiteral(info.getVersion());
        if (!isSameOrVar(obj, version))
            continue;
        BindingBuilder builder = Binding.builder(binding);
        if (subj.isVariable())
            builder.add(Var.alloc(subj), info.getIRI());
        if (subj.isVariable())
            builder.add(Var.alloc(obj), version);
        results.add(builder.build());
    }
    return QueryIterPlainWrapper.create(results.iterator(), execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) SystemInfo(org.apache.jena.sparql.mgt.SystemInfo) BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList)

Example 27 with BindingBuilder

use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.

the class CSVInputIterator method parseLine.

private Binding parseLine(List<Var> vars, String line) {
    BindingBuilder rowBuilder = Binding.builder();
    List<String> terms = new ArrayList<>();
    int idx = 0;
    while (idx < line.length()) {
        char ch = line.charAt(idx);
        StringBuilder s = new StringBuilder();
        if (ch == '\"' || ch == '\'') {
            char qCh = ch;
            idx++;
            while (idx < line.length()) {
                ch = line.charAt(idx);
                idx++;
                if (ch == qCh)
                    break;
                // escapes??
                s.append(ch);
            }
            if (ch != qCh)
                throw new QueryException(String.format("Error Parsing CSV results at Line %d  - Unterminated quoted string", this.lineNum));
            if (idx < line.length()) {
                ch = line.charAt(idx);
                if (ch != ',')
                    throw new QueryException(String.format("Error Parsing CSV results at Line %d - Expected comma after quote", this.lineNum));
            }
        } else {
            while (idx < line.length()) {
                ch = line.charAt(idx);
                if (ch == ',')
                    break;
                idx++;
                // escapes
                s.append(ch);
            }
        }
        terms.add(s.toString());
        // Looking at , or EOL.
        if (ch == ',' && idx == line.length() - 1) {
            // EOL
            terms.add("");
            break;
        }
        // Skip ","
        idx++;
    }
    if (terms.size() != vars.size())
        throw new QueryException(String.format("Error Parsing CSV results at Line %d - The result row '%s' has %d items when %d was expected", this.lineNum, line, terms.size(), vars.size()));
    for (int i = 0; i < vars.size(); i++) rowBuilder.add(vars.get(i), NodeFactory.createLiteral(terms.get(i)));
    return rowBuilder.build();
}
Also used : QueryException(org.apache.jena.query.QueryException) BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) ArrayList(java.util.ArrayList)

Example 28 with BindingBuilder

use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.

the class RDFInput method buildRowsOrdered.

private void buildRowsOrdered(Resource root, int count) {
    Model m = root.getModel();
    BindingBuilder builder = Binding.builder();
    // Assume one result set per file.
    for (int index = 1; ; index++) {
        Literal ind = m.createTypedLiteral(index, XSDDatatype.XSDinteger);
        StmtIterator sIter = m.listStatements(null, ResultSetGraphVocab.index, ind);
        if (!sIter.hasNext())
            break;
        Statement s = sIter.nextStatement();
        if (sIter.hasNext())
            Log.warn(this, "More than one solution: index = " + index);
        Resource soln = s.getSubject();
        Binding rb = buildBinding(builder, soln);
        rows.add(rb);
        sIter.close();
    }
    if (rows.size() != count)
        Log.warn(this, "Found " + rows.size() + ": expected " + count);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder)

Example 29 with BindingBuilder

use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.

the class RDFInput method buildRows.

private void buildRows(Resource root) {
    // Now the results themselves
    int count = 0;
    StmtIterator solnIter = root.listProperties(ResultSetGraphVocab.solution);
    BindingBuilder builder = Binding.builder();
    for (; solnIter.hasNext(); ) {
        Resource soln = solnIter.nextStatement().getResource();
        count++;
        Binding rb = buildBinding(builder, soln);
        rows.add(rb);
    }
    solnIter.close();
    if (root.hasProperty(ResultSetGraphVocab.size)) {
        try {
            int size = root.getRequiredProperty(ResultSetGraphVocab.size).getInt();
            if (size != count)
                Log.warn(this, "Warning: Declared size = " + size + " : Count = " + count);
        } catch (JenaException rdfEx) {
        }
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) JenaException(org.apache.jena.shared.JenaException) BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder)

Example 30 with BindingBuilder

use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.

the class versionARQ method execEvaluated.

@Override
public QueryIterator execEvaluated(Binding binding, PropFuncArg subject, Node predicate, PropFuncArg object, ExecutionContext execCxt) {
    BindingBuilder builder = Binding.builder(binding);
    Node subj = subject.getArg();
    if (!isSameOrVar(subj, arq))
        IterLib.noResults(execCxt);
    if (subj.isVariable())
        builder.add(Var.alloc(subj), arq);
    Node obj = object.getArg();
    if (!isSameOrVar(obj, version))
        IterLib.noResults(execCxt);
    if (obj.isVariable())
        builder.add(Var.alloc(obj), version);
    return IterLib.result(builder.build(), execCxt);
}
Also used : BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Node(org.apache.jena.graph.Node)

Aggregations

BindingBuilder (org.apache.jena.sparql.engine.binding.BindingBuilder)30 Node (org.apache.jena.graph.Node)19 Var (org.apache.jena.sparql.core.Var)16 Binding (org.apache.jena.sparql.engine.binding.Binding)14 ArrayList (java.util.ArrayList)6 Iterator (java.util.Iterator)4 Iter (org.apache.jena.atlas.iterator.Iter)4 Triple (org.apache.jena.graph.Triple)4 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)4 Predicate (java.util.function.Predicate)3 Graph (org.apache.jena.graph.Graph)3 List (java.util.List)2 Objects (java.util.Objects)2 Function (java.util.function.Function)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 Quad (org.apache.jena.sparql.core.Quad)2 Substitute (org.apache.jena.sparql.core.Substitute)2 SolverLib.nodeTopLevel (org.apache.jena.sparql.engine.main.solver.SolverLib.nodeTopLevel)2 SolverLib.sameTermAs (org.apache.jena.sparql.engine.main.solver.SolverLib.sameTermAs)2 SolverLib.tripleHasEmbTripleWithVars (org.apache.jena.sparql.engine.main.solver.SolverLib.tripleHasEmbTripleWithVars)2