Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Assignment1/DatasetDescriptions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Binary file added Assignment2/Ismmael.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions Assignment2/Ismmael.rdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0"?>

<rdf:RDF

xmlns="http://www.oeg-upm.net/ontologies/class#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:class="http://www.oeg-upm.net/ontologies/class#"
xmlns:sensor="http://www.oeg-upm.net/ontologies/sensor#"
xmlns:computer="http://www.oeg-upm.net/ontologies/computer#"
xmlns:measurement="http://www.oeg-upm.net/ontologies/measurement#"
xmlns:user="http://www.oeg-upm.net/ontologies/user#"
xml:base="http://www.oeg-upm.net/ontologies/class">

<rdf:Property rdf:about="http://www.oeg-upm.net/ontologies/#includes"/>
<rdf:Property rdf:about="http://www.oeg-upm.net/ontologies/#hasMeasurement"/>
<rdf:Property rdf:about="http://www.oeg-upm.net/ontologies/#hasOwner"/>
<rdf:Property rdf:about="http://www.oeg-upm.net/ontologies/#hasName"/>
<rdf:Property rdf:about="http://www.oeg-upm.net/ontologies/#hasTemperature"/>
<rdf:Property rdf:about="http://www.oeg-upm.net/ontologies/#atTime"/>

<rdf:Description rdf:about="#Class01">
<class:includes rdf:resource="#Sensor029"/>
<class:includes rdf:resource="#Computer101"/>
</rdf:Description>

<rdf:Description rdf:about="#User10A">
<user:hasName>Pedro</user:hasName>
</rdf:Description>

<rdf:Description rdf:about="#Sensor029">
<sensor:hasMeasurement rdf:resource="#Measurement8401"/>
</rdf:Description>

<rdf:Description rdf:about="#Computer101">
<computer:hasOwner rdf:resource="#User10A"/>
</rdf:Description>

<rdf:Description rdf:about="#Measurement8401">
<measurement:hasTemperature>29</measurement:hasTemperature>
<measurement:atTime>2010-06-12T 12:00:12</measurement:atTime>
</rdf:Description>

</rdf:RDF>
20 changes: 20 additions & 0 deletions Assignment2/Ismmael.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@base <http://www.oeg-upm.net/ontologies/class/> .
@prefix class: <http://www.oeg-upm.net/ontologies/class#> .
@prefix sensor: <http://www.oeg-upm.net/ontologies/sensor#> .
@prefix computer: <http://www.oeg-upm.net/ontologies/computer#> .
@prefix user: <http://www.oeg-upm.net/ontologies/user#> .
@prefix measurement: <http://www.oeg-upm.net/ontologies/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".


87 changes: 87 additions & 0 deletions Assignment3/Ismmael-w140334/Task06.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
84 changes: 84 additions & 0 deletions Assignment3/Ismmael-w140334/Task07.java
Original file line number Diff line number Diff line change
@@ -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<Individual> 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<OntClass> 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<Individual> i = (ExtendedIterator<Individual>) personas.listInstances(); i.hasNext()){
System.out.println(i.next().getURI());
}

System.out.println("");
System.out.println("Subclasses:");
for (ExtendedIterator<OntClass> i = persons.listSubClasses(); i.hasNext()){
System.out.println(i.next().getURI());
};
}
}
126 changes: 126 additions & 0 deletions Assignment6/Ismmael-w140334/queries.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Ismael Ayat Ortiz - w140334 - Ismmael


///// 1.) How many accidents were there in Madrid in 2013?

PREFIX mv: <http://example.org/myVocabulary#>
PREFIX qb: <http://purl.org/linked-data/cube#>
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: <http://example.org/myVocabulary#>
PREFIX qb: <http://purl.org/linked-data/cube#>
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: <http://example.org/myVocabulary#>
PREFIX qb: <http://purl.org/linked-data/cube#>
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: <http://example.org/myVocabulary#>
PREFIX qb: <http://purl.org/linked-data/cube#>
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: <http://example.org/myVocabulary#>
PREFIX qb: <http://purl.org/linked-data/cube#>
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