protected void abort() { if (null != evaluator) { evaluator.stop(); } } }
public QueryEngine(final Model model, final PrintStream out, final PrintStream err) throws RippleException { this(model, new LazyStackEvaluator(), out, err); }
public void write(final byte[] b, final int beginIndex, final int length) throws IOException { for (int i = beginIndex; i < length && i < b.length; i++) { write(b[i]); } }
@Test public void testQueries() throws Exception { Model model = getTestModel(); StackEvaluator eval = new LazyStackEvaluator(); QueryEngine qe = new QueryEngine(model, eval, System.out, System.err); Collector<RippleList> expected = new Collector<>(); Collector<RippleList> results = new Collector<>(); QueryPipe qp = new QueryPipe(qe, results); ModelConnection mc = qe.getConnection(); qp.accept("2 3 add .\n"); expected.clear(); expected.accept(createStack(mc, five)); assertCollectorsEqual(expected, results); qp.accept("105" + " ((1 2 3 4 5) 0 add fold.) {7}" + " add {6} sub.\n"); expected.clear(); expected.accept(createStack(mc, zero)); assertCollectorsEqual(expected, results); qp.accept("(1 2) each. 3 add.\n"); expected.clear(); expected.accept(createStack(mc, four)); expected.accept(createStack(mc, five)); assertCollectorsEqual(expected, results); qp.close();
public RippleScriptEngine(final ScriptEngineFactory factory) throws RippleException { this.factory = factory; results = new Collector<>(); URIMap uriMap = new URIMap(); SailConfiguration sailConfig = new SailConfiguration(uriMap); // TODO: shutDown on failure model = new SesameModel(sailConfig.getSail()); StackEvaluator eval = new LazyStackEvaluator(); QueryEngine queryEngine = new QueryEngine(model, eval, System.out, System.err); queryPipe = new QueryPipe(queryEngine, results); }
protected void assertReducesTo(final String from, final String... to) throws Exception { Collector<RippleList> expected = new Collector<>(), actual = new Collector<>(); QueryEngine qe = getTestQueryEngine(); QueryPipe actualPipe = new QueryPipe(qe, actual); actualPipe.accept(from + "\n"); actualPipe.close(); QueryPipe expectedPipe = new QueryPipe(qe, expected); for (String t : to) { expectedPipe.accept(t + "\n"); } expectedPipe.close(); assertCollectorsEqual(expected, actual); }
protected QueryEngine getTestQueryEngine() throws RippleException { if (null == queryEngine) { StackEvaluator eval = new LazyEvaluatingIterator.WrappingEvaluator(); //StackEvaluator eval = new LazyStackEvaluator(); queryEngine = new QueryEngine(getTestModel(), eval, System.out, System.err); } return queryEngine; }
public void execute(final QueryEngine qe, final ModelConnection mc) throws RippleException { final Collector<RippleList> expressions = new Collector<>(); final Sink<RippleList> exprSink = l -> { // Note: the first element of the list will also be a list final RippleList stack = ((RippleList) l.getFirst()).invert(); expressions.accept(stack); }; query.evaluate(exprSink, qe, mc); evaluator = qe.getEvaluator(); final Sink<RippleList> evaluatorSink = l -> evaluator.apply(l, sink, mc); expressions.writeTo(evaluatorSink); }
public void execute(final QueryEngine qe, final ModelConnection mc) throws RippleException { mc.setNamespace(prefix, null, true); // Note: when a namespace is manually defined, it may both override an // existing prefix with the same name, or duplicate another namespace // with the same URI. qe.getLexicon().removeNamespace(prefix); }
protected void executeProtected() throws RippleException { if (null == queryEngine) { throw new RippleException("null QueryEngine"); } queryEngine.executeCommand(this); }
public void executeCommand(final Command cmd) throws RippleException { cmd.execute(this, connection); }
@Override public long skip(final long n) throws IOException { long i; for (i = 0; i < n; i++) { int c = read(); if (-1 == c) { break; } } return i; } }
protected void stopProtected() { abort(); } }
private void alert(final String s) { queryEngine.getErrorPrintStream().println("\n" + s + "\n"); }
@Override public boolean hasNext() throws RippleException { while (true) { if (solutions.size() > 0) { return true; } else if (intermediates.size() > 0) { reduce(intermediates.remove(0)); } else { return false; } } }
private void addCommand(final Command cmd) { cmd.setQueryEngine(queryEngine); taskQueue.add(cmd); }
public QueryEngine(final Model model) throws RippleException { this(model, new LazyStackEvaluator(), System.out, System.err); }
public void write(final byte[] b) throws IOException { for (byte aB : b) { write(aB); } }
public void execute(final QueryEngine qe, final ModelConnection mc) throws RippleException { qe.getLexicon().putTemporaryValue(name.getName(), value); }
protected void handleCommand(Command command) throws RippleException { command.execute(queryEngine, connection); connection.commit(); }