[TASK] Enhance queries, they are now working.
TODO: Somehow limit the tuples involved in the queries; right now i get way too many results.
This commit is contained in:
parent
8229911bda
commit
fb942ded5d
|
@ -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: <http://larkc.eu/csparql/sparql/jena/ext#> "
|
||||
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
|
||||
+ "PREFIX cars: <http://myexample.org/cars#> "
|
||||
+ "SELECT ?car ?speed ?temp) "
|
||||
+ "SELECT ?car ?speed ?temp (f:timestamp(?e,cars:carID,?car) AS ?ts) "
|
||||
+ "FROM STREAM <http://myexample.org/cars> [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: <http://larkc.eu/csparql/sparql/jena/ext#> "
|
||||
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
|
||||
+ "PREFIX cars: <http://myexample.org/cars#> "
|
||||
+ "SELECT ?car ?tempFrom ?tempTo "
|
||||
+ "SELECT ?car (?temp2-?temp1 AS ?delta) "
|
||||
+ "FROM STREAM <http://myexample.org/cars> [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: <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 "
|
||||
+ "SELECT ?car (?speed2-?speed1 AS ?delta) "
|
||||
+ "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) "
|
||||
+ " ?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) "
|
||||
+ "}";
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue