diff --git a/.gitignore b/.gitignore index e420ee4..f1472b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ target/* +export.ttl \ No newline at end of file diff --git a/assignments/lab-2.html b/assignments/lab-2.html index 40979d1..639592f 100644 --- a/assignments/lab-2.html +++ b/assignments/lab-2.html @@ -35,7 +35,7 @@

After having written each functions, run the tests. You can read the code for the tests if you are unsure of what you should do.

Implementing IControlFunctions

-

The controler uses functions from the model, and uses them to enrich the dataset. Once you complete the interface implementation, go to the main function in the Controler class. You must edit some code snippets depending on your environment.

+

The controller uses functions from the model, and uses them to enrich the dataset. Once you complete the interface implementation, go to the main function in the Controler class. You must edit some code snippets depending on your environment.

Remarks

This is a purely pedagogical codebase, and its performances are not great: many optimisations could be done. Moreover, the generated knowledge graph is managed in memory only: when the software stops, the knowledge base disappears. Export it if you want to persist it. The bottleneck are queries to the knowledge base, so think about caching. diff --git a/export.ttl b/export.ttl deleted file mode 100644 index cf7f328..0000000 --- a/export.ttl +++ /dev/null @@ -1,476 +0,0 @@ - - a , ; - - "TemperatureSensor_1@en" ; - - . - - - a ; - - "Continent@en" , "Continent@fr" ; - - . - - - a . - - - a ; - - ; - - "mesure@fr" , "measures@en" ; - - . - - - a , ; - - "TemperatureSensor_3@en" ; - - . - - - a ; - - "Lieu@fr" , "Place@en" . - - - a ; - - "a pour maximum@en" . - - - a ; - - "Beau temps@fr" , "Nice Weather@en" ; - - . - - - a ; - - "3043c3cfe6c9e26bb1a96a9ea27976f2" ; - - ; - - "a pour capitale@fr" , "has capital@en" ; - - ; - - . - - - a , ; - - "Paris@fr" . - - - a , ; - - "Pluviométrie@en" . - - - a ; - - ; - - "débute à@fr" , "starts at@en" ; - - . - - - a , ; - - "Positive temperature range relatively common on earth. Expressed in °C" ; - - "Positive earthly temperatures@en" , "Températures positives" ; - - ; - - "0.0^^http://www.w3.org/2001/XMLSchema#float" ; - - "50.0^^http://www.w3.org/2001/XMLSchema#float" . - - - a , ; - - "Output T2@en" ; - - . - - - a ; - - . - - - a , ; - - "France@fr" ; - - , . - - - a ; - - "Paramètre observable@en" . - - - a ; - - "a pour minimum@en" . - - - a ; - - ; - - "a pour localisation@fr" , "has location@en" ; - - . - - - a . - - - a ; - - "Phénomène@fr" , "Phenomenon@en" . - - - a ; - - "Observation@fr" , "Observation météo@fr" , "WeatherObservation@en" . - - - a , ; - - "TemperatureSensor_2@en" ; - - . - - - a ; - - "Ensoleillement@fr" , "Sunshine@en" ; - - . - - - a ; - - ; - - "caractérisé par@fr" , "has characteristics@en" ; - - . - - - a , ; - - "P1@en" ; - - ; - - ; - - "3.0^^http://www.w3.org/2001/XMLSchema#float" ; - - . - - - a . - - - a , ; - - "Platform1@en" ; - - ; - - . - - - a , ; - - "Température" . - - - a , ; - - "France@en" . - - - a , ; - - "Vitesse du vent@en" . - - - a ; - - "est la capitale de@fr" , "is capital@en" ; - - . - - - a . - - - a ; - - ; - - "a pour symptome@fr" , "has symptom@en" ; - - . - - - a ; - - "Brouillard@fr" , "Fog@en" ; - - . - - - a , ; - - "Range B@en" ; - - . - - - a ; - - "Pluie@en" ; - - ; - - "591fc5014267cd4faa70a08765865245" . - - - a ; - - ; - - "finit à@fr" , "end at@en" ; - - . - - - a . - - - a ; - - "Mauvais temps@fr" , "Bad Weather@en" ; - - . - - - a , ; - - "Pression athmosphérique@en" . - - - a , ; - - "Temperatures commonly measured on earth, both positive and negative, expressed in °C." ; - - "Common temperatures@en" ; - - ; - - "-30.0^^http://www.w3.org/2001/XMLSchema#float" ; - - "50.0^^http://www.w3.org/2001/XMLSchema#float" . - - - a , ; - - "Output T1@en" ; - - . - - - a , ; - - "Range A@en" ; - - . - - - a , ; - - "A1@en" ; - - . - - - a . - - - a ; - - ; - - "a pour date@fr" , "has date@en" ; - - . - - - a . - - - a , ; - - "La ville Lumière@fr" . - - - a , ; - - ; - - "est inclus dans@fr" , "is included in@en" ; - - . - - - a ; - - , . - - - a . - - - a , ; - - "Output T3@en" ; - - . - - - a ; - - ; - - "est compatible avec@fr" , "compatible with@en" ; - - ; - - "5b8182:17e291f0415:-7ffb" . - - - a , ; - - "I1@en" ; - - "2015-10-11T13:20:00Z^^http://www.w3.org/2001/XMLSchema#dateTimeStamp" . - - - a ; - - "Paramètre mesurables@fr" , "Parameters@en" ; - - . - - - a , ; - - "Hygrométrie@fr" , "Humidity" . - - - a ; - - "Ville@fr" , "City@en" ; - - . - - - a ; - - ; - - "a pour valeur@fr" , "has value@en" ; - - . - - - a , ; - - "Température@fr" , "Temperature@en" . - - - a ; - - "4f32868b7102faf5c78538d8d9010e96" . - - - a ; - - "Instant@en" , "Instant@fr" . - - - a , ; - - "Hygrométrie@en" . - - - a , ; - - "Sonde T1@en" ; - - . - - - a ; - - ; - - "a pour timestamp@fr" , "has timestamp@en" ; - - . - - - a ; - - "se situe dans@en" ; - - "5b8182:17e291f0415:-7fff" , "5b8182:17e291f0415:-7ffd" . - - - a , ; - - "Sonde_P1@en" ; - - . - - - a ; - - ; - - "71f7ea4964da0ace95707802f7c19a48" . - - - a ; - - "Pays@fr" , "Country@en" ; - - ; - - . - - - a , , ; - - "Toulouse@en" ; - - . - - - a , ; - - "Vitesse du vent@en" . diff --git a/src/main/java/semantic/controler/Controler.java b/src/main/java/semantic/controler/Controler.java deleted file mode 100644 index fa134db..0000000 --- a/src/main/java/semantic/controler/Controler.java +++ /dev/null @@ -1,73 +0,0 @@ -package semantic.controler; - -import java.io.IOException; -import java.util.List; - -import semantic.model.DoItYourselfModel; -import semantic.model.IModelFunctions; -import semantic.model.ObservationEntity; -import semantic.model.SemanticModel; -import semantic.view.JSONEndpoint; - -public class Controler -{ - private SemanticModel model; - private IModelFunctions customModel; - private IControlFunctions customControl; - - public Controler() - { - // TODO : Change the path to the one to your own ontology - this.model = new SemanticModel("tp-iss.ttl"); - this.customModel = new DoItYourselfModel(this.model); - this.customControl = new DoItYourselfControl(this.model, this.customModel); - this.initializeContext(); - } - - private void initializeContext() - { - this.customModel.createPlace("Aarhus"); - } - - public void exportModel(String path) - { - this.model.exportModel(path); - } - - public SemanticModel getModel() - { - return this.model; - } - - public IModelFunctions getCustomModel() - { - return this.customModel; - } - - public IControlFunctions getCustomControl() - { - return this.customControl; - } - - public static void main(String[] args) - { - Controler c = new Controler(); - try - { - // TODO : Change the path to the one of the file you downloaded - List obsList = JSONEndpoint.parseObservations("tempm.txt"); - String tempURI = c.model.getEntityURI("Temperature").get(0); - c.getCustomControl().instantiateObservations(obsList, tempURI); - // TODO : Same thing, for humidity - obsList = JSONEndpoint.parseObservations("tempm.txt"); - String humidityURI = c.model.getEntityURI("Température").get(0); - c.getCustomControl().instantiateObservations(obsList, humidityURI); - // TODO : Change the path so that it points where you want the export to be done - c.exportModel("export.ttl"); - } - catch (IOException e) - { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/semantic/controler/Controller.java b/src/main/java/semantic/controler/Controller.java new file mode 100644 index 0000000..af3ce4a --- /dev/null +++ b/src/main/java/semantic/controler/Controller.java @@ -0,0 +1,58 @@ +package semantic.controler; + +import semantic.model.DoItYourselfModel; +import semantic.model.IModelFunctions; +import semantic.model.ObservationEntity; +import semantic.model.SemanticModel; +import semantic.view.JSONEndpoint; + +import java.io.IOException; +import java.util.List; + +public class Controller { + private final SemanticModel model; + private final IModelFunctions customModel; + private final IControlFunctions customControl; + + public Controller() { + this.model = new SemanticModel("tp-iss.ttl"); + this.customModel = new DoItYourselfModel(this.model); + this.customControl = new DoItYourselfControl(this.model, this.customModel); + this.initializeContext(); + } + + public static void main(String[] args) { + Controller controller = new Controller(); + try { + List obsList = JSONEndpoint.parseObservations("tempm.txt"); + String tempURI = controller.model.getEntityURI("Temperature").get(0); + controller.getCustomControl().instantiateObservations(obsList, tempURI); + obsList = JSONEndpoint.parseObservations("hum.txt"); + String humidityURI = controller.model.getEntityURI("Humidity").get(0); + controller.getCustomControl().instantiateObservations(obsList, humidityURI); + controller.exportModel("export.ttl"); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void initializeContext() { + this.customModel.createPlace("Aarhus"); + } + + public void exportModel(String path) { + this.model.exportModel(path); + } + + public SemanticModel getModel() { + return this.model; + } + + public IModelFunctions getCustomModel() { + return this.customModel; + } + + public IControlFunctions getCustomControl() { + return this.customControl; + } +} diff --git a/src/main/java/semantic/model/IConvenienceInterface.java b/src/main/java/semantic/model/IConvenienceInterface.java index d6fb73c..ec94433 100644 --- a/src/main/java/semantic/model/IConvenienceInterface.java +++ b/src/main/java/semantic/model/IConvenienceInterface.java @@ -10,7 +10,7 @@ public interface IConvenienceInterface /** * There are multiple temperature sensors on the platform. This method indicates * which one performed a measure based on its timestamp. - * @param obs, useful to get the timestamp + * @param timestamp, useful to get the timestamp * @param paramURI, the URI of the observed parameter * @return the URI of the sensor having performed the measure. */ @@ -30,7 +30,7 @@ public interface IConvenienceInterface public boolean hasSensorDoneIt(String obsURI, String sensorURI); /** - * @param label + * @param classURI * @return all the URIs of instances of the class of concepts associated to this label. */ public List getInstancesURI(String classURI); @@ -51,7 +51,7 @@ public interface IConvenienceInterface /** * Creates an instance of the provided type, with the provided label. * @param label - * @param the URI of the type + * @param type the URI of the type * @return the URI of the created individual */ public String createInstance(String label, String type); diff --git a/src/test/java/semantic/TestModelFunctions.java b/src/test/java/semantic/TestModelFunctions.java index 2120460..4ba52c1 100644 --- a/src/test/java/semantic/TestModelFunctions.java +++ b/src/test/java/semantic/TestModelFunctions.java @@ -3,7 +3,7 @@ package semantic; import org.junit.Assert; import org.junit.Test; -import semantic.controler.Controler; +import semantic.controler.Controller; import semantic.model.TimestampEntity; public class TestModelFunctions @@ -11,7 +11,7 @@ public class TestModelFunctions @Test public void testPlaceCreation() { - Controler c = new Controler(); + Controller c = new Controller(); String jurassicParkURI = c.getCustomModel().createPlace("Jurassic park"); String placeClassURI = c.getModel().getEntityURI("Lieu").get(0); Assert.assertTrue("L'entité créée n'est pas de classe Lieu", c.getModel().isOfType(jurassicParkURI, placeClassURI)); @@ -21,7 +21,7 @@ public class TestModelFunctions @Test public void testInstantCreation() { - Controler c = new Controler(); + Controller c = new Controller(); TimestampEntity t = new TimestampEntity("2014-02-13T06:20:00"); String instantURI = c.getCustomModel().createInstant(t); String instantClassURI = c.getModel().getEntityURI("Instant").get(0); @@ -34,7 +34,7 @@ public class TestModelFunctions @Test public void testInstantRetrieval() { - Controler c = new Controler(); + Controller c = new Controller(); TimestampEntity t = new TimestampEntity("2014-02-13T06:20:00"); TimestampEntity t2 = new TimestampEntity("2015-02-13T06:20:00"); String instantURI = c.getCustomModel().createInstant(t); @@ -45,7 +45,7 @@ public class TestModelFunctions @Test public void testTimestampRetrieval() { - Controler c = new Controler(); + Controller c = new Controller(); TimestampEntity t = new TimestampEntity("2014-02-13T06:20:00"); String instantURI = c.getCustomModel().createInstant(t); Assert.assertTrue("Le timestamp ne correspond pas", c.getCustomModel().getInstantTimestamp(instantURI).equals("2014-02-13T06:20:00")); @@ -54,7 +54,7 @@ public class TestModelFunctions @Test public void testObservationCreation() { - Controler c = new Controler(); + Controller c = new Controller(); TimestampEntity t = new TimestampEntity("2014-02-13T06:20:00"); String instantURI = c.getCustomModel().createInstant(t); String paramURI = c.getModel().getEntityURI("Temperature").get(0);