From 40ce5f0ee6bc92b8c0741f63c3d26eac7892e24a Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 7 Jun 2016 12:33:03 +0200 Subject: [PATCH] [TASK] Add basic speed change query. --- src/main/java/lu/jpt/csparqltest/Main.java | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/lu/jpt/csparqltest/Main.java b/src/main/java/lu/jpt/csparqltest/Main.java index 9506850..c7fdfe8 100644 --- a/src/main/java/lu/jpt/csparqltest/Main.java +++ b/src/main/java/lu/jpt/csparqltest/Main.java @@ -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: " + "PREFIX xsd: " + "PREFIX cars: " - + "SELECT ?car ?temp1 ?temp2 ( f:timestamp(?car,cars:currentTemperature,?temp1) AS ?ts1) " + + "SELECT ?car ?tempFrom ?tempTo " + "FROM STREAM [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: " + + "PREFIX xsd: " + + "PREFIX cars: " + + "SELECT ?car ?speedFrom ?speedTo " + + "FROM STREAM [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) " + "}"; }