Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to execute query over data source using Csparql2 in RSP4J #20

Open
rahuldh2006 opened this issue Feb 14, 2022 · 3 comments
Open

How to execute query over data source using Csparql2 in RSP4J #20

rahuldh2006 opened this issue Feb 14, 2022 · 3 comments

Comments

@rahuldh2006
Copy link

rahuldh2006 commented Feb 14, 2022

In Csparql 1.0, we execute query over data source (static knowledge) as below:

String generalQuery = "SELECT ?val FROM http://localhost:8080/csparql_web_server/demo.rdf "
+ "WHERE {" + rdf.createIRI("http://test#Person") + " " + rdf.createIRI("http://test#hasBrother") + " ?val }";

String updateQuery = "PREFIX : http://www.streamreasoning.org/ontologies/sr4ld2014-onto# "
+ "INSERT DATA "
+ "{ GRAPH http://streamreasoning.org/roomConnection { :room :isConnectedTo :room2 } }";

RDFTable queryResult = engine.evaluateGeneralQueryOverDatasource(generalQuery);
engine.execUpdateQueryOverDatasource(updateQuery);

How do we do similar to above using CSparql 2.0 in RSP4J?

@rahuldh2006 rahuldh2006 changed the title How to execute general query over data source using Csparql2 How to execute general query over data source using Csparql2 in RSP4J Feb 14, 2022
@rahuldh2006 rahuldh2006 changed the title How to execute general query over data source using Csparql2 in RSP4J How to execute query over data source using Csparql2 in RSP4J Feb 14, 2022
@pbonte
Copy link
Collaborator

pbonte commented Feb 14, 2022

Hi @rahuldh2006,

Just to understand the question correctly, this is only for static data?
So you have a named graph http://streamreasoning.org/roomConnection which contains the static data of your rooms?
And then you join it with the stream in a later phase?

KR

@rahuldh2006
Copy link
Author

rahuldh2006 commented Feb 14, 2022

Hi Pieter,

The query above was just example. My use case with RSP4J is :
Use static data model as a context database. Perform stream reasoning on incoming stream, where the reasoning queries would also use the data from this context database. After reasoning, the output stream would update this context database (if any of its data needs to be updated based on the stream).

To achieve the above use case in CSparql2 inside RSP4J, I want to add a static named model like done below in CSparql1.0 :
engine.putStaticNamedModel("http://streamreasoning.org/roomConnection", CsparqlUtils.serializeRDFFile("examples_files/roomConnection.rdf"));
After that, i would execute general queries and update queries on this static model.

How can i do this in CSparql2 / RSP4J ? Please correct me if wrong. Thanks.

Regards,
Rahul

@pbonte
Copy link
Collaborator

pbonte commented Feb 17, 2022

Hi Rahul,

Yes, you can definetly use static data with RSP4J!
CSPARQL2 and RSP4J use the RSP-QL model under the hood and accept RSP-QL queries.
You can define the static data you want to use directly in the query, for example:

PREFIX ars: <http://www.streamreasoning/artist#>
PREFIX afn: <http://jena.apache.org/ARQ/function#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX : <http://differenthost:12134/>

REGISTER RSTREAM <out> AS
SELECT  *
FROM NAMED WINDOW <win2> ON :stream2 [RANGE PT5S STEP PT0.5S]
FROM <file:///.../rsp4j/csparql2/src/test/resources/static.ttl>
WHERE  {
    ?a ars:hasName ?name.
    WINDOW ?w {
        ?a a ars:Artist ;
           ars:hasAge ?age .
    }

     BIND( UUID() as ?uuid )
}

In the query above the FROM clause loads the static data which then can be queried inside the default graph. You can see the example here for CSPARQL2.0.

YASPER is our own from scratch implementation on top of RSP4j, you can register the same query there as well.

Let me know if this solves your problem!

Kr,
Pieter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants