Commit ea0898d9 authored by liorpeak's avatar liorpeak
Browse files

query update

parent 890360f1
/*******************************************************************************
* Copyright 2014 Davide Barbieri, Emanuele Della Valle, Marco Balduini
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Acknowledgements:
*
* This work was partially supported by the European project LarKC (FP7-215535)
* and by the European project MODAClouds (FP7-318484)
******************************************************************************/
package eu.larkc.csparql.sr4ld2014;
import java.awt.geom.GeneralPath;
import java.util.Formattable;
import java.util.Formatter;
import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -30,45 +14,73 @@ import eu.larkc.csparql.core.engine.ConsoleFormatter;
import eu.larkc.csparql.core.engine.CsparqlEngineImpl;
import eu.larkc.csparql.core.engine.CsparqlQueryResultProxy;
import eu.larkc.csparql.sr4ld2014.streamer.SensorsStreamer;
import eu.larkc.csparql.sr4ld2014.streamer.SensorsStreamer1;
public class Example {
private static Logger logger = LoggerFactory.getLogger(Example.class);
public static void main(String[] args) {
try{
//Configure log4j logger for the csparql engine
PropertyConfigurator.configure("log4j_configuration/csparql_readyToGoPack_log4j.properties");
//Create csparql engine instance
CsparqlEngineImpl engine = new CsparqlEngineImpl();
//Initialize the engine instance
//The initialization creates the static engine (SPARQL) and the stream engine (CEP)
engine.initialize();
//engine.initialize();
engine.initialize(true);
/*String queryBody = "REGISTER STREAM IsInFs AS "
+ "PREFIX : <http://www.streamreasoning.org/ontologies/sr4ld2014-onto#> "
+ "CONSTRUCT { ?person :isIn ?room } "
+ "FROM STREAM <http://streamreasoning.org/streams/fs> [RANGE 10s STEP 1s] "
+ "WHERE { "
+ "?person :posts [ :who ?person ; :where ?room ] "
+ "}";
*/
String queryBody = "REGISTER QUERY reasoning AS "
+ "PREFIX :<http://onto#> "
+ "SELECT ?s ?p ?r "
+ "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> "
//+ "CONSTRUCT { ?s :isIn ?p } "
+ "SELECT ?o1 ?o2 "
//+ "FROM STREAM <http://streamreasoning.org/streams/fb> [RANGE 1s STEP 1s] "
+ "FROM STREAM <http://streamreasoning.org/streams/sensors> [RANGE 1s STEP 1s] "
+ "FROM STREAM <http://streamreasoning.org/streams/sensors> [RANGE 5s STEP 5s] "
+ "FROM STREAM <http://streamreasoning.org/streams/sensors1> [RANGE 5s STEP 5s] "
//+ "WHERE { "
//+ "GRAPH stream1 {"
//+ "?s2 :madeObservation ?o2"
//+ "} UNION "
//+ "GRAPH stream2 {"
//+ "?s2 :madeObservation ?o2"
//+ "}"
+ "WHERE { "
//+ "?s :madeObservation ?o ."
//+ "?o :hasSimpleResult ?p . "
+ "?s :madeObservation [ :hasSimpleResult ?p ; :hasTime ?r ] "
+ "FILTER (?p = 2). "
+ "{ ?s :madeObservation ?o1 ."
+ " ?o1 :hasSimpleResult ?p ."
+ " ?o1 :hasTime ?r . "
+ " ?s1 :madeObservation ?o2 ."
+ " ?o2 :hasSimpleResult ?p1 ."
+ " ?o2 :hasTime ?r1 ."
+ "FILTER (f:timestamp(?s,:madeObservation,?o1) < f:timestamp(?s1,:madeObservation,?o2) && ?p > 1 && ?p1 > 2 && ?s != ?s1 ). }"
//+ "UNION " f:timestamp(?s,:madeObservation,?o1) < f:timestamp(?s1,:madeObservation,?o2)
//+ "{ ?s1 :madeObservation [ :hasSimpleResult ?p1 ; :hasTime ?r1 ] "
//+ "FILTER (?p1 > 3 && ?s != ?s1). }"
+ "} ";
//FacebookStreamer fb = new FacebookStreamer("http://streamreasoning.org/streams/fb", "http://www.streamreasoning.org/ontologies/sr4ld2014-onto#", 1000L);
SensorsStreamer1 s1 = new SensorsStreamer1("http://streamreasoning.org/streams/sensors1", "http://onto#", 1000L);
SensorsStreamer s = new SensorsStreamer("http://streamreasoning.org/streams/sensors", "http://onto#", 10000L);
//Register new streams in the engine
engine.registerStream(s);
engine.registerStream(s1);
//Thread fbThread = new Thread(fb);
Thread sThread = new Thread(s);
Thread s1Thread = new Thread(s1);
//Register new query in the engine
CsparqlQueryResultProxy c = engine.registerQuery(queryBody, false);
......@@ -78,9 +90,10 @@ public class Example {
//Start streaming data
sThread.start();
s1Thread.start();
engine.updateReasoner(c.getSparqlQueryId(), CsparqlUtils.fileToString("examples_files/rdfs.rules"), ReasonerChainingType.FORWARD, CsparqlUtils.serializeRDFFile("examples_files/tbox.rdf"));
}catch (Exception e) {
logger.error(e.getMessage(), e);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment