[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:
Jan Philipp Timme 2016-07-08 11:37:36 +02:00
parent 8229911bda
commit fb942ded5d
2 changed files with 25 additions and 16 deletions

View File

@ -40,7 +40,7 @@ public class Main {
t.start(); t.start();
// Now build a query to run - interchangeable // 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 // Create a result proxy by registering the query at the engine
CsparqlQueryResultProxy resultProxy = null; CsparqlQueryResultProxy resultProxy = null;
@ -76,7 +76,7 @@ public class Main {
+ "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> " + "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> "
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
+ "PREFIX cars: <http://myexample.org/cars#> " + "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] " + "FROM STREAM <http://myexample.org/cars> [RANGE 5s STEP 1s] "
+ "WHERE { " + "WHERE { "
+ " ?e cars:carID ?car . " + " ?e cars:carID ?car . "
@ -85,32 +85,41 @@ public class Main {
+ "}"; + "}";
} }
private static String getTemperatureChangeQuery() { private static String getIncreasingTemperatureQuery() {
return "REGISTER QUERY TemperatureDelta AS " return "REGISTER QUERY getIncreasingTemperature AS "
+ "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> " + "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> "
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
+ "PREFIX cars: <http://myexample.org/cars#> " + "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] " + "FROM STREAM <http://myexample.org/cars> [RANGE 5s STEP 1s] "
+ "WHERE { " + "WHERE { "
+ " ?car cars:currentTemperature ?tempFrom . " + " ?e1 cars:carID ?car . "
+ " ?car cars:currentTemperature ?tempTo . " + " ?e1 cars:currentSpeed ?speed1 . "
+ " FILTER(f:timestamp(?car,cars:currentTemperature,?tempFrom) < f:timestamp(?car,cars:currentTemperature,?tempTo)) " + " ?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() { private static String getAcceleratingCarsQuery() {
return "REGISTER QUERY SpeedDelta AS " return "REGISTER QUERY getAcceleratingCars AS "
+ "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> " + "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> "
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
+ "PREFIX cars: <http://myexample.org/cars#> " + "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] " + "FROM STREAM <http://myexample.org/cars> [RANGE 5s STEP 1s] "
+ "WHERE { " + "WHERE { "
+ " ?car cars:currentSpeed ?speedFrom . " + " ?e1 cars:carID ?car . "
+ " ?car cars:currentSpeed ?speedTo . " + " ?e1 cars:currentSpeed ?speed1 . "
+ " FILTER(f:timestamp(?car,cars:currentSpeed,?speedFrom) < f:timestamp(?car,cars:currentSpeed,?speedTo)) " + " ?e1 cars:currentTemperature ?temp1 . "
+ " FILTER(?speedFrom < ?speedTo) " + " ?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) "
+ "}"; + "}";
} }

View File

@ -48,7 +48,7 @@ public class CarStreamGenerator extends RdfStream implements Runnable {
) )
); );
this.put(new RdfQuadruple( this.put(new RdfQuadruple(
getIRI() + "/" + currentCar.getID(), eventID,
getIRI() + "#currentTemperature", getIRI() + "#currentTemperature",
""+currentCar.getMotorTemperature() + "^^http://www.w3.org/2001/XMLSchema#integer", ""+currentCar.getMotorTemperature() + "^^http://www.w3.org/2001/XMLSchema#integer",
currentTime currentTime