[TASK] Generic commit.
This commit is contained in:
parent
00f063bff8
commit
1a3598920f
|
@ -130,7 +130,7 @@ public class SimulationContext {
|
||||||
SimulationContext.logger.debug("Engine from: " + this.engine.getClass().getProtectionDomain().getCodeSource());
|
SimulationContext.logger.debug("Engine from: " + this.engine.getClass().getProtectionDomain().getCodeSource());
|
||||||
// Load local domain knowledge into its target graph
|
// Load local domain knowledge into its target graph
|
||||||
try {
|
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) {
|
} catch (Exception e) {
|
||||||
SimulationContext.logger.error(e.toString());
|
SimulationContext.logger.error(e.toString());
|
||||||
SimulationContext.logger.error(e.getStackTrace().toString());
|
SimulationContext.logger.error(e.getStackTrace().toString());
|
||||||
|
@ -168,6 +168,7 @@ public class SimulationContext {
|
||||||
queriesToRegister.add(simulation.getTireWearStream());
|
queriesToRegister.add(simulation.getTireWearStream());
|
||||||
queriesToRegister.add(simulation.getCarTakenEventsQuery());
|
queriesToRegister.add(simulation.getCarTakenEventsQuery());
|
||||||
queriesToRegister.add(simulation.getCarReturnedEventsQuery());
|
queriesToRegister.add(simulation.getCarReturnedEventsQuery());
|
||||||
|
queriesToRegister.add(simulation.getWearEvents());
|
||||||
// Now register each query appropriately!
|
// Now register each query appropriately!
|
||||||
for(QueryContainer queryContainer : queriesToRegister) {
|
for(QueryContainer queryContainer : queriesToRegister) {
|
||||||
CsparqlQueryResultProxy resultProxy = null;
|
CsparqlQueryResultProxy resultProxy = null;
|
||||||
|
@ -179,7 +180,7 @@ public class SimulationContext {
|
||||||
// Take care of streams and queries differently.
|
// Take care of streams and queries differently.
|
||||||
if(queryContainer.isStream) {
|
if(queryContainer.isStream) {
|
||||||
// If the query is a stream, we need additional components to feed it back into the engine.
|
// 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);
|
RDFStreamFormatter rdfStreamFormatter = new RDFStreamFormatter(streamUri);
|
||||||
engine.registerStream(rdfStreamFormatter);
|
engine.registerStream(rdfStreamFormatter);
|
||||||
resultProxy.addObserver(rdfStreamFormatter);
|
resultProxy.addObserver(rdfStreamFormatter);
|
||||||
|
|
|
@ -38,6 +38,7 @@ public class RentACarSimulation implements Runnable {
|
||||||
public static final String BASE_OBJECT_IRI = BASE_URI + "/objects";
|
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 CAR_STREAM_IRI = BASE_STREAM_IRI + "/carStream";
|
||||||
public static final String DRIVER_STREAM_IRI = BASE_STREAM_IRI + "/driverStream";
|
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 CarPool carPool;
|
||||||
private List<Driver> drivers;
|
private List<Driver> drivers;
|
||||||
|
@ -304,7 +305,7 @@ public class RentACarSimulation implements Runnable {
|
||||||
+ " ; car:maxMotorRPM ?maxMotorRPM . "
|
+ " ; car:maxMotorRPM ?maxMotorRPM . "
|
||||||
+ "} "
|
+ "} "
|
||||||
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 3s STEP 1s] "
|
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 3s STEP 1s] "
|
||||||
+ "FROM <http://example.org/carSimKnowledgeGraph> "
|
+ "FROM <"+RentACarSimulation.DOMAIN_KNOWLEDGE_GRAPH_IRI+"> "
|
||||||
+ "WHERE { "
|
+ "WHERE { "
|
||||||
+ " { "
|
+ " { "
|
||||||
+ " SELECT ?car (AVG(?motorRPM) AS ?avgMotorRPM) "
|
+ " SELECT ?car (AVG(?motorRPM) AS ?avgMotorRPM) "
|
||||||
|
@ -337,7 +338,7 @@ public class RentACarSimulation implements Runnable {
|
||||||
+ " [] rdf:type car:CarBrakeWearEvent "
|
+ " [] rdf:type car:CarBrakeWearEvent "
|
||||||
+ " ; car:relatedCar ?car . "
|
+ " ; car:relatedCar ?car . "
|
||||||
+ "} "
|
+ "} "
|
||||||
+ "FROM STREAM <http://example.org/stream/getStronglyBrakingCars> [RANGE 2s STEP 1s] "
|
+ "FROM STREAM <"+RentACarSimulation.BASE_STREAM_IRI+"/getStronglyBrakingCars> [RANGE 2s STEP 1s] "
|
||||||
+ "WHERE { "
|
+ "WHERE { "
|
||||||
+ " ?e rdf:type car:CarStrongBrakingEvent . "
|
+ " ?e rdf:type car:CarStrongBrakingEvent . "
|
||||||
+ " ?e car:relatedCar ?car . "
|
+ " ?e car:relatedCar ?car . "
|
||||||
|
@ -391,7 +392,7 @@ public class RentACarSimulation implements Runnable {
|
||||||
+ " ; car:relatedCar ?car . "
|
+ " ; car:relatedCar ?car . "
|
||||||
+ "} "
|
+ "} "
|
||||||
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 3s STEP 1s] "
|
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 3s STEP 1s] "
|
||||||
+ "FROM <http://example.org/carSimKnowledgeGraph> "
|
+ "FROM <"+RentACarSimulation.DOMAIN_KNOWLEDGE_GRAPH_IRI+"> "
|
||||||
+ "WHERE { "
|
+ "WHERE { "
|
||||||
+ " ?e rdf:type car:CarStatusEvent . "
|
+ " ?e rdf:type car:CarStatusEvent . "
|
||||||
+ " ?e car:relatedCar ?car . "
|
+ " ?e car:relatedCar ?car . "
|
||||||
|
@ -437,7 +438,7 @@ public class RentACarSimulation implements Runnable {
|
||||||
String carUri = tuple.get(1);
|
String carUri = tuple.get(1);
|
||||||
String updateQuery = "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> "
|
String updateQuery = "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> "
|
||||||
+ "INSERT DATA { "
|
+ "INSERT DATA { "
|
||||||
+ " GRAPH <http://example.org/carSimKnowledgeGraph> { "
|
+ " GRAPH <"+RentACarSimulation.DOMAIN_KNOWLEDGE_GRAPH_IRI+"> { "
|
||||||
+ " <"+driverUri+"> car:drives <"+carUri+"> . "
|
+ " <"+driverUri+"> car:drives <"+carUri+"> . "
|
||||||
+ " <"+carUri+"> car:isDrivenBy <"+driverUri+"> . "
|
+ " <"+carUri+"> car:isDrivenBy <"+driverUri+"> . "
|
||||||
+ " } "
|
+ " } "
|
||||||
|
@ -481,7 +482,7 @@ public class RentACarSimulation implements Runnable {
|
||||||
String carUri = tuple.get(1);
|
String carUri = tuple.get(1);
|
||||||
String updateQuery = "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> "
|
String updateQuery = "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> "
|
||||||
+ "DELETE DATA { "
|
+ "DELETE DATA { "
|
||||||
+ " GRAPH <http://example.org/carSimKnowledgeGraph> { "
|
+ " GRAPH <"+RentACarSimulation.DOMAIN_KNOWLEDGE_GRAPH_IRI+"> { "
|
||||||
+ " <"+driverUri+"> car:drives <"+carUri+"> . "
|
+ " <"+driverUri+"> car:drives <"+carUri+"> . "
|
||||||
+ " <"+carUri+"> car:isDrivenBy <"+driverUri+"> . "
|
+ " <"+carUri+"> car:isDrivenBy <"+driverUri+"> . "
|
||||||
+ " } "
|
+ " } "
|
||||||
|
@ -494,6 +495,32 @@ public class RentACarSimulation implements Runnable {
|
||||||
return queryContainer;
|
return queryContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 5) Query to report all WearEvents using enabled inference.
|
||||||
|
*/
|
||||||
|
public QueryContainer getWearEvents() {
|
||||||
|
String query = "REGISTER QUERY getWearEvents AS "
|
||||||
|
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
|
||||||
|
+ "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 ?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() {
|
public QueryContainer getEventsQuery() {
|
||||||
|
@ -532,7 +559,7 @@ public class RentACarSimulation implements Runnable {
|
||||||
+ "SELECT ?car ?driverName ?driverPhone "
|
+ "SELECT ?car ?driverName ?driverPhone "
|
||||||
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 5s STEP 1s] "
|
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 5s STEP 1s] "
|
||||||
+ "FROM STREAM <"+RentACarSimulation.DRIVER_STREAM_IRI+"> [RANGE 15s STEP 1s] "
|
+ "FROM STREAM <"+RentACarSimulation.DRIVER_STREAM_IRI+"> [RANGE 15s STEP 1s] "
|
||||||
+ "FROM <http://example.org/carSimKnowledgeGraph> "
|
+ "FROM <"+RentACarSimulation.DOMAIN_KNOWLEDGE_GRAPH_IRI+"> "
|
||||||
+ "WHERE { "
|
+ "WHERE { "
|
||||||
+ " ?e rdf:type car:CarStatusEvent . "
|
+ " ?e rdf:type car:CarStatusEvent . "
|
||||||
+ " ?e car:relatedCar ?car . "
|
+ " ?e car:relatedCar ?car . "
|
||||||
|
|
Loading…
Reference in New Issue