[TASK] Generic commit

This commit is contained in:
Jan Philipp Timme 2016-10-11 13:32:50 +02:00
parent 0ab6364465
commit cad2ad2e8c
3 changed files with 53 additions and 9 deletions

View File

@ -168,8 +168,9 @@ public class SimulationContext {
queriesToRegister.add(simulation.getTireWearStream());
queriesToRegister.add(simulation.getCarTakenEventsQuery());
queriesToRegister.add(simulation.getCarReturnedEventsQuery());
queriesToRegister.add(simulation.getWearEvents());
queriesToRegister.add(simulation.getLockedMovingCars());
queriesToRegister.add(simulation.getWearEventsStream());
queriesToRegister.add(simulation.getLockedMovingCarsQuery());
queriesToRegister.add(simulation.getMaintenanceEventsStream());
// Now register each query appropriately!
for(QueryContainer queryContainer : queriesToRegister) {
CsparqlQueryResultProxy resultProxy = null;

View File

@ -363,6 +363,7 @@ public class FancyTextObserverWindow extends JFrame implements Observer {
}
} catch(Exception e) {
// This is to prevent the whole stack from crashing.
e.printStackTrace();
FancyTextObserverWindow.logger.error(e.toString());
FancyTextObserverWindow.logger.error(e.getMessage());
}
@ -370,6 +371,8 @@ public class FancyTextObserverWindow extends JFrame implements Observer {
/**
* Method to actually pretty-print the results of a Csparql query
* TODO: Fix a bug that leads to printing in black when more tokens are encountered
* than expected.
* @param CsparqlQueryResultProxy result
* @param RDFTable table
*/
@ -389,7 +392,8 @@ public class FancyTextObserverWindow extends JFrame implements Observer {
if(elementNamesIterator.hasNext()) {
elementName += ", ";
}
this.showToken(elementName, palette[nameIndex]);
Color c = (nameIndex < palette.length) ? palette[nameIndex] : Color.BLACK;
this.showToken(elementName, c);
nameIndex++;
}
this.showText("]", Color.BLACK);
@ -409,7 +413,8 @@ public class FancyTextObserverWindow extends JFrame implements Observer {
} else {
token += "\n";
}
this.showToken(token, palette[tokenIndex]);
Color c = (tokenIndex < palette.length) ? palette[tokenIndex] : Color.BLACK;
this.showToken(token, c);
tokenIndex++;
}
}

View File

@ -183,7 +183,7 @@ public class RentACarSimulation implements Runnable {
+ " [] rdf:type car:CarStandingEvent "
+ " ; car:relatedCar ?car . "
+ "} "
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 2s STEP 1s] "
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 1s TUMBLING] "
+ "WHERE { "
+ " ?e rdf:type car:CarStatusEvent . "
+ " ?e car:relatedCar ?car . "
@ -207,7 +207,7 @@ public class RentACarSimulation implements Runnable {
+ " [] rdf:type car:CarMovingEvent "
+ " ; car:relatedCar ?car . "
+ "} "
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 2s STEP 1s] "
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 1s TUMBLING] "
+ "WHERE { "
+ " ?e rdf:type car:CarStatusEvent . "
+ " ?e car:relatedCar ?car . "
@ -506,14 +506,19 @@ public class RentACarSimulation implements Runnable {
* 5) Query to report all WearEvents using enabled inference.
* Also returns the responsible driver if available
*/
public QueryContainer getWearEvents() {
public QueryContainer getWearEventsStream() {
String query = "REGISTER STREAM getWearEvents AS "
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
+ "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> "
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
+ "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> "
+ "SELECT ?e ?type ?car ?driverName ?driverPhone "
+ "CONSTRUCT { "
+ " [] rdf:type car:CarWearEvent "
+ " ; car:relatedCar ?car "
+ " ; car:responsibleDriverName ?driverName "
+ " ; car:responsibleDriverPhone ?driverPhone . "
+ "} "
+ "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getEngineWear> [RANGE 1s TUMBLING] "
+ "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getBrakeWear> [RANGE 1s TUMBLING] "
+ "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getHandbrakeWear> [RANGE 1s TUMBLING] "
@ -538,7 +543,7 @@ public class RentACarSimulation implements Runnable {
/**
* 6) Query to report locked cars that move due to forgotten handbrake
*/
public QueryContainer getLockedMovingCars() {
public QueryContainer getLockedMovingCarsQuery() {
String query = "REGISTER QUERY getLockedMovingCars AS "
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
+ "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> "
@ -565,6 +570,39 @@ public class RentACarSimulation implements Runnable {
return queryContainer;
}
public QueryContainer getMaintenanceEventsStream() {
String query = "REGISTER STREAM getMaintenanceEvents AS "
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
+ "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> "
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
+ "PREFIX car: <http://example.org/carSim/carSimulationOntology#> "
+ "CONSTRUCT { "
+ " [] rdf:type car:CarMaintenanceNeededEvent "
+ " ; car:relatedCar ?car . "
+ "} "
+ "FROM STREAM <http://example.org/carSim/stream/carStream> [RANGE 5s TUMBLING] "
+ "FROM STREAM <http://example.org/carSim/stream/getEngineWear> [RANGE 4h STEP 5m] "
+ "WHERE { "
+ " { "
+ " SELECT ?car "
+ " WHERE { "
+ " ?wearEvent rdf:type car:CarWearEvent . "
+ " ?wearEvent car:relatedCar ?car . "
+ " } "
+ " GROUP BY ?car "
+ " HAVING (COUNT(?wearEvent) > 10) "
+ " } "
+ " UNION { "
+ " ?checkEngineEvent rdf:type car:CarCheckEngineEvent . "
+ " ?checkEngineEvent car:relatedCar ?car . "
+ " } "
+ "}";
QueryContainer queryContainer = new QueryContainer("getMaintenanceEvents", query, true);
queryContainer.useObserverWindow();
return queryContainer;
}
///////////////////////////////////// UNUSED QUERIES BELOW THIS LINE /////////////////////////////////////
///////////////////////////////////// UNUSED QUERIES BELOW THIS LINE /////////////////////////////////////
///////////////////////////////////// UNUSED QUERIES BELOW THIS LINE /////////////////////////////////////