Search in sources :

Example 6 with ResultSetStream

use of org.apache.jena.sparql.engine.ResultSetStream in project jena by apache.

the class TestResultSet method make.

private ResultSet make(String var1, Node val1, String var2, Node val2) {
    BindingMap b = BindingFactory.create();
    b.add(Var.alloc(var1), val1);
    b.add(Var.alloc(var2), val2);
    List<String> vars = new ArrayList<>();
    vars.add(var1);
    vars.add(var2);
    QueryIterator qIter = QueryIterSingleton.create(b, null);
    ResultSet rs = new ResultSetStream(vars, null, qIter);
    return rs;
}
Also used : QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ArrayList(java.util.ArrayList) BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 7 with ResultSetStream

use of org.apache.jena.sparql.engine.ResultSetStream in project jena by apache.

the class TestResultSet method make2.

private ResultSet make2(String var, Node val) {
    BindingMap b1 = BindingFactory.create();
    b1.add(Var.alloc(var), val);
    BindingMap b2 = BindingFactory.create();
    b2.add(Var.alloc(var), val);
    List<String> vars = new ArrayList<>();
    vars.add(var);
    List<Binding> solutions = new ArrayList<>();
    solutions.add(b1);
    solutions.add(b2);
    QueryIterator qIter = new QueryIterPlainWrapper(solutions.iterator(), null);
    ResultSet rs = new ResultSetStream(vars, null, qIter);
    return rs;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ArrayList(java.util.ArrayList) BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 8 with ResultSetStream

use of org.apache.jena.sparql.engine.ResultSetStream in project jena by apache.

the class XMLInputSAX method worker.

private void worker(InputSource in, Model model) {
    if (model == null)
        model = GraphFactory.makeJenaDefaultModel();
    try {
        XMLReader xr = XMLReaderFactory.createXMLReader();
        xr.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
        // ResultSetXMLHandler1 handler = new ResultSetXMLHandler1() ;
        ResultSetXMLHandler2 handler = new ResultSetXMLHandler2();
        xr.setContentHandler(handler);
        xr.parse(in);
        if (handler.isBooleanResult) {
            // Set superclass member
            set(handler.askResult);
            return;
        }
        ResultSetStream rss = new ResultSetStream(handler.variables, model, new QueryIterPlainWrapper(handler.results.iterator()));
        // Set superclass member
        set(rss);
    } catch (SAXException ex) {
        throw new ResultSetException("Problems parsing file (SAXException)", ex);
    } catch (IOException ex) {
        throw new ResultSetException("Problems parsing file (IOException)", ex);
    }
}
Also used : QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) IOException(java.io.IOException) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 9 with ResultSetStream

use of org.apache.jena.sparql.engine.ResultSetStream in project jena by apache.

the class EvaluatorSimple method dump.

private static void dump(Table table) {
    System.out.println("Table: " + Lib.className(table));
    QueryIterator qIter = table.iterator(null);
    ResultSet rs = new ResultSetStream(table.getVarNames(), null, table.iterator(null));
    ResultSetFormatter.out(rs);
}
Also used : QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ResultSet(org.apache.jena.query.ResultSet) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 10 with ResultSetStream

use of org.apache.jena.sparql.engine.ResultSetStream in project jena by apache.

the class AlgebraExec method main.

public static void main(String[] argv) {
    String BASE = "http://example/";
    BasicPattern bp = new BasicPattern();
    Var var_x = Var.alloc("x");
    Var var_z = Var.alloc("z");
    // ---- Build expression
    bp.add(new Triple(var_x, NodeFactory.createURI(BASE + "p"), var_z));
    Op op = new OpBGP(bp);
    //Expr expr = ExprUtils.parse("?z < 2 ") ;
    Expr expr = new E_LessThan(new ExprVar(var_z), NodeValue.makeNodeInteger(2));
    op = OpFilter.filter(expr, op);
    // ---- Example setup
    Model m = makeModel();
    m.write(System.out, "TTL");
    System.out.println("--------------");
    System.out.print(op);
    System.out.println("--------------");
    // ---- Execute expression
    QueryIterator qIter = Algebra.exec(op, m.getGraph());
    // -------- Either read the query iterator directly ...
    if (false) {
        for (; qIter.hasNext(); ) {
            Binding b = qIter.nextBinding();
            Node n = b.get(var_x);
            System.out.println(NodeFmtLib.displayStr(n));
            System.out.println(b);
        }
        qIter.close();
    } else {
        // -------- Or make ResultSet from it (but not both - reading an
        //          iterator consumes the current solution)
        List<String> varNames = new ArrayList<>();
        varNames.add("x");
        varNames.add("z");
        ResultSet rs = new ResultSetStream(varNames, m, qIter);
        ResultSetFormatter.out(rs);
        qIter.close();
    }
    System.exit(0);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Binding(org.apache.jena.sparql.engine.binding.Binding) Op(org.apache.jena.sparql.algebra.Op) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) BasicPattern(org.apache.jena.sparql.core.BasicPattern) E_LessThan(org.apache.jena.sparql.expr.E_LessThan) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream) Triple(org.apache.jena.graph.Triple) Expr(org.apache.jena.sparql.expr.Expr) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ResultSet(org.apache.jena.query.ResultSet)

Aggregations

ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)14 ArrayList (java.util.ArrayList)10 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)10 ResultSet (org.apache.jena.query.ResultSet)8 Var (org.apache.jena.sparql.core.Var)7 Binding (org.apache.jena.sparql.engine.binding.Binding)7 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)7 Node (org.apache.jena.graph.Node)4 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)4 IOException (java.io.IOException)2 Op (org.apache.jena.sparql.algebra.Op)2 BuilderResultSet (org.apache.jena.sparql.sse.builders.BuilderResultSet)2 BufferedReader (java.io.BufferedReader)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Function (java.util.function.Function)1 CSVParser (org.apache.jena.atlas.csv.CSVParser)1 Triple (org.apache.jena.graph.Triple)1 RDFNode (org.apache.jena.rdf.model.RDFNode)1 RiotException (org.apache.jena.riot.RiotException)1