From 9c8d49c6e858b8c60ff1e263702e0daa2b22c1e8 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Wed, 17 Aug 2016 14:55:57 +0200 Subject: [PATCH] [TASK] Add query that successfully uses background knowledge. --- data/carData.rdf | 6 ++--- src/main/java/lu/jpt/csparqltest/Main.java | 9 ++++---- .../java/lu/jpt/csparqltest/rentacar/Car.java | 2 +- .../lu/jpt/csparqltest/rentacar/Driver.java | 2 +- .../rentacar/RentACarSimulation.java | 22 +++++++++++++++++-- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/data/carData.rdf b/data/carData.rdf index 8515904..1b61a6e 100644 --- a/data/carData.rdf +++ b/data/carData.rdf @@ -10,7 +10,7 @@ - + 3500 3.5 @@ -23,11 +23,11 @@ - + Max +49 12345 B - \ No newline at end of file + diff --git a/src/main/java/lu/jpt/csparqltest/Main.java b/src/main/java/lu/jpt/csparqltest/Main.java index 96b4caf..243a906 100644 --- a/src/main/java/lu/jpt/csparqltest/Main.java +++ b/src/main/java/lu/jpt/csparqltest/Main.java @@ -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 . " + + " ?s a <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"CarStatusEvent> . " + " ?s ?p ?o . " + "}"; } @@ -129,7 +130,7 @@ public class Main { return "REGISTER QUERY BasicCarInfo AS " + "PREFIX f: " + "PREFIX xsd: " - + "PREFIX car: " + + "PREFIX 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] " diff --git a/src/main/java/lu/jpt/csparqltest/rentacar/Car.java b/src/main/java/lu/jpt/csparqltest/rentacar/Car.java index 0754c3a..3f163b3 100644 --- a/src/main/java/lu/jpt/csparqltest/rentacar/Car.java +++ b/src/main/java/lu/jpt/csparqltest/rentacar/Car.java @@ -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(); this.CAR_TYPE = RandomHelper.nextInt(2); this.initializeCarType(this.CAR_TYPE); diff --git a/src/main/java/lu/jpt/csparqltest/rentacar/Driver.java b/src/main/java/lu/jpt/csparqltest/rentacar/Driver.java index 453ff1d..598a597 100644 --- a/src/main/java/lu/jpt/csparqltest/rentacar/Driver.java +++ b/src/main/java/lu/jpt/csparqltest/rentacar/Driver.java @@ -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(); diff --git a/src/main/java/lu/jpt/csparqltest/rentacar/RentACarSimulation.java b/src/main/java/lu/jpt/csparqltest/rentacar/RentACarSimulation.java index e86f434..8d6830c 100644 --- a/src/main/java/lu/jpt/csparqltest/rentacar/RentACarSimulation.java +++ b/src/main/java/lu/jpt/csparqltest/rentacar/RentACarSimulation.java @@ -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: " + + "PREFIX f: " + + "PREFIX xsd: " + + "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 " + + "WHERE { " + + " ?e rdf:type car:CarStatusEvent . " + + " ?e car:relatedCar ?car . " + + " ?car car:isDrivenBy ?driver . " + + " ?driver car:hasName ?driverName . " + + " ?driver car:hasPhoneNumber ?driverPhone . " + + "}"; + } }