feat: implement model functions
This commit is contained in:
parent
9776ba727a
commit
69ae083224
4 changed files with 63 additions and 49 deletions
|
@ -1,41 +1,62 @@
|
||||||
package semantic.model;
|
package semantic.model;
|
||||||
|
|
||||||
public class DoItYourselfModel implements IModelFunctions
|
import java.util.List;
|
||||||
{
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class DoItYourselfModel implements IModelFunctions {
|
||||||
IConvenienceInterface model;
|
IConvenienceInterface model;
|
||||||
|
|
||||||
public DoItYourselfModel(IConvenienceInterface m) {
|
public DoItYourselfModel(IConvenienceInterface m) {
|
||||||
this.model = m;
|
this.model = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createPlace(String name) {
|
public String createPlace(String name) {
|
||||||
// TODO Auto-generated method stub
|
String placeURI = model.getEntityURI("Place").get(0);
|
||||||
return null;
|
return model.createInstance(name, placeURI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createInstant(TimestampEntity instant) {
|
public String createInstant(TimestampEntity instant) {
|
||||||
// TODO Auto-generated method stub
|
String instantURI = model.getEntityURI("Instant").get(0);
|
||||||
return null;
|
String propertyURI = model.getEntityURI("a pour timestamp").get(0);
|
||||||
|
String instantInstanceURI = model.createInstance(instant.getTimeStamp(), instantURI);
|
||||||
|
model.addDataPropertyToIndividual(instantInstanceURI, propertyURI, instant.getTimeStamp());
|
||||||
|
return instantInstanceURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getInstantTimestamp(String instantURI) {
|
||||||
|
String propertyURI = model.getEntityURI("a pour timestamp").get(0);
|
||||||
|
List<List<String>> listProperties = model.listProperties(instantURI);
|
||||||
|
Optional<List<String>> timestampProperty = listProperties.stream().filter(property ->
|
||||||
|
property.get(0).equals(propertyURI)
|
||||||
|
).findFirst();
|
||||||
|
return timestampProperty.map(strings -> strings.get(1)).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInstantURI(TimestampEntity instant) {
|
public String getInstantURI(TimestampEntity instant) {
|
||||||
// TODO Auto-generated method stub
|
String instantTypeURI = model.getEntityURI("Instant").get(0);
|
||||||
return null;
|
String propertyURI = model.getEntityURI("a pour timestamp").get(0);
|
||||||
}
|
List<String> instancesURIList = model.getInstancesURI(instantTypeURI);
|
||||||
|
Optional<String> instantURI = instancesURIList.stream().filter(instanceURI ->
|
||||||
@Override
|
model.hasDataPropertyValue(
|
||||||
public String getInstantTimestamp(String instantURI)
|
instanceURI, propertyURI, instant.getTimeStamp())
|
||||||
{
|
).findFirst();
|
||||||
// TODO Auto-generated method stub
|
return instantURI.orElse(null);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createObs(String value, String paramURI, String instantURI) {
|
public String createObs(String value, String paramURI, String instantURI) {
|
||||||
// TODO Auto-generated method stub
|
String obsClassURI = model.getEntityURI("Observation").get(0);
|
||||||
return null;
|
String obsInstanceURI = model.createInstance(instantURI + "_" + paramURI + "_" + value, obsClassURI);
|
||||||
|
String dataValueURI = model.getEntityURI("a pour valeur").get(0);
|
||||||
|
String datePropertyURI = model.getEntityURI("a pour date").get(0);
|
||||||
|
String sensorURI = model.whichSensorDidIt(getInstantTimestamp(instantURI), paramURI);
|
||||||
|
model.addDataPropertyToIndividual(obsInstanceURI, dataValueURI, value);
|
||||||
|
model.addObjectPropertyToIndividual(obsInstanceURI, datePropertyURI, instantURI);
|
||||||
|
model.addObservationToSensor(obsInstanceURI, sensorURI);
|
||||||
|
return obsInstanceURI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,12 +49,12 @@ public interface IConvenienceInterface
|
||||||
*/
|
*/
|
||||||
public boolean isOfType(String instanceURI, String typeURI);
|
public boolean isOfType(String instanceURI, String typeURI);
|
||||||
/**
|
/**
|
||||||
* Creates an instance of the provided type, with the provided label.
|
* Creates an instance of the provided typeURI, with the provided label.
|
||||||
* @param label
|
* @param label the label of the instance
|
||||||
* @param type the URI of the type
|
* @param typeURI the URI of the type
|
||||||
* @return the URI of the created individual
|
* @return the URI of the created individual
|
||||||
*/
|
*/
|
||||||
public String createInstance(String label, String type);
|
public String createInstance(String label, String typeURI);
|
||||||
/**
|
/**
|
||||||
* Adds a triple in the knowledge base <subject, property, object>
|
* Adds a triple in the knowledge base <subject, property, object>
|
||||||
* @param subjectURI
|
* @param subjectURI
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class SemanticModel implements IConvenienceInterface
|
||||||
this.model = this.dataset.getDefaultModel();
|
this.model = this.dataset.getDefaultModel();
|
||||||
this.loadFromFile("./tp2_sensors.rdf", "", "RDF/XML", true);
|
this.loadFromFile("./tp2_sensors.rdf", "", "RDF/XML", true);
|
||||||
this.loadFromFile(ontologyPath, "", "TURTLE", true);
|
this.loadFromFile(ontologyPath, "", "TURTLE", true);
|
||||||
// Computation of URI that will be needed often, to limit frequent requests
|
// Computation of URI that will often be needed, to limit frequent requests
|
||||||
this.temperatureSensor1URI = this.getEntityURI("TemperatureSensor_1").get(0);
|
this.temperatureSensor1URI = this.getEntityURI("TemperatureSensor_1").get(0);
|
||||||
this.temperatureSensor2URI = this.getEntityURI("TemperatureSensor_2").get(0);
|
this.temperatureSensor2URI = this.getEntityURI("TemperatureSensor_2").get(0);
|
||||||
this.temperatureSensor3URI = this.getEntityURI("TemperatureSensor_3").get(0);
|
this.temperatureSensor3URI = this.getEntityURI("TemperatureSensor_3").get(0);
|
||||||
|
|
|
@ -2,38 +2,41 @@ package semantic;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import semantic.controler.Controller;
|
import semantic.controler.Controller;
|
||||||
import semantic.model.TimestampEntity;
|
import semantic.model.TimestampEntity;
|
||||||
|
|
||||||
public class TestModelFunctions
|
public class TestModelFunctions {
|
||||||
{
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlaceCreation()
|
public void testPlaceCreation() {
|
||||||
{
|
|
||||||
Controller c = new Controller();
|
Controller c = new Controller();
|
||||||
String jurassicParkURI = c.getCustomModel().createPlace("Jurassic park");
|
String jurassicParkURI = c.getCustomModel().createPlace("Jurassic park");
|
||||||
String placeClassURI = c.getModel().getEntityURI("Lieu").get(0);
|
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));
|
Assert.assertTrue("L'entité créée n'est pas de classe Lieu", c.getModel().isOfType(jurassicParkURI, placeClassURI));
|
||||||
Assert.assertTrue("Le lieu créé n'a pas de label pour indiquer son nom", c.getModel().listLabels(jurassicParkURI).contains("Jurassic park"));
|
Assert.assertTrue("Le lieu créé n'a pas de label pour indiquer son nom", c.getModel().listLabels(jurassicParkURI).contains("Jurassic park"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInstantCreation()
|
public void testInstantCreation() {
|
||||||
{
|
|
||||||
Controller c = new Controller();
|
Controller c = new Controller();
|
||||||
TimestampEntity t = new TimestampEntity("2014-02-13T06:20:00");
|
TimestampEntity t = new TimestampEntity("2014-02-13T06:20:00");
|
||||||
String instantURI = c.getCustomModel().createInstant(t);
|
String instantURI = c.getCustomModel().createInstant(t);
|
||||||
String instantClassURI = c.getModel().getEntityURI("Instant").get(0);
|
String instantClassURI = c.getModel().getEntityURI("Instant").get(0);
|
||||||
String propertyURI = c.getModel().getEntityURI("a pour timestamp").get(0);
|
String propertyURI = c.getModel().getEntityURI("a pour timestamp").get(0);
|
||||||
Assert.assertTrue("L'entité créée n'est pas de la classe Instant", c.getModel().isOfType(instantURI, instantClassURI));
|
Assert.assertTrue("L'entité créée n'est pas de la classe Instant", c.getModel().isOfType(instantURI, instantClassURI));
|
||||||
Assert.assertTrue("L'instant créé n'a pas le bon timestamp", c.getModel().hasDataPropertyValue(
|
Assert.assertTrue("L'instant créé n'a pas le bon timestamp", c.getModel().hasDataPropertyValue(
|
||||||
instantURI, propertyURI, "2014-02-13T06:20:00"));
|
instantURI, propertyURI, "2014-02-13T06:20:00"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInstantRetrieval()
|
public void testTimestampRetrieval() {
|
||||||
{
|
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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInstantRetrieval() {
|
||||||
Controller c = new Controller();
|
Controller c = new Controller();
|
||||||
TimestampEntity t = new TimestampEntity("2014-02-13T06:20:00");
|
TimestampEntity t = new TimestampEntity("2014-02-13T06:20:00");
|
||||||
TimestampEntity t2 = new TimestampEntity("2015-02-13T06:20:00");
|
TimestampEntity t2 = new TimestampEntity("2015-02-13T06:20:00");
|
||||||
|
@ -41,19 +44,9 @@ public class TestModelFunctions
|
||||||
Assert.assertTrue("La recherche d'un instant par timestamp ne retourne rien pour un instant sensé exister", c.getCustomModel().getInstantURI(t).equals(instantURI));
|
Assert.assertTrue("La recherche d'un instant par timestamp ne retourne rien pour un instant sensé exister", c.getCustomModel().getInstantURI(t).equals(instantURI));
|
||||||
Assert.assertNull("La recherche d'un instant par timestamp inexistant ne retourne pas un résultat null", c.getCustomModel().getInstantURI(t2));
|
Assert.assertNull("La recherche d'un instant par timestamp inexistant ne retourne pas un résultat null", c.getCustomModel().getInstantURI(t2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTimestampRetrieval()
|
public void testObservationCreation() {
|
||||||
{
|
|
||||||
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"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testObservationCreation()
|
|
||||||
{
|
|
||||||
Controller c = new Controller();
|
Controller c = new Controller();
|
||||||
TimestampEntity t = new TimestampEntity("2014-02-13T06:20:00");
|
TimestampEntity t = new TimestampEntity("2014-02-13T06:20:00");
|
||||||
String instantURI = c.getCustomModel().createInstant(t);
|
String instantURI = c.getCustomModel().createInstant(t);
|
||||||
|
@ -66,8 +59,8 @@ public class TestModelFunctions
|
||||||
String datePropertyURI = c.getModel().getEntityURI("a pour date").get(0);
|
String datePropertyURI = c.getModel().getEntityURI("a pour date").get(0);
|
||||||
String sensorURI = c.getModel().whichSensorDidIt("2014-02-13T06:20:00", paramURI);
|
String sensorURI = c.getModel().whichSensorDidIt("2014-02-13T06:20:00", paramURI);
|
||||||
Assert.assertTrue("L'observation n'est pas une instance de la bonne classe", c.getModel().isOfType(obsURI, obsClassURI));
|
Assert.assertTrue("L'observation n'est pas une instance de la bonne classe", c.getModel().isOfType(obsURI, obsClassURI));
|
||||||
Assert.assertTrue("L'observation n'a pas la bonne valeur",c.getModel().hasDataPropertyValue(obsURI, hasDataValueURI, value));
|
Assert.assertTrue("L'observation n'a pas la bonne valeur", c.getModel().hasDataPropertyValue(obsURI, hasDataValueURI, value));
|
||||||
Assert.assertTrue("L'observation n'a pas la bonne date",c.getModel().hasObjectProperty(obsURI, datePropertyURI, instantURI));
|
Assert.assertTrue("L'observation n'a pas la bonne date", c.getModel().hasObjectProperty(obsURI, datePropertyURI, instantURI));
|
||||||
Assert.assertTrue("L'observation n'est pas rattachée au bon capteur", c.getModel().hasSensorDoneIt(obsURI, sensorURI));
|
Assert.assertTrue("L'observation n'est pas rattachée au bon capteur", c.getModel().hasSensorDoneIt(obsURI, sensorURI));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue