Skip to content

Using CSPARQL with RSP4J

Pieter Bonte edited this page Oct 13, 2021 · 4 revisions

Using CSPARQL 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 CSPARQL 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.

CSPARQL Construct example

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



        String query1 = "REGISTER QUERY GetColours AS "
                + "PREFIX ex: <http://myexample.org/> "
                + "CONSTRUCT { ?s ?p ?o }"
                + "FROM STREAM <http://test/stream> [RANGE 5s STEP 1s] "
                + "WHERE { ?s ?p ?o }";


        CSPARQLEngineRSP4J csparql = new CSPARQLEngineRSP4J();
        csparql.register(inputStream);
        csparql.setConstructOutput(outputStream);

        ContinuousQuery<Graph, Graph, Binding, Graph> cq = csparql.parseCSPARQLConstruct(query1);

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

CSPARQL Select example

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



        String query1 = "REGISTER QUERY GetColours AS "
                + "PREFIX ex: <http://myexample.org/> "
                + "SELECT ?s ?p ?o "
                + "FROM STREAM <http://test/stream> [RANGE 5s STEP 1s] "
                + "WHERE { ?s ?p ?o }";


        CSPARQLEngineRSP4J csparql = new CSPARQLEngineRSP4J();
        csparql.register(inputStream);
        csparql.setSelectOutput(outputStream);

        ContinuousQuery<Graph, Graph, Binding, Binding> cq = csparql.parseCSPARQLSelect(query1);

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

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