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;
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations