[TASK] Make code and ontology match more.

This commit is contained in:
JPT committed 2016-08-11 20:42:24 +02:00
1 parent a4444da92e
commit f49110eaef
4 files changed
+276 -87

No files matched your search

@@ -45,7 +45,7 @@ public class Car {
public Car(int id) {
this.id = id;
this.IRI = RentACarSimulation.CAR_IRI;
this.IRI = RentACarSimulation.BASE_OBJECT_IRI + "/car";
this.quads = new ArrayList<RdfQuadruple>();
this.CAR_TYPE = RandomHelper.nextInt(2);
this.initializeCarType(this.CAR_TYPE);
@@ -197,23 +197,26 @@ public class Car {
private void fireAirbagEvent() {
long time = System.currentTimeMillis();
String baseIri = RentACarSimulation.BASE_IRI;
String baseIri = RentACarSimulation.BASE_OBJECT_IRI;
String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI;
String eventIri = baseIri + "/event#" + time;
this.quads.add(new RdfQuadruple(eventIri, "http://myexample.org/car#subject", this.getIri(), time));
this.quads.add(new RdfQuadruple(eventIri, "http://myexample.org/car#airbagTriggered", ""+true+"^^http://www.w3.org/2001/XMLSchema#boolean", time));
this.quads.add(new RdfQuadruple(eventIri, "a", baseOnt+"/CarAirbagEvent", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#relatedCar", this.getIri(), time));
}
private void generateContinousReportQuads() {
long time = System.currentTimeMillis();
String baseIri = RentACarSimulation.BASE_IRI;
String baseIri = RentACarSimulation.BASE_OBJECT_IRI;
String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI;
String eventIri = baseIri + "/event#" + time;
this.quads.add(new RdfQuadruple(eventIri, "http://myexample.org/car#subject", this.getIri(), time));
this.quads.add(new RdfQuadruple(eventIri, "http://myexample.org/car#motorOn", ""+this.motorOn+"^^http://www.w3.org/2001/XMLSchema#boolean", time));
this.quads.add(new RdfQuadruple(eventIri, "http://myexample.org/car#motorRPM", ""+this.motorRpm+"^^http://www.w3.org/2001/XMLSchema#integer", time));
this.quads.add(new RdfQuadruple(eventIri, "http://myexample.org/car#speed", ""+this.speed+"^^http://www.w3.org/2001/XMLSchema#integer", time));
this.quads.add(new RdfQuadruple(eventIri, "http://myexample.org/car#handbrakeEngaged", ""+this.handbrakeEngaged+"^^http://www.w3.org/2001/XMLSchema#boolean", time));
this.quads.add(new RdfQuadruple(eventIri, "http://myexample.org/car#tirePressure", ""+this.tirePressure+"^^http://www.w3.org/2001/XMLSchema#double", time));
this.quads.add(new RdfQuadruple(eventIri, "http://myexample.org/car#locked", ""+this.isLocked+"^^http://www.w3.org/2001/XMLSchema#boolean", time));
this.quads.add(new RdfQuadruple(eventIri, "a", baseOnt+"/CarStatusEvent", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#relatedCar", this.getIri(), time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#motorOn", ""+this.motorOn+"^^http://www.w3.org/2001/XMLSchema#boolean", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#motorRPM", ""+this.motorRpm+"^^http://www.w3.org/2001/XMLSchema#integer", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#speed", ""+this.speed+"^^http://www.w3.org/2001/XMLSchema#integer", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#handbrakeEngaged", ""+this.handbrakeEngaged+"^^http://www.w3.org/2001/XMLSchema#boolean", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#tirePressure", ""+this.tirePressure+"^^http://www.w3.org/2001/XMLSchema#double", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#locked", ""+this.isLocked+"^^http://www.w3.org/2001/XMLSchema#boolean", time));
}
public CarState getState() {
@@ -237,7 +240,7 @@ public class Car {
}
public String getIri() {
return RentACarSimulation.CAR_IRI + "#" + this.id;
return this.IRI + "#" + this.id;
}
public List<RdfQuadruple> getQuadruples() {
@@ -27,9 +27,12 @@ public class Driver {
private List<RdfQuadruple> quads;
private final String IRI;
public Driver(int id, CarPool carPool) {
this.id = id;
this.IRI = RentACarSimulation.BASE_OBJECT_IRI + "/driver";
this.carPool = carPool;
this.car = null;
this.quads = new ArrayList<RdfQuadruple>();
@@ -42,7 +45,7 @@ public class Driver {
}
public String getIri() {
return RentACarSimulation.DRIVER_IRI + "#" + this.id;
return this.IRI + "#" + this.id;
}
/**
@@ -145,19 +148,23 @@ public class Driver {
this.car = this.carPool.takeRandomCar();
this.carUseCycles = useCycles;
long time = System.currentTimeMillis();
String baseIri = RentACarSimulation.BASE_IRI;
String baseIri = RentACarSimulation.BASE_OBJECT_IRI;
String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI;
String eventIri = baseIri + "/event#" + time;
this.quads.add(new RdfQuadruple(eventIri, baseIri+"#user", this.getIri(), time));
this.quads.add(new RdfQuadruple(eventIri, baseIri+"#took", this.car.getIri(), System.currentTimeMillis()));
this.quads.add(new RdfQuadruple(eventIri, baseIri+"#usagePeriod", ""+useCycles+"^^http://www.w3.org/2001/XMLSchema#integer", System.currentTimeMillis()));
this.quads.add(new RdfQuadruple(eventIri, "a", baseOnt+"/CarTakenEvent", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#relatedUser", this.getIri(), time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#relatedCar", this.car.getIri(), System.currentTimeMillis()));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#usagePeriod", ""+useCycles+"^^http://www.w3.org/2001/XMLSchema#integer", System.currentTimeMillis()));
}
private void returnCar() {
long time = System.currentTimeMillis();
String baseIri = RentACarSimulation.BASE_IRI;
String baseIri = RentACarSimulation.BASE_OBJECT_IRI;
String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI;
String eventIri = baseIri + "/event#" + time;
this.quads.add(new RdfQuadruple(eventIri, baseIri+"#user", this.getIri(), time));
this.quads.add(new RdfQuadruple(eventIri, baseIri+"#returned", this.car.getIri(), time));
this.quads.add(new RdfQuadruple(eventIri, "a", baseOnt+"/CarReturnedEvent", time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#relatedUser", this.getIri(), time));
this.quads.add(new RdfQuadruple(eventIri, baseOnt+"#relatedCar", this.car.getIri(), time));
this.carPool.returnCar(this.car);
this.car = null;
}
@@ -8,9 +8,11 @@ import eu.larkc.csparql.cep.api.RdfStream;
public class RentACarSimulation implements Runnable {
public static final String BASE_IRI = "http://myexample.org";
public static final String CAR_IRI = BASE_IRI + "/car";
public static final String DRIVER_IRI = BASE_IRI + "/driver";
public static final String BASE_ONTOLOGY_IRI = "http://simontology.org";
public static final String BASE_STREAM_IRI = "http://simstream.org";
public static final String BASE_OBJECT_IRI = "http://simobject.org";
public static final String CAR_STREAM_IRI = BASE_STREAM_IRI + "/carStream";
public static final String DRIVER_STREAM_IRI = BASE_STREAM_IRI + "/driverStream";
private CarPool carPool;
private List<Driver> drivers;
@@ -33,8 +35,8 @@ public class RentACarSimulation implements Runnable {
this.drivers.add(driver);
}
// Create streams
this.carStream = new RdfStream(CAR_IRI);
this.driverStream = new RdfStream(DRIVER_IRI);
this.carStream = new RdfStream(CAR_STREAM_IRI);
this.driverStream = new RdfStream(DRIVER_STREAM_IRI);
// Green light for simulation
this.runSimulation = true;
}