Skip to content

Using CQELS with RSP4J

Pieter Bonte edited this page Sep 9, 2021 · 4 revisions

Using CQELS with RSP4J

RSP4J allows to wrap existing engines such as CSPARQL or CQELS, allowing to easily interchange them while using the same interfaces to access the engines.

The code example below shows how one can register a CQELS Construct query using RSP4J interfaces. The same input and output streams (DataStream) can be used to send input and retrieve the output as with any RSP4J program.

CQELS Construct example

        DataStream<Graph> inputStream = ...
        DataStream<Graph> outputStream = new DataStreamImpl<>("http://out/stream");


        String query1 = "CONSTRUCT{?s ?p ?o} WHERE {"
                + "STREAM <http://test/stream> [RANGE 15s] {?s ?p ?o .}"
                + "}";


        CQELSEngineRSP4J cqels = new CQELSEngineRSP4J();
        cqels.register(inputStream);
        cqels.setConstructOutput(outputStream);

        ContinuousQuery<Graph, Binding, Binding, Graph> cq = cqels.parseCQELSConstruct(query1);

        ContinuousQueryExecution<Graph, Binding, Binding, Graph> cqe = cqels.parseConstruct(cq);

CQELS Select example

        DataStream<Graph> inputStream = ...
        DataStream<Binding> outputStream = new DataStreamImpl<>("http://out/stream");


        String query1 = "Select * WHERE {"
                + "STREAM <http://test/stream> [RANGE 15s] {?s ?p ?o .}"
                + "}";


        CQELSEngineRSP4J cqels = new CQELSEngineRSP4J();
        cqels.register(inputStream);
        cqels.setSelectOutput(outputStream);

        ContinuousQuery<Graph, Binding, Binding, Binding> cq = cqels.parseCQELSSelect(query1);

        ContinuousQueryExecution<Graph, Binding, Binding, Binding> cqe = cqels.parseSelect(cq);

To get you easily started, you can find these example in the test cases of the cqels-rsp4j module!