diff --git a/Assignment1/DatasetDescriptions.csv b/Assignment1/DatasetDescriptions.csv index 233580cd..98d29c3c 100644 --- a/Assignment1/DatasetDescriptions.csv +++ b/Assignment1/DatasetDescriptions.csv @@ -69,4 +69,5 @@ Dalei Li, Beijing Hourly PM2.5 data, http://www.stateair.net/web/historical/1/1. Alberto Martín de Pablo,taxi Zaragoza,https://datahub.io/dataset/taxi-zaragoza,Información relativa al Servicio de Taxis en la ciudad de Zaragoza Alfonso Mateos Pérez-Iñigo, casas cultura ciudad Bogotá https://www.datos.gov.co/en/Cultura/Casas-de-la-Cultura-Ciudad-de-Bogot-/g72h-f9ru/data Santaigo Cervantes Reus, Puntos de interes de Zaragoza, http://www.zaragoza.es/ciudad/risp/detalle_Risp?id=23 -Pablo Sayans Cobos, Llegadas y salidas de aviones a Singapore, https://data.gov.sg/dataset/aircraft-arrivals-departures, La medición empieza en el año 2005 \ No newline at end of file +Pablo Sayans Cobos, Llegadas y salidas de aviones a Singapore, https://data.gov.sg/dataset/aircraft-arrivals-departures, La medición empieza en el año 2005 +Ismael Ayat Ortiz, Santander bus lines information, http://datos.santander.es/api/rest/datasets/lineas_bus.rdf?items=33, dataset with a lot of information about the different bus lines in Santander \ No newline at end of file diff --git a/Assignment2/Ismmael.jpg b/Assignment2/Ismmael.jpg new file mode 100644 index 00000000..794a3964 Binary files /dev/null and b/Assignment2/Ismmael.jpg differ diff --git a/Assignment2/Ismmael.rdf b/Assignment2/Ismmael.rdf new file mode 100644 index 00000000..70b233cf --- /dev/null +++ b/Assignment2/Ismmael.rdf @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + Pedro + + + + + + + + + + + + 29 + 2010-06-12T 12:00:12 + + + diff --git a/Assignment2/Ismmael.ttl b/Assignment2/Ismmael.ttl new file mode 100644 index 00000000..b28b292a --- /dev/null +++ b/Assignment2/Ismmael.ttl @@ -0,0 +1,20 @@ +@base . +@prefix class: . +@prefix sensor: . +@prefix computer: . +@prefix user: . +@prefix measurement: . + +:Class01 class:includes:Sensor029; + class:includes:Computer101. + +:User10A user:hasName "Pedro"; + +:Sensor029 sensor:hasMeasurement:Measurement8401. + +:Computer101 computer:hasOwner:User10A. + +:Measurement8401 measurement:hasTemperature "29"; + measurement:atTime "2010-06-12T 12:00:12". + + diff --git a/Assignment3/Ismmael-w140334/Task06.java b/Assignment3/Ismmael-w140334/Task06.java new file mode 100644 index 00000000..2ba179cc --- /dev/null +++ b/Assignment3/Ismmael-w140334/Task06.java @@ -0,0 +1,87 @@ +package ontologyapi; + +import java.io.InputStream; + +import org.apache.jena.ontology.Individual; +import org.apache.jena.ontology.OntClass; +import org.apache.jena.ontology.OntModel; +import org.apache.jena.ontology.OntModelSpec; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.rdf.model.Property; +import org.apache.jena.util.FileManager; +import org.apache.jena.vocabulary.VCARD; + +/** + * Task 06: Modifying ontologies (RDFs) + * @author Ismael Ayat Ortiz - w140334 - Ismmael + * + * + */ +public class Task06 +{ + public static String ns = "http://somewhere#"; + public static String foafNS = "http://xmlns.com/foaf/0.1/"; + public static String foafEmailURI = foafNS+"email"; + public static String foafKnowsURI = foafNS+"knows"; + public static String stringTypeURI = "http://www.w3.org/2001/XMLSchema#string"; + + public static void main(String args[]) + { + String filename = "example5.rdf"; + + // Create an empty model + OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM); + + // Use the FileManager to find the input file + InputStream in = FileManager.get().open(filename); + + if (in == null) + throw new IllegalArgumentException("File: "+filename+" not found"); + + // Read the RDF/XML file + model.read(in, null); + + // Create a new class named "Researcher" + OntClass researcher = model.createClass(ns+"Researcher"); + + // ** TASK 6.1: Create a new class named "University" ** + + OntClass university = model.createClass(ns + "University"); + + // ** TASK 6.2: Add "Researcher" as a subclass of "Person" ** + + OntClass person = model.createClass(ns + "Person"); + person.addSubClass(researcher); + + // ** TASK 6.3: Create a new property named "worksIn" ** + + Property worksIn = model.createProperty(ns + "worksIn"); + + // ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" ** + + Individual jane_Smith = researcher.createIndividual(ns + "Jane Smith"); + + // ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names ** + + // Adding Full Name + jane_Smith.addProperty(VCARD.FN,"Jane Smith"); + + + // Adding Family Name + jane_Smith.addProperty(VCARD.Family,"Smith"); + + // Adding Given Name + jane_Smith.addProperty(VCARD.Given,"Jane"); + + // ** TASK 6.6: Add UPM as the university where John Smith works ** + + System.out.println("Task 6.6"); + + Individual upm = university.createIndividual(ns+"UPM"); + Individual john_Smith = model.getIndividual(ns+"John Smith"); + + john_Smith.addProperty(worksIn,upm); + + model.write(System.out, "RDF/XML-ABBREV"); + } +} diff --git a/Assignment3/Ismmael-w140334/Task07.java b/Assignment3/Ismmael-w140334/Task07.java new file mode 100644 index 00000000..d97e73b0 --- /dev/null +++ b/Assignment3/Ismmael-w140334/Task07.java @@ -0,0 +1,84 @@ +package ontologyapi; + +import java.io.InputStream; + +import org.apache.jena.ontology.Individual; +import org.apache.jena.ontology.OntClass; +import org.apache.jena.ontology.OntModel; +import org.apache.jena.ontology.OntModelSpec; +import org.apache.jena.ontology.OntResource; +import org.apache.jena.rdf.model.ModelFactory; +import org.apache.jena.util.FileManager; +import org.apache.jena.util.iterator.ExtendedIterator; + +/** + * Task 07: Querying ontologies (RDFs) + * @author Ismael Ayat Ortiz - w140334 - Ismmael + * + */ +public class Task07 +{ + public static String ns = "http://somewhere#"; + + public static void main(String args[]) + { + String filename = "example6.rdf"; + + // Create an empty model + OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM); + + // Use the FileManager to find the input file + InputStream in = FileManager.get().open(filename); + + if (in == null) + throw new IllegalArgumentException("File: "+filename+" not found"); + + // Read the RDF/XML file + model.read(in, null); + + + // ** TASK 7.1: List all individuals of "Person" ** + System.out.println("Task 7.1"); + System.out.println(""); + + Resource x = model.getResource(ns+"Person"); + ExtendedIterator iterador = model.listIndividuals(x); + int size = 1; + while(iterador.hasNext()) + { + System.out.println("Person " + size + " : " + iterador.next().getURI()); + size++; + } + + System.out.println(""); + + // ** TASK 7.2: List all subclasses of "Person" ** + + System.out.println("Task 7.2"); + System.out.println(""); + + ExtendedIterator iterador2 = x.listSubClasses(); + int size2 = 1; + while(iterador2.hasNext()){ + System.out.println("Subclasses: "+ size2 + " : " + iterador2.next().getURI()); + size2++; + } + System.out.println(""); + + // ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... ** + + System.out.println("Task 7.3"); + System.out.println(""); + System.out.println("Individuals:") + OntClass personas = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF, model).getOntClass(ns+"Person"); + for (ExtendedIterator i = (ExtendedIterator) personas.listInstances(); i.hasNext()){ + System.out.println(i.next().getURI()); + } + + System.out.println(""); + System.out.println("Subclasses:"); + for (ExtendedIterator i = persons.listSubClasses(); i.hasNext()){ + System.out.println(i.next().getURI()); + }; + } +} diff --git a/Assignment6/Ismmael-w140334/queries.sparql b/Assignment6/Ismmael-w140334/queries.sparql new file mode 100644 index 00000000..34ee8071 --- /dev/null +++ b/Assignment6/Ismmael-w140334/queries.sparql @@ -0,0 +1,126 @@ +// Ismael Ayat Ortiz - w140334 - Ismmael + + +///// 1.) How many accidents were there in Madrid in 2013? + +PREFIX mv: +PREFIX qb: +SELECT (SUM(?x) AS ?numberOfAccidents) WHERE { + ?obs a qb:Observation ; + mv:numberOfAccidents ?x . +} + +// Resultado: 11749 + + +///// 2.) Give me the number of accidens in Usera for each type of accident + +PREFIX mv: +PREFIX qb: +SELECT ?accidentType xsd:integer(?numberAccidents) AS ?number WHERE { + ?obs a qb:Observation ; + mv:relatedDistrict "USERA"; + mv:hasAccidentType ?accidentType ; + mv:numberOfAccidents ?numberAccidents +} + +// Resultado: + +// http://example.org/myVocabulary#DoubleCollision 204 +// http://example.org/myVocabulary#MultipleCollision 28 +// http://example.org/myVocabulary#CollisionWithObject 70 +// http://example.org/myVocabulary#RunOver 59 +// http://example.org/myVocabulary#Overturn 2 +// http://example.org/myVocabulary#MotorcycleFall 13 +// http://example.org/myVocabulary#MopedFall 5 +// http://example.org/myVocabulary#BicycleFall 1 +// http://example.org/myVocabulary#BusPassengerFall 3 +// http://example.org/myVocabulary#OtherCause 2 + + +///// 3.) Give me the number of multiple collisions for each district + +PREFIX mv: +PREFIX qb: +SELECT ?x AS ?district xsd:integer(?y) AS ?collisionsNumber WHERE{ + ?obs a qb:Observation ; + mv:relatedDistrict ?x ; + mv:hasAccidentType mv:MultipleCollision ; + mv:numberOfAccidents ?y . +} + +// Resultado: + +// BARAJAS 4 +// VICALVARO 4 +// VILLA DE VALLECAS 4 +// VILLAVERDE 11 +// MORATALAZ 14 +// SAN BLAS 16 +// HORTALEZA 18 +// USERA 28 +// LATINA 29 +// CHAMBERI 30 +// CENTRO 33 +// TETUAN 35 +// PUENTE DE VALLECAS 37 +// CARABANCHEL 40 +// FUENCARRAL-EL PARDO 42 +// ARGANZUELA 50 +// CIUDAD LINEAL 52 +// RETIRO 59 +// MONCLOA-ARAVACA 65 +// SALAMANCA 70 +// CHAMARTIN 82 + + +///// 4.) Which is the district were the number of bicycle falls was higher in 2013? + +PREFIX mv: +PREFIX qb: +SELECT ?x AS ?district xsd:integer(MAX(?y)) AS ?numberAccidents WHERE { + ?obs a qb:Observation ; + mv:relatedDistrict ?x ; + mv:numberOfAccidents ?y; + mv:hasAccidentType mv:BicycleFall . +} +ORDER BY DESC(?y) + +// En este caso se elige el primer elemento de la lista (puesto que la última línea de la query ordena los elementos en orden descendente. +// En este caso hay tres distritos que son FUENCARRAL, MONCLOA y SAN BLAS con 13 cada uno. + + +///// 5.) Give me the districts with more than 500 accidents in 2013 + +PREFIX mv: +PREFIX qb: +SELECT ?x AS ?district ?y AS ?accidentNumber +WHERE { +{ +SELECT ?x SUM(xsd:integer(?z)) AS ?y +WHERE +{ + ?obs a qb:Observation ; + mv:relatedDistrict ?x ; + mv:numberOfAccidents ?z . +} +} +} +HAVING(?y > 500) + +//Resultado: + +// TETUAN 594 +// CENTRO 926 +// CHAMBERI 715 +// PUENTE DE VALLECAS 651 +// RETIRO 593 +// SAN BLAS 518 +// ARGANZUELA 631 +// CHAMARTIN 844 +// FUENCARRAL-EL PARDO 682 +// SALAMANCA 982 +// CARABANCHEL 709 +// CIUDAD LINEAL 750 +// LATINA 530 +// MONCLOA-ARAVACA 702 \ No newline at end of file