From a8d3b0932f582cc98f58bdd15bea228e4f9cd8c5 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sun, 2 Oct 2016 20:48:10 +0200 Subject: [PATCH] [TASK] More comments. --- src/main/java/lu/jpt/csparqltest/Main.java | 236 ----------------- .../misc/UnusedQueryCollection.java | 248 ++++++++++++++++++ 2 files changed, 248 insertions(+), 236 deletions(-) create mode 100644 src/main/java/lu/jpt/csparqltest/misc/UnusedQueryCollection.java diff --git a/src/main/java/lu/jpt/csparqltest/Main.java b/src/main/java/lu/jpt/csparqltest/Main.java index c4575e2..03f3373 100644 --- a/src/main/java/lu/jpt/csparqltest/Main.java +++ b/src/main/java/lu/jpt/csparqltest/Main.java @@ -5,7 +5,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import lu.jpt.csparqltest.gui.SimulationControlWindow; -import lu.jpt.csparqltest.rentacar.RentACarSimulation; /** * This is the main entry point of the whole project. A logger is being set up @@ -32,239 +31,4 @@ public class Main { // That's it, the program is now basically running on its own. } - private static String getSPO() { - return "REGISTER QUERY getSPO AS " - + "PREFIX f: " - + "PREFIX xsd: " - + "SELECT ?s ?p ?o " - + "FROM STREAM [RANGE 5s STEP 1s] " - + "WHERE { " - + " ?s ?p ?o . " - + "}"; - } - - /* - * WHERE { - OPTIONAL { - ?eventA rdf:type . - } - OPTIONAL { - ?eventB rdf:type . - } - FILTER((BOUND(?eventA) || BOUND(?eventB)) - && NOT (BOUND(?eventA) && BOUND(?eventB))) - } - * */ - private static String getAXORB() { - return "REGISTER QUERY matchAXORB AS " - + "PREFIX f: " - + "PREFIX rdf: " - + "PREFIX xsd: " - + "SELECT ?atype ?btype " - + "FROM STREAM [RANGE 5s STEP 1s] " - + "WHERE { " - + " OPTIONAL { " - + " ?a a . " - + " ?a a ?atype . " - + " } " - + " OPTIONAL { " - + " ?b a . " - + " ?b a ?btype . " - + " } " - + " FILTER( (BOUND(?a) || BOUND(?b)) && !(BOUND(?a) && BOUND(?b)) ) " - + "}"; - } - - private static String getNOTA() { - return "REGISTER QUERY matchNOTA AS " - + "PREFIX f: " - + "PREFIX rdf: " - + "PREFIX xsd: " - + "SELECT ?anyEventType " - + "FROM STREAM [RANGE 5s STEP 1s] " - + "WHERE { " - + " ?anyEvent a ?anyEventType . " - + " OPTIONAL { " - + " ?eventA a . " - + " } " - + " FILTER(!BOUND(?eventA)) " - + "}"; - } - - private static String getTestPatternQuery() { - return "REGISTER QUERY matchANotBC AS " - + "PREFIX f: " - + "PREFIX rdf: " - + "PREFIX xsd: " - + "SELECT ?a ?b ?c " - + "FROM STREAM [RANGE 5s STEP 1s] " - + "WHERE { " - + " ?a a . " - + " ?c a . " - + " BIND(f:timestamp(?a,rdf:type,) AS ?tsa) " - + " BIND(f:timestamp(?c,rdf:type,) AS ?tsc) " - + " FILTER(?tsa < ?tsc) " - + " FILTER NOT EXISTS { " - + " ?b a . " - + " BIND(f:timestamp(?b,rdf:type,) AS ?tsb) " - + " FILTER(?tsa < ?tsb && ?tsb < ?tsc)" - + " } " - + "}"; - } - - private static String getPatternANOTBCQuery() { - return "REGISTER QUERY matchANotBC AS " - + "PREFIX f: " - + "PREFIX rdf: " - + "PREFIX xsd: " - + "SELECT ?bbound ?abeforeb ?bbeforec ?tsa ?tsb ?tsc " - + "FROM STREAM [RANGE 5s STEP 1s] " - + "WHERE { " - + " ?a a . " - + " ?c a . " - + " BIND(f:timestamp(?a,rdf:type,) AS ?tsa) " - + " BIND(f:timestamp(?c,rdf:type,) AS ?tsc) " - + " FILTER(?tsa < ?tsc) " - + " OPTIONAL {" - + " ?b a . " - + " BIND(f:timestamp(?b,rdf:type,) AS ?tsb) " - + " FILTER(?tsb < ?tsa || ?tsc < ?tsb)" - + " } " - + " BIND(BOUND(?b) AS ?bbound) " - + " BIND(?tsa < ?tsb AS ?abeforeb) " - + " BIND(?tsb < ?tsc AS ?bbeforec) " - + "}"; - } - - - private static String getTestPatternABCQuery() { - return "REGISTER QUERY matchABC AS " - + "PREFIX f: " - + "PREFIX rdf: " - + "PREFIX xsd: " - + "SELECT ?tsa ?tsb ?tsc " - + "FROM STREAM [RANGE 5s STEP 1s] " - + "WHERE { " - + " ?a a . " - + " ?a a ?atype . " - + " OPTIONAL {" - + " ?b a . " - + " ?b a ?btype . " - + " } " - + " ?c a . " - + " ?c a ?ctype . " - + " BIND(f:timestamp(?a,rdf:type,?atype) AS ?tsa) " - + " BIND(f:timestamp(?b,rdf:type,?btype) AS ?tsb) " - + " BIND(f:timestamp(?c,rdf:type,?ctype) AS ?tsc) " - + " FILTER(f:timestamp(?a,rdf:type,?atype) < f:timestamp(?b,rdf:type,?btype)) " - + " FILTER(f:timestamp(?b,rdf:type,?btype) < f:timestamp(?c,rdf:type,?ctype)) " - + "}"; - } - - private static String getSPOFromRentACar() { - return "REGISTER QUERY BasicCarInfo AS " - + "PREFIX f: " - + "PREFIX xsd: " - + "SELECT ?s ?p ?o " - + "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 5s STEP 1s] " - + "FROM STREAM <"+RentACarSimulation.DRIVER_STREAM_IRI+"> [RANGE 15s STEP 1s] " - + "WHERE { " - + " ?s a <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"CarStatusEvent> . " - + " ?s ?p ?o . " - + "}"; - } - - private static String getAllCarAttributesQuery() { - return "REGISTER QUERY BasicCarInfo AS " - + "PREFIX f: " - + "PREFIX xsd: " - + "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] " - + "WHERE { " - + " ?e car:subject ?car . " - + " ?e car:locked ?locked . " - + " ?e car:motorOn ?on . " - + " ?e car:speed ?speed . " - + " ?e car:motorRPM ?rpm . " - + " ?e car:handbrakeEngaged ?handbrake . " - + " ?e car:tirePressure ?pressure . " - + "}"; - } - - private static String getBasicCarInfoQuery() { - return "REGISTER QUERY BasicCarInfo AS " - + "PREFIX f: " - + "PREFIX xsd: " - + "PREFIX cars: " - + "SELECT ?car ?speed ?temp (f:timestamp(?e,cars:carID,?car) AS ?ts) " - + "FROM STREAM [RANGE 5s STEP 1s] " - + "WHERE { " - + " ?e cars:carID ?car . " - + " ?e cars:currentSpeed ?speed . " - + " ?e cars:currentTemperature ?temp . " - + "}"; - } - - private static String getIncreasingTemperatureQuery() { - return "REGISTER QUERY IncreasingTemperature AS " - + "PREFIX f: " - + "PREFIX xsd: " - + "PREFIX cars: " - + "SELECT ?car (?temp2-?temp1 AS ?delta) " - + "FROM STREAM [RANGE 5s STEP 1s] " - + "WHERE { " - + " ?e1 cars:carID ?car . " - + " ?e1 cars:currentSpeed ?speed1 . " - + " ?e1 cars:currentTemperature ?temp1 . " - + " ?e2 cars:carID ?car . " - + " ?e2 cars:currentSpeed ?speed2 . " - + " ?e2 cars:currentTemperature ?temp2 . " - + " FILTER(f:timestamp(?e1,cars:carID,?car) < f:timestamp(?e2,cars:carID,?car)) " - + " FILTER(?temp1 < ?temp2) " - + "}"; - } - - private static String getAcceleratingCarsQuery() { - return "REGISTER QUERY AcceleratingCars AS " - + "PREFIX f: " - + "PREFIX xsd: " - + "PREFIX cars: " - + "SELECT ?car (?speed2-?speed1 AS ?delta) " - + "FROM STREAM [RANGE 5s STEP 1s] " - + "WHERE { " - + " ?e1 cars:carID ?car . " - + " ?e1 cars:currentSpeed ?speed1 . " - + " ?e1 cars:currentTemperature ?temp1 . " - + " ?e2 cars:carID ?car . " - + " ?e2 cars:currentSpeed ?speed2 . " - + " ?e2 cars:currentTemperature ?temp2 . " - + " FILTER(f:timestamp(?e1,cars:carID,?car) < f:timestamp(?e2,cars:carID,?car)) " - + " FILTER(?speed1 < ?speed2) " - + "}"; - } - - private static String getBreakingDownCarsQuery() { - return "REGISTER QUERY BreakingDownCars AS " - + "PREFIX f: " - + "PREFIX xsd: " - + "PREFIX cars: " - + "SELECT ?car (?speed2 - ?speed1 AS ?deltaspeed) (?temp2 - ?temp1 AS ?deltatemp) ?speed2 ?temp2 " - + "FROM STREAM [RANGE 5s STEP 1s] " - + "WHERE { " - + " ?e1 cars:carID ?car ; " - + " cars:currentSpeed ?speed1 ; " - + " cars:currentTemperature ?temp1 . " - + " ?e2 cars:carID ?car ; " - + " cars:currentSpeed ?speed2 ; " - + " cars:currentTemperature ?temp2 . " - + " FILTER(f:timestamp(?e1,cars:carID,?car) < f:timestamp(?e2,cars:carID,?car)) " - + " FILTER(f:timestamp(?e2,cars:carID,?car) - f:timestamp(?e1,cars:carID,?car) < 1800) " - + " FILTER(?speed1 > ?speed2) " - + " FILTER(?temp2 > ?temp1) " - + " FILTER(?temp2 > 90) " - + "}"; - } - } diff --git a/src/main/java/lu/jpt/csparqltest/misc/UnusedQueryCollection.java b/src/main/java/lu/jpt/csparqltest/misc/UnusedQueryCollection.java new file mode 100644 index 0000000..a85fd62 --- /dev/null +++ b/src/main/java/lu/jpt/csparqltest/misc/UnusedQueryCollection.java @@ -0,0 +1,248 @@ +package lu.jpt.csparqltest.misc; + +import lu.jpt.csparqltest.rentacar.RentACarSimulation; + +/** + * This class contains a bunch of unused C-SPARQL queries. + * It may be used for inspiration, but tread with care, as they + * probably won't work without adapting them a lot/little bit. + */ +public class UnusedQueryCollection { + + /** + * Fetch subject, predicate and object of everything (in given stream and window) + */ + private static String getSPO() { + return "REGISTER QUERY getSPO AS " + + "PREFIX f: " + + "PREFIX xsd: " + + "SELECT ?s ?p ?o " + + "FROM STREAM [RANGE 5s STEP 1s] " + + "WHERE { " + + " ?s ?p ?o . " + + "}"; + } + + /** + * Match A XOR B within window + */ + private static String getAXORB() { + return "REGISTER QUERY matchAXORB AS " + + "PREFIX f: " + + "PREFIX rdf: " + + "PREFIX xsd: " + + "SELECT ?atype ?btype " + + "FROM STREAM [RANGE 5s STEP 1s] " + + "WHERE { " + + " OPTIONAL { " + + " ?a a . " + + " ?a a ?atype . " + + " } " + + " OPTIONAL { " + + " ?b a . " + + " ?b a ?btype . " + + " } " + + " FILTER( (BOUND(?a) || BOUND(?b)) && !(BOUND(?a) && BOUND(?b)) ) " + + "}"; + } + + /** + * NOT A + */ + private static String getNOTA() { + return "REGISTER QUERY matchNOTA AS " + + "PREFIX f: " + + "PREFIX rdf: " + + "PREFIX xsd: " + + "SELECT ?anyEventType " + + "FROM STREAM [RANGE 5s STEP 1s] " + + "WHERE { " + + " ?anyEvent a ?anyEventType . " + + " OPTIONAL { " + + " ?eventA a . " + + " } " + + " FILTER(!BOUND(?eventA)) " + + "}"; + } + + /** + * A -> NOT B -> C + */ + private static String getTestPatternQuery() { + return "REGISTER QUERY matchANotBC AS " + + "PREFIX f: " + + "PREFIX rdf: " + + "PREFIX xsd: " + + "SELECT ?a ?b ?c " + + "FROM STREAM [RANGE 5s STEP 1s] " + + "WHERE { " + + " ?a a . " + + " ?c a . " + + " BIND(f:timestamp(?a,rdf:type,) AS ?tsa) " + + " BIND(f:timestamp(?c,rdf:type,) AS ?tsc) " + + " FILTER(?tsa < ?tsc) " + + " FILTER NOT EXISTS { " + + " ?b a . " + + " BIND(f:timestamp(?b,rdf:type,) AS ?tsb) " + + " FILTER(?tsa < ?tsb && ?tsb < ?tsc)" + + " } " + + "}"; + } + + /** + * A -> NOT B -> C + */ + private static String getPatternANOTBCQuery() { + return "REGISTER QUERY matchANotBC AS " + + "PREFIX f: " + + "PREFIX rdf: " + + "PREFIX xsd: " + + "SELECT ?bbound ?abeforeb ?bbeforec ?tsa ?tsb ?tsc " + + "FROM STREAM [RANGE 5s STEP 1s] " + + "WHERE { " + + " ?a a . " + + " ?c a . " + + " BIND(f:timestamp(?a,rdf:type,) AS ?tsa) " + + " BIND(f:timestamp(?c,rdf:type,) AS ?tsc) " + + " FILTER(?tsa < ?tsc) " + + " OPTIONAL {" + + " ?b a . " + + " BIND(f:timestamp(?b,rdf:type,) AS ?tsb) " + + " FILTER(?tsb < ?tsa || ?tsc < ?tsb)" + + " } " + + " BIND(BOUND(?b) AS ?bbound) " + + " BIND(?tsa < ?tsb AS ?abeforeb) " + + " BIND(?tsb < ?tsc AS ?bbeforec) " + + "}"; + } + + private static String getTestPatternABCQuery() { + return "REGISTER QUERY matchABC AS " + + "PREFIX f: " + + "PREFIX rdf: " + + "PREFIX xsd: " + + "SELECT ?tsa ?tsb ?tsc " + + "FROM STREAM [RANGE 5s STEP 1s] " + + "WHERE { " + + " ?a a . " + + " ?a a ?atype . " + + " OPTIONAL {" + + " ?b a . " + + " ?b a ?btype . " + + " } " + + " ?c a . " + + " ?c a ?ctype . " + + " BIND(f:timestamp(?a,rdf:type,?atype) AS ?tsa) " + + " BIND(f:timestamp(?b,rdf:type,?btype) AS ?tsb) " + + " BIND(f:timestamp(?c,rdf:type,?ctype) AS ?tsc) " + + " FILTER(f:timestamp(?a,rdf:type,?atype) < f:timestamp(?b,rdf:type,?btype)) " + + " FILTER(f:timestamp(?b,rdf:type,?btype) < f:timestamp(?c,rdf:type,?ctype)) " + + "}"; + } + + private static String getSPOFromRentACar() { + return "REGISTER QUERY BasicCarInfo AS " + + "PREFIX f: " + + "PREFIX xsd: " + + "SELECT ?s ?p ?o " + + "FROM STREAM <"+RentACarSimulation.CAR_STREAM_IRI+"> [RANGE 5s STEP 1s] " + + "FROM STREAM <"+RentACarSimulation.DRIVER_STREAM_IRI+"> [RANGE 15s STEP 1s] " + + "WHERE { " + + " ?s a <"+RentACarSimulation.BASE_ONTOLOGY_IRI+"CarStatusEvent> . " + + " ?s ?p ?o . " + + "}"; + } + + private static String getAllCarAttributesQuery() { + return "REGISTER QUERY BasicCarInfo AS " + + "PREFIX f: " + + "PREFIX xsd: " + + "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] " + + "WHERE { " + + " ?e car:subject ?car . " + + " ?e car:locked ?locked . " + + " ?e car:motorOn ?on . " + + " ?e car:speed ?speed . " + + " ?e car:motorRPM ?rpm . " + + " ?e car:handbrakeEngaged ?handbrake . " + + " ?e car:tirePressure ?pressure . " + + "}"; + } + + private static String getBasicCarInfoQuery() { + return "REGISTER QUERY BasicCarInfo AS " + + "PREFIX f: " + + "PREFIX xsd: " + + "PREFIX cars: " + + "SELECT ?car ?speed ?temp (f:timestamp(?e,cars:carID,?car) AS ?ts) " + + "FROM STREAM [RANGE 5s STEP 1s] " + + "WHERE { " + + " ?e cars:carID ?car . " + + " ?e cars:currentSpeed ?speed . " + + " ?e cars:currentTemperature ?temp . " + + "}"; + } + + private static String getIncreasingTemperatureQuery() { + return "REGISTER QUERY IncreasingTemperature AS " + + "PREFIX f: " + + "PREFIX xsd: " + + "PREFIX cars: " + + "SELECT ?car (?temp2-?temp1 AS ?delta) " + + "FROM STREAM [RANGE 5s STEP 1s] " + + "WHERE { " + + " ?e1 cars:carID ?car . " + + " ?e1 cars:currentSpeed ?speed1 . " + + " ?e1 cars:currentTemperature ?temp1 . " + + " ?e2 cars:carID ?car . " + + " ?e2 cars:currentSpeed ?speed2 . " + + " ?e2 cars:currentTemperature ?temp2 . " + + " FILTER(f:timestamp(?e1,cars:carID,?car) < f:timestamp(?e2,cars:carID,?car)) " + + " FILTER(?temp1 < ?temp2) " + + "}"; + } + + private static String getAcceleratingCarsQuery() { + return "REGISTER QUERY AcceleratingCars AS " + + "PREFIX f: " + + "PREFIX xsd: " + + "PREFIX cars: " + + "SELECT ?car (?speed2-?speed1 AS ?delta) " + + "FROM STREAM [RANGE 5s STEP 1s] " + + "WHERE { " + + " ?e1 cars:carID ?car . " + + " ?e1 cars:currentSpeed ?speed1 . " + + " ?e1 cars:currentTemperature ?temp1 . " + + " ?e2 cars:carID ?car . " + + " ?e2 cars:currentSpeed ?speed2 . " + + " ?e2 cars:currentTemperature ?temp2 . " + + " FILTER(f:timestamp(?e1,cars:carID,?car) < f:timestamp(?e2,cars:carID,?car)) " + + " FILTER(?speed1 < ?speed2) " + + "}"; + } + + private static String getBreakingDownCarsQuery() { + return "REGISTER QUERY BreakingDownCars AS " + + "PREFIX f: " + + "PREFIX xsd: " + + "PREFIX cars: " + + "SELECT ?car (?speed2 - ?speed1 AS ?deltaspeed) (?temp2 - ?temp1 AS ?deltatemp) ?speed2 ?temp2 " + + "FROM STREAM [RANGE 5s STEP 1s] " + + "WHERE { " + + " ?e1 cars:carID ?car ; " + + " cars:currentSpeed ?speed1 ; " + + " cars:currentTemperature ?temp1 . " + + " ?e2 cars:carID ?car ; " + + " cars:currentSpeed ?speed2 ; " + + " cars:currentTemperature ?temp2 . " + + " FILTER(f:timestamp(?e1,cars:carID,?car) < f:timestamp(?e2,cars:carID,?car)) " + + " FILTER(f:timestamp(?e2,cars:carID,?car) - f:timestamp(?e1,cars:carID,?car) < 1800) " + + " FILTER(?speed1 > ?speed2) " + + " FILTER(?temp2 > ?temp1) " + + " FILTER(?temp2 > 90) " + + "}"; + } +}