From cad2ad2e8c6d7dd44607ee8d1cd28be367c2f621 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Tue, 11 Oct 2016 13:32:50 +0200 Subject: [PATCH] [TASK] Generic commit --- .../jpt/csparqlproject/SimulationContext.java | 5 +- .../gui/FancyTextObserverWindow.java | 9 +++- .../rentacar/RentACarSimulation.java | 48 +++++++++++++++++-- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/main/java/lu/jpt/csparqlproject/SimulationContext.java b/src/main/java/lu/jpt/csparqlproject/SimulationContext.java index 9d6d0fa..cf9a655 100644 --- a/src/main/java/lu/jpt/csparqlproject/SimulationContext.java +++ b/src/main/java/lu/jpt/csparqlproject/SimulationContext.java @@ -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; diff --git a/src/main/java/lu/jpt/csparqlproject/gui/FancyTextObserverWindow.java b/src/main/java/lu/jpt/csparqlproject/gui/FancyTextObserverWindow.java index 5183fc6..c09e2e1 100644 --- a/src/main/java/lu/jpt/csparqlproject/gui/FancyTextObserverWindow.java +++ b/src/main/java/lu/jpt/csparqlproject/gui/FancyTextObserverWindow.java @@ -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++; } } diff --git a/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java b/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java index 865bc7d..a782681 100644 --- a/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java +++ b/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java @@ -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: " + "PREFIX rdfs: " + "PREFIX f: " + "PREFIX xsd: " + "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: " + "PREFIX f: " @@ -565,6 +570,39 @@ public class RentACarSimulation implements Runnable { return queryContainer; } + public QueryContainer getMaintenanceEventsStream() { + String query = "REGISTER STREAM getMaintenanceEvents AS " + + "PREFIX rdf: " + + "PREFIX rdfs: " + + "PREFIX f: " + + "PREFIX xsd: " + + "PREFIX car: " + + "CONSTRUCT { " + + " [] rdf:type car:CarMaintenanceNeededEvent " + + " ; car:relatedCar ?car . " + + "} " + + "FROM STREAM [RANGE 5s TUMBLING] " + + "FROM STREAM [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 /////////////////////////////////////