diff --git a/src/main/java/lu/jpt/csparqltest/Main.java b/src/main/java/lu/jpt/csparqltest/Main.java index 4d46b6e..da9b256 100644 --- a/src/main/java/lu/jpt/csparqltest/Main.java +++ b/src/main/java/lu/jpt/csparqltest/Main.java @@ -40,7 +40,7 @@ public class Main { t.start(); // Now build a query to run - interchangeable - String query = Main.getBasicCarInfoQuery(); + String query = Main.getAcceleratingCarsQuery(); // Create a result proxy by registering the query at the engine CsparqlQueryResultProxy resultProxy = null; @@ -76,7 +76,7 @@ public class Main { + "PREFIX f: " + "PREFIX xsd: " + "PREFIX cars: " - + "SELECT ?car ?speed ?temp) " + + "SELECT ?car ?speed ?temp (f:timestamp(?e,cars:carID,?car) AS ?ts) " + "FROM STREAM [RANGE 5s STEP 1s] " + "WHERE { " + " ?e cars:carID ?car . " @@ -85,32 +85,41 @@ public class Main { + "}"; } - private static String getTemperatureChangeQuery() { - return "REGISTER QUERY TemperatureDelta AS " + private static String getIncreasingTemperatureQuery() { + return "REGISTER QUERY getIncreasingTemperature AS " + "PREFIX f: " + "PREFIX xsd: " + "PREFIX cars: " - + "SELECT ?car ?tempFrom ?tempTo " + + "SELECT ?car (?temp2-?temp1 AS ?delta) " + "FROM STREAM [RANGE 5s STEP 1s] " + "WHERE { " - + " ?car cars:currentTemperature ?tempFrom . " - + " ?car cars:currentTemperature ?tempTo . " - + " FILTER(f:timestamp(?car,cars:currentTemperature,?tempFrom) < f:timestamp(?car,cars:currentTemperature,?tempTo)) " + + " ?e1 cars:carID ?car . " + + " ?e1 cars:currentSpeed ?speed1 . " + + " ?e1 cars:currentTemperature ?temp1 . " + + " ?e2 cars:carID ?car . " + + " ?e2 cars:currentSpeed ?speed2 . " + + " ?e2 cars:currentTemperature ?temp2 . " + + " FILTER(f:timestamp(?e1,cars:carID,?car) > f:timestamp(?e2,cars:carID,?car)) " + + " FILTER(?temp1 < ?temp2) " + "}"; } - private static String getAcceleratingCars() { - return "REGISTER QUERY SpeedDelta AS " + private static String getAcceleratingCarsQuery() { + return "REGISTER QUERY getAcceleratingCars AS " + "PREFIX f: " + "PREFIX xsd: " + "PREFIX cars: " - + "SELECT ?car ?speedFrom ?speedTo " + + "SELECT ?car (?speed2-?speed1 AS ?delta) " + "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) " + + " ?e1 cars:carID ?car . " + + " ?e1 cars:currentSpeed ?speed1 . " + + " ?e1 cars:currentTemperature ?temp1 . " + + " ?e2 cars:carID ?car . " + + " ?e2 cars:currentSpeed ?speed2 . " + + " ?e2 cars:currentTemperature ?temp2 . " + + " FILTER(f:timestamp(?e1,cars:carID,?car) > f:timestamp(?e2,cars:carID,?car)) " + + " FILTER(?speed1 < ?speed2) " + "}"; } diff --git a/src/main/java/lu/jpt/csparqltest/carexample/CarStreamGenerator.java b/src/main/java/lu/jpt/csparqltest/carexample/CarStreamGenerator.java index 50ae9a7..892e923 100644 --- a/src/main/java/lu/jpt/csparqltest/carexample/CarStreamGenerator.java +++ b/src/main/java/lu/jpt/csparqltest/carexample/CarStreamGenerator.java @@ -48,7 +48,7 @@ public class CarStreamGenerator extends RdfStream implements Runnable { ) ); this.put(new RdfQuadruple( - getIRI() + "/" + currentCar.getID(), + eventID, getIRI() + "#currentTemperature", ""+currentCar.getMotorTemperature() + "^^http://www.w3.org/2001/XMLSchema#integer", currentTime