[TASK] Add query that successfully uses background knowledge.
This commit is contained in:
parent
137425b81a
commit
9c8d49c6e8
|
@ -10,7 +10,7 @@
|
|||
<!-- Car data -->
|
||||
|
||||
<owl:NamedIndividual rdf:about="http://example.org/carSim/objects/Car#0">
|
||||
<rdf:type rdf:resource="http://simontology.org/Car"/>
|
||||
<rdf:type rdf:resource="http://example.org/carSim/carSimulationOntology#Car"/>
|
||||
<simontology:isDrivenBy rdf:resource="http://example.org/carSim/objects/Driver#0"/>
|
||||
<simontology:maximumMotorRPM rdf:datatype="xsd:integer">3500</simontology:maximumMotorRPM>
|
||||
<simontology:maximumTirePressure rdf:datatype="xsd:double">3.5</simontology:maximumTirePressure>
|
||||
|
@ -23,11 +23,11 @@
|
|||
<!-- Driver data -->
|
||||
|
||||
<owl:NamedIndividual rdf:about="http://example.org/carSim/objects/Driver#0">
|
||||
<rdf:type rdf:resource="http://simontology.org/Driver"/>
|
||||
<rdf:type rdf:resource="http://example.org/carSim/carSimulationOntology#Driver"/>
|
||||
<simontology:drives rdf:resource="http://example.org/carSim/objects/Car#0"/>
|
||||
<simontology:hasName rdf:datatype="xsd:string">Max</simontology:hasName>
|
||||
<simontology:hasPhoneNumber rdf:datatype="xsd:string">+49 12345</simontology:hasPhoneNumber>
|
||||
<simontology:hasDriverLicense rdf:datatype="xsd:string">B</simontology:hasDriverLicense>
|
||||
</owl:NamedIndividual>
|
||||
|
||||
</rdf:RDF>
|
||||
</rdf:RDF>
|
||||
|
|
|
@ -36,7 +36,7 @@ public class Main {
|
|||
|
||||
// Add static knowledge into local graph from file
|
||||
try {
|
||||
engine.putStaticNamedModel("http://jpt.lu/carSimKnowledge", CsparqlUtils.serializeRDFFile("data/carData.rdf"));
|
||||
engine.putStaticNamedModel("http://example.org/carSimKnowledgeGraph", CsparqlUtils.serializeRDFFile("data/carData.rdf"));
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString());
|
||||
logger.error(e.getStackTrace().toString());
|
||||
|
@ -64,7 +64,8 @@ public class Main {
|
|||
simulationThread.start();
|
||||
|
||||
// Now build a query to run - interchangeable
|
||||
String query = Main.getSPO();
|
||||
//String query = Main.getSPO();
|
||||
String query = RentACarSimulation.getEventUsingBackgroundKnowledge();
|
||||
|
||||
// Create a result proxy by registering the query at the engine
|
||||
CsparqlQueryResultProxy resultProxy = null;
|
||||
|
@ -120,7 +121,7 @@ public class Main {
|
|||
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 5s STEP 1s] "
|
||||
+ "FROM STREAM <"+RentACarSimulation.DRIVER_STREAM_IRI+"> [RANGE 15s STEP 1s] "
|
||||
+ "WHERE { "
|
||||
+ " ?s a <http://jpt.lu/carSimulationOntology#CarStatusEvent> . "
|
||||
+ " ?s a <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"CarStatusEvent> . "
|
||||
+ " ?s ?p ?o . "
|
||||
+ "}";
|
||||
}
|
||||
|
@ -129,7 +130,7 @@ public class Main {
|
|||
return "REGISTER QUERY BasicCarInfo AS "
|
||||
+ "PREFIX f: <http://larkc.eu/csparql/sparql/jena/ext#> "
|
||||
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
|
||||
+ "PREFIX car: <http://myexample.org/car#> "
|
||||
+ "PREFIX car: <http://example.org/car#> "
|
||||
+ "SELECT ?car ?locked ?on ?speed ?rpm ?handbrake ?tirePressure "
|
||||
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 5s STEP 1s] "
|
||||
+ "FROM STREAM <"+RentACarSimulation.DRIVER_STREAM_IRI+"> [RANGE 15s STEP 1s] "
|
||||
|
|
|
@ -48,7 +48,7 @@ public class Car {
|
|||
|
||||
public Car(int id) {
|
||||
this.id = id;
|
||||
this.IRI = RentACarSimulation.BASE_OBJECT_IRI + "/car";
|
||||
this.IRI = RentACarSimulation.BASE_OBJECT_IRI + "/Car";
|
||||
this.quads = new ArrayList<RdfQuadruple>();
|
||||
this.CAR_TYPE = RandomHelper.nextInt(2);
|
||||
this.initializeCarType(this.CAR_TYPE);
|
||||
|
|
|
@ -32,7 +32,7 @@ public class Driver {
|
|||
|
||||
public Driver(int id, CarPool carPool) {
|
||||
this.id = id;
|
||||
this.IRI = RentACarSimulation.BASE_OBJECT_IRI + "/driver";
|
||||
this.IRI = RentACarSimulation.BASE_OBJECT_IRI + "/Driver";
|
||||
this.carPool = carPool;
|
||||
this.car = null;
|
||||
this.quads = new ArrayList<RdfQuadruple>();
|
||||
|
|
|
@ -110,8 +110,8 @@ public class RentACarSimulation implements Runnable {
|
|||
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 5s STEP 1s] "
|
||||
+ "FROM STREAM <"+RentACarSimulation.DRIVER_STREAM_IRI+"> [RANGE 15s STEP 1s] "
|
||||
+ "WHERE { "
|
||||
+ " ?e rdf:type car:Event . "
|
||||
+ " ?e car:subject ?car . "
|
||||
+ " ?e rdf:type car:CarStatusEvent . "
|
||||
+ " ?e car:relatedCar ?car . "
|
||||
+ " ?e car:locked ?locked . "
|
||||
+ " ?e car:motorOn ?on . "
|
||||
+ " ?e car:speed ?speed . "
|
||||
|
@ -124,4 +124,22 @@ public class RentACarSimulation implements Runnable {
|
|||
+ "}";
|
||||
}
|
||||
|
||||
public static String getEventUsingBackgroundKnowledge() {
|
||||
return "REGISTER QUERY getEventsCombinedWithBackgroundKnowledge 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 ?car ?driverName ?driverPhone "
|
||||
+ "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 5s STEP 1s] "
|
||||
+ "FROM STREAM <"+RentACarSimulation.DRIVER_STREAM_IRI+"> [RANGE 15s STEP 1s] "
|
||||
+ "FROM <http://example.org/carSimKnowledgeGraph> "
|
||||
+ "WHERE { "
|
||||
+ " ?e rdf:type car:CarStatusEvent . "
|
||||
+ " ?e car:relatedCar ?car . "
|
||||
+ " ?car car:isDrivenBy ?driver . "
|
||||
+ " ?driver car:hasName ?driverName . "
|
||||
+ " ?driver car:hasPhoneNumber ?driverPhone . "
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue