From 1a3598920fe5ceb06972d900525991fa003165e4 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sun, 9 Oct 2016 18:20:34 +0200 Subject: [PATCH] [TASK] Generic commit. --- .../jpt/csparqlproject/SimulationContext.java | 5 ++- .../rentacar/RentACarSimulation.java | 39 ++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/main/java/lu/jpt/csparqlproject/SimulationContext.java b/src/main/java/lu/jpt/csparqlproject/SimulationContext.java index 868da3a..ccd18c8 100644 --- a/src/main/java/lu/jpt/csparqlproject/SimulationContext.java +++ b/src/main/java/lu/jpt/csparqlproject/SimulationContext.java @@ -130,7 +130,7 @@ public class SimulationContext { SimulationContext.logger.debug("Engine from: " + this.engine.getClass().getProtectionDomain().getCodeSource()); // Load local domain knowledge into its target graph try { - engine.putStaticNamedModel("http://example.org/carSimKnowledgeGraph", CsparqlUtils.serializeRDFFile("data/carSimulationABox.rdf")); + engine.putStaticNamedModel(RentACarSimulation.DOMAIN_KNOWLEDGE_GRAPH_IRI, CsparqlUtils.serializeRDFFile("data/carSimulationABox.rdf")); } catch (Exception e) { SimulationContext.logger.error(e.toString()); SimulationContext.logger.error(e.getStackTrace().toString()); @@ -168,6 +168,7 @@ public class SimulationContext { queriesToRegister.add(simulation.getTireWearStream()); queriesToRegister.add(simulation.getCarTakenEventsQuery()); queriesToRegister.add(simulation.getCarReturnedEventsQuery()); + queriesToRegister.add(simulation.getWearEvents()); // Now register each query appropriately! for(QueryContainer queryContainer : queriesToRegister) { CsparqlQueryResultProxy resultProxy = null; @@ -179,7 +180,7 @@ public class SimulationContext { // Take care of streams and queries differently. if(queryContainer.isStream) { // If the query is a stream, we need additional components to feed it back into the engine. - String streamUri = "http://example.org/stream/"+queryContainer.name; + String streamUri = RentACarSimulation.BASE_STREAM_IRI+"/"+queryContainer.name; RDFStreamFormatter rdfStreamFormatter = new RDFStreamFormatter(streamUri); engine.registerStream(rdfStreamFormatter); resultProxy.addObserver(rdfStreamFormatter); diff --git a/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java b/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java index 36c80f2..dc77c75 100644 --- a/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java +++ b/src/main/java/lu/jpt/csparqlproject/rentacar/RentACarSimulation.java @@ -38,6 +38,7 @@ public class RentACarSimulation implements Runnable { public static final String BASE_OBJECT_IRI = BASE_URI + "/objects"; public static final String CAR_STREAM_IRI = BASE_STREAM_IRI + "/carStream"; public static final String DRIVER_STREAM_IRI = BASE_STREAM_IRI + "/driverStream"; + public static final String DOMAIN_KNOWLEDGE_GRAPH_IRI = BASE_URI + "/localDomainKnowledge"; private CarPool carPool; private List drivers; @@ -304,7 +305,7 @@ public class RentACarSimulation implements Runnable { + " ; car:maxMotorRPM ?maxMotorRPM . " + "} " + "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 3s STEP 1s] " - + "FROM " + + "FROM <"+RentACarSimulation.DOMAIN_KNOWLEDGE_GRAPH_IRI+"> " + "WHERE { " + " { " + " SELECT ?car (AVG(?motorRPM) AS ?avgMotorRPM) " @@ -337,7 +338,7 @@ public class RentACarSimulation implements Runnable { + " [] rdf:type car:CarBrakeWearEvent " + " ; car:relatedCar ?car . " + "} " - + "FROM STREAM [RANGE 2s STEP 1s] " + + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getStronglyBrakingCars> [RANGE 2s STEP 1s] " + "WHERE { " + " ?e rdf:type car:CarStrongBrakingEvent . " + " ?e car:relatedCar ?car . " @@ -391,7 +392,7 @@ public class RentACarSimulation implements Runnable { + " ; car:relatedCar ?car . " + "} " + "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 3s STEP 1s] " - + "FROM " + + "FROM <"+RentACarSimulation.DOMAIN_KNOWLEDGE_GRAPH_IRI+"> " + "WHERE { " + " ?e rdf:type car:CarStatusEvent . " + " ?e car:relatedCar ?car . " @@ -437,7 +438,7 @@ public class RentACarSimulation implements Runnable { String carUri = tuple.get(1); String updateQuery = "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> " + "INSERT DATA { " - + " GRAPH { " + + " GRAPH <"+RentACarSimulation.DOMAIN_KNOWLEDGE_GRAPH_IRI+"> { " + " <"+driverUri+"> car:drives <"+carUri+"> . " + " <"+carUri+"> car:isDrivenBy <"+driverUri+"> . " + " } " @@ -481,7 +482,7 @@ public class RentACarSimulation implements Runnable { String carUri = tuple.get(1); String updateQuery = "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> " + "DELETE DATA { " - + " GRAPH { " + + " GRAPH <"+RentACarSimulation.DOMAIN_KNOWLEDGE_GRAPH_IRI+"> { " + " <"+driverUri+"> car:drives <"+carUri+"> . " + " <"+carUri+"> car:isDrivenBy <"+driverUri+"> . " + " } " @@ -494,6 +495,32 @@ public class RentACarSimulation implements Runnable { return queryContainer; } + /** + * 5) Query to report all WearEvents using enabled inference. + */ + public QueryContainer getWearEvents() { + String query = "REGISTER QUERY getWearEvents AS " + + "PREFIX rdf: " + + "PREFIX f: " + + "PREFIX xsd: " + + "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> " + + "SELECT ?e ?car ?types " + + "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 3s STEP 1s] " + + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getEngineWear> [RANGE 3s STEP 1s] " + + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getBrakeWear> [RANGE 3s STEP 1s] " + + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getHandbrakeWear> [RANGE 3s STEP 1s] " + + "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getTireWear> [RANGE 3s STEP 1s] " + + "WHERE { " + + " ?e rdf:type car:CarWearEvent . " + + " ?e rdf:type ?types . " + + " ?e car:relatedCar ?car " + + "}"; + QueryContainer queryContainer = new QueryContainer("getWearEvents", query, true); + queryContainer.useObserverWindow(); + RentACarSimulation.setUpReasoningOnQueryContainer(queryContainer); + return queryContainer; + } + ////////////////////////////////////////////////////////////// public QueryContainer getEventsQuery() { @@ -532,7 +559,7 @@ public class RentACarSimulation implements Runnable { + "SELECT ?car ?driverName ?driverPhone " + "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 5s STEP 1s] " + "FROM STREAM <"+RentACarSimulation.DRIVER_STREAM_IRI+"> [RANGE 15s STEP 1s] " - + "FROM " + + "FROM <"+RentACarSimulation.DOMAIN_KNOWLEDGE_GRAPH_IRI+"> " + "WHERE { " + " ?e rdf:type car:CarStatusEvent . " + " ?e car:relatedCar ?car . "