[TASK] Add basic speed change query.

This commit is contained in:
Jan Philipp Timme 2016-06-07 12:33:03 +02:00
parent 8e31770533
commit 40ce5f0ee6
1 changed files with 21 additions and 6 deletions

View File

@ -32,7 +32,7 @@ public class Main {
t.start();
// Now build a query to run - interchangeable
String query = Main.getTemperatureChangeQuery();
String query = Main.getAcceleratingCars();
// Create a result proxy by registering the query at the engine
CsparqlQueryResultProxy resultProxy = null;
@ -77,16 +77,31 @@ public class Main {
}
private static String getTemperatureChangeQuery() {
return "REGISTER QUERY TemperatureChange AS "
return "REGISTER QUERY TemperatureDelta AS "
+ "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> "
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
+ "PREFIX cars: <http://myexample.org/cars#> "
+ "SELECT ?car ?temp1 ?temp2 ( f:timestamp(?car,cars:currentTemperature,?temp1) AS ?ts1) "
+ "SELECT ?car ?tempFrom ?tempTo "
+ "FROM STREAM <http://myexample.org/cars> [RANGE 5s STEP 1s] "
+ "WHERE { "
+ " ?car cars:currentTemperature ?temp1 . "
+ " ?car cars:currentTemperature ?temp2 . "
+ " FILTER(?temp1 != ?temp2) "
+ " ?car cars:currentTemperature ?tempFrom . "
+ " ?car cars:currentTemperature ?tempTo . "
+ " FILTER(f:timestamp(?car,cars:currentTemperature,?tempFrom) < f:timestamp(?car,cars:currentTemperature,?tempTo)) "
+ "}";
}
private static String getAcceleratingCars() {
return "REGISTER QUERY SpeedDelta AS "
+ "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> "
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
+ "PREFIX cars: <http://myexample.org/cars#> "
+ "SELECT ?car ?speedFrom ?speedTo "
+ "FROM STREAM <http://myexample.org/cars> [RANGE 5s STEP 1s] "
+ "WHERE { "
+ " ?car cars:currentSpeed ?speedFrom . "
+ " ?car cars:currentSpeed ?speedTo . "
+ " FILTER(f:timestamp(?car,cars:currentSpeed,?speedFrom) < f:timestamp(?car,cars:currentSpeed,?speedTo)) "
+ " FILTER(?speedFrom < ?speedTo) "
+ "}";
}