From ce802396ffd412fa4fbf0d00f7c1db23cc0621dd Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Mon, 15 Aug 2016 14:22:25 +0200 Subject: [PATCH] [TASK] Add a TBox for testing purposes, figured it out. --- data/carSimulationTBox.rdf | 67 +++++++++++++++++++ src/main/java/lu/jpt/csparqltest/Main.java | 22 ++++-- .../java/lu/jpt/csparqltest/rentacar/Car.java | 4 +- .../lu/jpt/csparqltest/rentacar/Driver.java | 4 +- .../rentacar/RentACarSimulation.java | 4 +- 5 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 data/carSimulationTBox.rdf diff --git a/data/carSimulationTBox.rdf b/data/carSimulationTBox.rdf new file mode 100644 index 0000000..380cd56 --- /dev/null +++ b/data/carSimulationTBox.rdf @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 26be9c0..96b4caf 100644 --- a/src/main/java/lu/jpt/csparqltest/Main.java +++ b/src/main/java/lu/jpt/csparqltest/Main.java @@ -7,6 +7,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import eu.larkc.csparql.common.utils.CsparqlUtils; +import eu.larkc.csparql.common.utils.ReasonerChainingType; import eu.larkc.csparql.core.engine.ConsoleFormatter; import eu.larkc.csparql.core.engine.CsparqlEngine; import eu.larkc.csparql.core.engine.CsparqlEngineImpl; @@ -47,10 +48,7 @@ public class Main { + "{ GRAPH { :room :isConnectedTo :room2 } }"; engine.execUpdateQueryOverDatasource(updateQuery); */ - - // Enable reasoning with rdfs rules from file and a tbox rdf file. - //engine.updateReasoner(c.getSparqlQueryId(), CsparqlUtils.fileToString("examples_files/rdfs.rules"), ReasonerChainingType.FORWARD, CsparqlUtils.serializeRDFFile("examples_files/tbox.rdf")); - + // Debugging: Needed to verify which engine is being used //logger.debug("CWD: " + System.getProperty("user.dir")); @@ -76,6 +74,21 @@ public class Main { logger.error(e.toString()); logger.error(e.getStackTrace().toString()); } + + // Enable reasoning with rdfs rules from file and a tbox rdf file. + /*try { + engine.updateReasoner( + resultProxy.getSparqlQueryId(), + CsparqlUtils.fileToString("data/rdfs.rules"), + ReasonerChainingType.FORWARD, + CsparqlUtils.serializeRDFFile("data/carSimulationTBox.rdf") + ); + } catch(Exception e) { + e.printStackTrace(); + logger.error(e.toString()); + logger.error(e.getStackTrace().toString()); + }*/ + // Add ConsoleFormatter as observer so it gets notified of every query result resultProxy.addObserver(new ConsoleFormatter()); @@ -107,6 +120,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 ?p ?o . " + "}"; } diff --git a/src/main/java/lu/jpt/csparqltest/rentacar/Car.java b/src/main/java/lu/jpt/csparqltest/rentacar/Car.java index 9746ccf..6760d72 100644 --- a/src/main/java/lu/jpt/csparqltest/rentacar/Car.java +++ b/src/main/java/lu/jpt/csparqltest/rentacar/Car.java @@ -200,7 +200,7 @@ public class Car { String baseIri = RentACarSimulation.BASE_OBJECT_IRI; String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI; String eventIri = baseIri + "/event#" + time; - this.quads.add(new RdfQuadruple(eventIri, "rdf:type", baseOnt+"CarAirbagEvent", time)); + this.quads.add(new RdfQuadruple(eventIri, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", baseOnt+"CarAirbagEvent", time)); this.quads.add(new RdfQuadruple(eventIri, baseOnt+"relatedCar", this.getIri(), time)); } @@ -209,7 +209,7 @@ public class Car { String baseIri = RentACarSimulation.BASE_OBJECT_IRI; String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI; String eventIri = baseIri + "/event#" + time; - this.quads.add(new RdfQuadruple(eventIri, "rdf:type", baseOnt+"CarStatusEvent", time)); + this.quads.add(new RdfQuadruple(eventIri, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", 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)); diff --git a/src/main/java/lu/jpt/csparqltest/rentacar/Driver.java b/src/main/java/lu/jpt/csparqltest/rentacar/Driver.java index 0d1ea3f..453ff1d 100644 --- a/src/main/java/lu/jpt/csparqltest/rentacar/Driver.java +++ b/src/main/java/lu/jpt/csparqltest/rentacar/Driver.java @@ -151,7 +151,7 @@ public class Driver { String baseIri = RentACarSimulation.BASE_OBJECT_IRI; String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI; String eventIri = baseIri + "/event#" + time; - this.quads.add(new RdfQuadruple(eventIri, "rdf:type", baseOnt+"CarTakenEvent", time)); + this.quads.add(new RdfQuadruple(eventIri, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", 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())); @@ -162,7 +162,7 @@ public class Driver { String baseIri = RentACarSimulation.BASE_OBJECT_IRI; String baseOnt = RentACarSimulation.BASE_ONTOLOGY_IRI; String eventIri = baseIri + "/event#" + time; - this.quads.add(new RdfQuadruple(eventIri, "rdf:type", baseOnt+"CarReturnedEvent", time)); + this.quads.add(new RdfQuadruple(eventIri, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", 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); diff --git a/src/main/java/lu/jpt/csparqltest/rentacar/RentACarSimulation.java b/src/main/java/lu/jpt/csparqltest/rentacar/RentACarSimulation.java index aeccb88..c3696bb 100644 --- a/src/main/java/lu/jpt/csparqltest/rentacar/RentACarSimulation.java +++ b/src/main/java/lu/jpt/csparqltest/rentacar/RentACarSimulation.java @@ -99,8 +99,9 @@ public class RentACarSimulation implements Runnable { this.runSimulation = false; } - public static String getEvents() { + public static String getEventsQuery() { return "REGISTER QUERY getEvents AS " + + "PREFIX rdf: " + "PREFIX f: " + "PREFIX xsd: " + "PREFIX car: <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"> " @@ -108,6 +109,7 @@ 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 car:locked ?locked . " + " ?e car:motorOn ?on . "