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 QueryPipe(final QueryEngine queryEngine, final Sink<RippleList> resultSink) throws RippleException { connection = queryEngine.getConnection(); (resultBuffer, queryResultHistory); recognizerAdapter = new RecognizerAdapter(queryEngine.getErrorPrintStream()) { protected void handleQuery(ListAST ast) throws RippleException { synchronized (mutex) { queryEngine.getErrorPrintStream());
protected void executeProtected() throws RippleException { if (null == queryEngine) { throw new RippleException("null QueryEngine"); } queryEngine.executeCommand(this); }
public void evaluate(final Sink<RippleList> sink, final QueryEngine qe, final ModelConnection mc) throws RippleException { Sink<Object> uriSink = v -> sink.accept(mc.list().push(v)); qe.getLexicon().uriForQName(nsPrefix, localName, uriSink, mc, qe.getErrorPrintStream()); } }
public RippleSession() throws RippleException { this.undoRedoStack = new UndoRedoStack<>(UNDO_REDO_DEPTH); undoRedoStack.done(new Collector<>()); sail = new MemoryStore(); try { sail.initialize(); } catch (SailException e) { throw new RippleException(e); } Model model = new SesameModel(sail); evaluator = new LazyStackEvaluator(); QueryEngine queryEngine = new QueryEngine(model, evaluator, System.out, System.err); connection = queryEngine.getConnection(); }
Model model = getTestModel(); ModelConnection mc = model.createConnection(); QueryEngine qe = new QueryEngine(model, null, System.out, System.err); ByteArrayOutputStream bos = new ByteArrayOutputStream(); RipplePrintStream ps = new RipplePrintStream(new PrintStream(bos), qe.getLexicon());
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); }
ListAST foobar2 = new ListAST( new StringLiteralAST("foo2"), new ListAST(new StringLiteralAST("bar2"), new ListAST())); IRI foobarUri = sail.getValueFactory().createIRI(qe.getLexicon().getDefaultNamespace() + "foobar"); Literal foo = sail.getValueFactory().createLiteral("foo", XMLSchema.STRING); Literal foo2 = sail.getValueFactory().createLiteral("foo2", XMLSchema.STRING); qe.executeCommand(undefCmd); count = countStatements(sc.getStatements(foobarUri, null, null, false)); assertEquals(0, count); qe.executeCommand(defCmd); count = countStatements(sc.getStatements(foobarUri, null, null, false)); assertEquals(3, count); qe.executeCommand(undefCmd); count = countStatements(sc.getStatements(foobarUri, null, null, false)); assertEquals(0, count); qe.executeCommand(defCmd); count = countStatements(sc.getStatements(foobarUri, null, null, false)); assertEquals(3, count); assertTrue(obj.equals(foo)); assertFalse(obj.equals(foo2)); qe.executeCommand(redefCmd); count = countStatements(sc.getStatements(foobarUri, null, null, false)); assertEquals(3, count); qe.executeCommand(undefCmd);
public QueryEngine(final Model model, final StackEvaluator evaluator, final PrintStream out, final PrintStream err) throws RippleException { this.model = model; this.evaluator = evaluator; lexicon = new Lexicon(model); printStream = new RipplePrintStream(out, lexicon); errorPrintStream = err; connection = model.createConnection(new LexiconUpdater(lexicon)); initializeLexicon(); // TODO: the default value is a temporary fix for version conflicts due to property renaming String defaultNamespace = Ripple.getConfiguration().getString( Ripple.DEFAULT_NAMESPACE, "http://example.org/ns/"); // Set the default namespace. //mc.setNamespace( "", defaultNamespace, false ); // FIXME: these should not be hard-coded getLexicon().addCommonNamespaces(connection); getLexicon().setNamespace("", defaultNamespace, connection); connection.commit(); }
queryEngine = qe; RecognizerAdapter ra = new RecognizerAdapter(qe.getErrorPrintStream()) { protected void handleQuery(final ListAST query) throws RippleException { addCommand(new VisibleQueryCommand(query, queryResultHistory)); qe.getErrorPrintStream()); qe.getPrintStream()); } catch (Throwable t) { throw new RippleException(t);
private void alert(final String s) { queryEngine.getErrorPrintStream().println("\n" + s + "\n"); }
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); }
QueryEngine qe = new QueryEngine(model, eval, System.out, errStream); Collector<RippleList> expected = new Collector<>(); Collector<RippleList> results = new Collector<>(); QueryPipe qp = new QueryPipe(qe, results); ModelConnection mc = qe.getConnection();
public void evaluate(final Sink<RippleList> sink, final QueryEngine qe, final ModelConnection mc) throws RippleException { Sink<Object> uriSink = v -> sink.accept(mc.list().push(v)); qe.getLexicon().resolveKeyword(name, uriSink, mc, qe.getErrorPrintStream()); } }
public void execute(final QueryEngine qe, final ModelConnection mc) throws RippleException { qe.getLexicon().putTemporaryValue(name.getName(), value); }
public void evaluate(final Sink<RippleList> sink, final QueryEngine qe, final ModelConnection mc) throws RippleException { Sink<RippleList> typeSink = l -> { Object type1 = l.getFirst(); Value t = mc.toRDF(type1); if (t instanceof IRI) { Object p = mc.valueOf(value, (IRI) t); sink.accept(mc.list().push(p)); } else { qe.getErrorPrintStream().println("datatype does not map to a URI reference: " + type1); } }; type.evaluate(typeSink, qe, mc); }
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();
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 void execute(final QueryEngine qe, final ModelConnection mc) throws RippleException { Collector<RippleList> expressions = new Collector<>(); list.evaluate(expressions, qe, mc); if (expressions.size() == 0) { qe.getErrorPrintStream().println( "Warning: the given expression did not resolve to a value."); } else if (expressions.size() > 1) { qe.getErrorPrintStream().println( "Warning: the given expression resolved to multiple values."); } else { // Note: the first element of the list will also be a list RippleList expr = (RippleList) expressions.iterator().next().getFirst(); //System.out.println( "exprList = " + exprList ); Value id = mc.valueOf(java.net.URI.create(qe.getLexicon().getDefaultNamespace() + name)); expr.setRDFEquivalent(id); mc.internalize(expr); mc.commit(); qe.getLexicon().addURI((IRI) id); mc.getModel().getSpecialValues().put(id, expr); } }
private void updateCompletors() { logger.trace("updating completors"); List<Completer> completors = new ArrayList<>(); try { Lexicon lex = queryEngine.getLexicon(); synchronized (lex) { completors.add(lex.getCompletor()); } ArrayList<String> directives = new ArrayList<>(); directives.add("@help"); directives.add("@list"); directives.add("@prefix"); directives.add("@quit"); directives.add("@relist"); directives.add("@show"); directives.add("@unlist"); directives.add("@unprefix"); completors.add( new DirectiveCompletor(directives)); try { // This makes candidates from multiple completors available at once. Completer multiCompletor = new AggregateCompleter(completors); reader.addCompleter(multiCompletor); } catch (Throwable t) { throw new RippleException(t); } } catch (RippleException e) { logger.error("failed to update completors", e); } }