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 Collection<RippleList> reduce(final InputStream from) throws RippleException { Collector<RippleList> results = new Collector<>(); QueryEngine qe = getTestQueryEngine(); QueryPipe actualPipe = new QueryPipe(qe, results); actualPipe.put(from); actualPipe.close(); Collection<RippleList> c = results.stream().collect(Collectors.toCollection(() -> new LinkedList<>())); return c; }
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); }
public Object eval(final String script) throws ScriptException { results.clear(); try { queryPipe.accept(script); } catch (RippleException e) { throw new ScriptException(e); } if (0 == results.size()) { return null; } else { for (Object result : results) { RippleList l = (RippleList) result; if (!l.isNil()) { return toJavaObject(l.getFirst()); } } return null; } }
public void accept(final String expr) throws RippleException { try { try (InputStream input = new ByteArrayInputStream((expr + "\n").getBytes())) { put(input); } } catch (IOException e) { throw new RippleException(e); } } }
protected Collection<RippleList> reduce(final String from) throws RippleException { Collector<RippleList> results = new Collector<>(); QueryEngine qe = getTestQueryEngine(); QueryPipe actualPipe = new QueryPipe(qe, results); actualPipe.accept(from + "\n"); actualPipe.close(); Collection<RippleList> c = results.stream().collect(Collectors.toCollection(() -> new LinkedList<>())); return c; }
Collector<RippleList> expected = new Collector<>(); Collector<RippleList> results = new Collector<>(); QueryPipe qp = new QueryPipe(qe, results); ModelConnection mc = qe.getConnection(); expr[j] = bytes[rand.nextInt(bytes.length)]; qp.accept(new String(expr)); qp.accept(".\n"); qp.accept(".\n"); qp.accept(".\n"); qp.accept("2 3 add.\n"); expected.clear(); expected.accept(createStack(mc, five)); qp.close();
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)); qp.accept("105" + " ((1 2 3 4 5) 0 add fold.) {7}" + " add {6} sub.\n"); qp.accept("(1 2) each. 3 add.\n"); expected.clear(); expected.accept(createStack(mc, four)); assertCollectorsEqual(expected, results); qp.close();