Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added asignment 2a #43

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
111 changes: 111 additions & 0 deletions Assignment2/andreigrozescu-fromJSONtoJSON-LD.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"@context": {
"fullName": "http://schema.org/name",
"hometown": "http://schema.org/homeLocation",
"age": "http://schema.org/age",
"almaMater": "http://schema.org/alumniOf",
"parents": "http://schema.org/parent",
"subjects": {
"@id": "http://schema.org/Subject",
"@container": "@set"
},
"name": "http://schema.org/name",
"teachers": "http://schema.org/teacher",
"briefDescription": "http://schema.org/description"
},
"@type": "Person",
"fullName": "Andrei Iulian Grozescu",
"hometown": "Aranjuez",
"age": 29,
"almaMater": "UPM",
"parents": [
{
"@id": "http://example.org/Elisa",
"hasName": "Elisa"
},
{
"@id": "http://example.org/Iulian",
"hasName": "Iulian"
}
],
"subjects": [
{
"@type": "Course",
"name": "PROBABILIDADES Y ESTADÍSTICA II",
"teachers": "-",
"briefDescription": "This course covers advanced probability theory and statistical methods, focusing on their application in various fields such as data analysis, decision making, and modeling uncertainty."
},
{
"@type": "Course",
"name": "GESTIÓN DE PROCESOS DE TECNOLOGÍAS DE LA INFORMACIÓN",
"teachers": "-",
"briefDescription": "This course explores IT process management techniques, including frameworks like ITIL, and focuses on aligning IT services with the needs of a business while improving efficiency."
},
{
"@type": "Course",
"name": "PROGRAMACIÓN DECLARATIVA: LÓGICA Y RESTRICCIONES",
"teachers": "-",
"briefDescription": "This subject introduces declarative programming paradigms, focusing on logic programming and constraint satisfaction problems, using languages like Prolog and CLP."
},
{
"@type": "Course",
"name": "INGENIERÍA DEL SOFTWARE II",
"teachers": "-",
"briefDescription": "A continuation of Software Engineering I, this course delves deeper into software development processes, methodologies, and practices for large-scale systems, with a focus on quality assurance and project management."
},
{
"@type": "Course",
"name": "ADMINISTRACIÓN DE SISTEMAS INFORMÁTICOS",
"teachers": "-",
"briefDescription": "This course covers system administration concepts, focusing on the management, configuration, and maintenance of information systems, with hands-on experience in operating systems, networks, and security."
},
{
"@type": "Course",
"name": "WEB SEMÁNTICA, LINKED DATA Y GRAFOS DE CONOCIMIENTOS",
"teachers": "-",
"briefDescription": "This course provides an introduction to Semantic Web technologies, linked data principles, and knowledge graphs, focusing on how they are used to enhance the interoperability and utility of web data."
},
{
"@type": "Course",
"name": "NANOTECNOLOGÍA",
"teachers": "-",
"briefDescription": "An introductory course on nanotechnology, exploring the fundamental concepts of nanoscience, nanomaterials, and their applications in fields like electronics, medicine, and materials science."
},
{
"@type": "Course",
"name": "COMPUTABILIDAD: FUNDAMENTOS Y APLICACIONES",
"teachers": "-",
"briefDescription": "This subject delves into the theoretical foundations of computability, exploring models like Turing machines and their applications in understanding the limits of what can be computed."
},
{
"@type": "Course",
"name": "APLICACIONES DE LA BIOMETRÍA DE LA VOZ",
"teachers": "-",
"briefDescription": "This course covers voice biometrics and its applications, focusing on technologies and algorithms used in voice recognition systems for security, authentication, and other practical uses."
},
{
"@type": "Course",
"name": "ARQUITECTURA DEL DATA WAREHOUSE",
"teachers": "-",
"briefDescription": "This course focuses on the architecture, design, and implementation of data warehouses, teaching students how to integrate, manage, and optimize large-scale data storage systems for decision support."
},
{
"@type": "Course",
"name": "MINERÍA DE DATOS",
"teachers": "-",
"briefDescription": "This course introduces data mining techniques and algorithms for extracting valuable patterns and knowledge from large datasets, focusing on real-world applications and tools."
},
{
"@type": "Course",
"name": "TEORÍA DE LA INFORMACIÓN Y LA CODIFICACIÓN",
"teachers": "-",
"briefDescription": "This course covers the principles of information theory, including entropy, data compression, and coding theory, with applications in communication systems and data transmission."
},
{
"@type": "Course",
"name": "INTELIGENCIA ARTIFICIAL Y CIENCIA ABIERTA EN INGENIERÍA DE SOFTWARE CIENTÍFICO",
"teachers": "-",
"briefDescription": "This course explores the integration of artificial intelligence techniques in scientific software engineering, emphasizing open science principles, reproducibility, and collaborative development."
}
]
}
44 changes: 44 additions & 0 deletions Assignment2/andreigrozescu-fromRDFtoJSON-LD.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"@context": {
"includes": "http://example.org/includes",
"hasMeasurement": "http://example.org/hasMeasurement",
"hasTemperature": "http://example.org/hasTemperature",
"atTime": "http://example.org/atTime",
"hasOwner": "http://example.org/hasOwner",
"hasName": "http://example.org/hasName"
},
"@graph": [
{
"@id": "http://example.org/Class01",
"includes": [
{
"@id": "http://example.org/Sensor029"
},
{
"@id": "http://example.org/Computer101"
}
]
},
{
"@id": "http://example.org/Sensor029",
"hasMeasurement": {
"@id": "http://example.org/Measurement8401"
}
},
{
"@id": "http://example.org/Measurement8401",
"hasTemperature": 29,
"atTime": "2010-06-12T12:00:12"
},
{
"@id": "http://example.org/Computer101",
"hasOwner": {
"@id": "http://example.org/User10A"
}
},
{
"@id": "http://example.org/User10A",
"hasName": "Pedro"
}
]
}
Binary file added Assignment2/andreigrozescu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions Assignment2/andreigrozescu.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@prefix ex: <http://example.org/> .

ex:ClassRoom03
ex:contains ex:Sensor347, ex:Table322 .

ex:Sensor347
ex:hasMeasurement ex:Measurement8432 .

ex:Measurement8432
ex:hasTemperature "29" ;
ex:atTime "2022-09-12T12:01:12"^^xsd:dateTime .

ex:Table322
ex:hasOwner ex:ETSInformaticos .

ex:ETSInformaticos
ex:hasName "ETSI Informaticos" .
94 changes: 94 additions & 0 deletions Assignment4/andreigrozescu-140217/andreigrozescu-140217/task06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# -*- coding: utf-8 -*-
"""Task06.ipynb

Automatically generated by Colab.

Original file is located at
https://colab.research.google.com/drive/1VCVegwrLrueUy0tY4tjxBAaFhZSikRrK

**Task 06: Modifying RDF(s)**
"""

!pip install rdflib
github_storage = "https://raw.githubusercontent.com/FacultadInformatica-LinkedData/Curso2024-2025/master/Assignment4/course_materials"

"""Read the RDF file as shown in class"""

from rdflib import Graph, Namespace, Literal
from rdflib.namespace import RDF, RDFS
g = Graph()
g.namespace_manager.bind('ns', Namespace("http://somewhere#"), override=False)
g.namespace_manager.bind('vcard', Namespace("http://www.w3.org/2001/vcard-rdf/3.0#"), override=False)
g.parse(github_storage+"/rdf/example5.rdf", format="xml")

"""Create a new class named Researcher"""

ns = Namespace("http://somewhere#")
g.add((ns.Researcher, RDF.type, RDFS.Class))
for s, p, o in g:
print(s,p,o)

"""**TASK 6.1: Create a new class named "University"**

"""

g.add((ns.University, RDF.type, RDFS.Class))
# Visualize the results
for s, p, o in g:
print(s,p,o)

"""**TASK 6.2: Add "Researcher" as a subclass of "Person"**"""

g.add((ns.Researcher, RDFS.subClassOf, ns.Person))
# Visualize the results
for s, p, o in g:
print(s,p,o)

"""**TASK 6.3: Create a new individual of Researcher named "Jane Smithers"**"""

g.add((ns.JaneSmithers, RDF.type, ns.Researcher))
# Visualize the results
for s, p, o in g:
print(s,p,o)

"""**TASK 6.4: Add to the individual JaneSmithers the email address, fullName, given and family names. Use the https://schema.org vocabulary**"""

# Bind schema.org namespace
schema = Namespace("https://schema.org/")
g.namespace_manager.bind('schema', schema)

# Add information about JaneSmithers using the schema.org vocabulary
g.add((ns.JaneSmithers, schema.email, Literal("janesmithers@example.org")))
g.add((ns.JaneSmithers, schema.givenName, Literal("Jane")))
g.add((ns.JaneSmithers, schema.familyName, Literal("Smithers")))
g.add((ns.JaneSmithers, schema.name, Literal("Jane Smithers")))

# Visualize the results
for s, p, o in g:
print(s, p, o)

"""**TASK 6.5: Add UPM as the university where John Smith works. Use the "https://example.org/ namespace**"""

# Bind the example.org namespace
example = Namespace("https://example.org/")
g.namespace_manager.bind('ex', example)

# Add UPM as the university where John Smith works
g.add((ns.JohnSmith, example.worksAt, ns.UPM))

# Visualize the results
for s, p, o in g:
print(s, p, o)

"""**Task 6.6: Add that Jown knows Jane using the FOAF vocabulary. Make sure the relationship exists.**"""

# Bind FOAF namespace
foaf = Namespace("http://xmlns.com/foaf/0.1/")
g.namespace_manager.bind('foaf', foaf)

# Add that JohnSmith knows JaneSmithers
g.add((ns.JohnSmith, foaf.knows, ns.JaneSmithers))

# Visualize the results
for s, p, o in g:
print(s, p, o)
122 changes: 122 additions & 0 deletions Assignment4/andreigrozescu-140217/andreigrozescu-140217/task07.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# -*- coding: utf-8 -*-
"""Task07.ipynb

Automatically generated by Colab.

Original file is located at
https://colab.research.google.com/drive/1dHEHWl7T0lAC-LTnytd4TzCfvFba97yb

**Task 07: Querying RDF(s)**
"""

!pip install rdflib
github_storage = "https://raw.githubusercontent.com/FacultadInformatica-LinkedData/Curso2024-2025/master/Assignment4/course_materials"

"""First let's read the RDF file"""

from rdflib import Graph, Namespace, Literal
from rdflib.namespace import RDF, RDFS
g = Graph()
g.namespace_manager.bind('ns', Namespace("http://somewhere#"), override=False)
g.namespace_manager.bind('vcard', Namespace("http://www.w3.org/2001/vcard-rdf/3.0#"), override=False)
g.parse(github_storage+"/rdf/example6.rdf", format="xml")

"""**TASK 7.1: List all subclasses of "LivingThing" with RDFLib and SPARQL**"""

q1 = """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?subclass
WHERE {
?subclass rdfs:subClassOf <http://somewhere#LivingThing> .
}
"""
# Visualize the results

print("Subclasses of LivingThing:")
for r in g.query(q1):
print(r)

"""**TASK 7.2: List all individuals of "Person" with RDFLib and SPARQL (remember the subClasses)**

"""

q2 = """
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?individual
WHERE {
?individual rdf:type <http://somewhere#Person> .
}
"""
print("\nIndividuals of Person:")
for r in g.query(q2):
print(r)

"""**TASK 7.3: List all individuals of just "Person" or "Animal". You do not need to list the individuals of the subclasses of person (in SPARQL only)**

"""

q3 = """
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?individual
WHERE {
{
?individual rdf:type <http://somewhere#Person> .
FILTER NOT EXISTS {
?individual rdf:type ?subclass .
?subclass rdfs:subClassOf <http://somewhere#Person> .
}
}
UNION
{
?individual rdf:type <http://somewhere#Animal> .
}
}
"""
print("\nIndividuals of just Person or Animal:")
for r in g.query(q3):
print(r)

"""**TASK 7.4: List the name of the persons who know Rocky (in SPARQL only)**"""

q4 = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE {
?person foaf:knows <http://somewhere#Rocky> .
?person <http://www.w3.org/2001/vcard-rdf/3.0/FN> ?name .
}
"""
print("\nList the name of the persons who know Rocky:")
for r in g.query(q4):
print(r)

"""**Task 7.5: List the name of those animals who know at least another animal in the graph (in SPARQL only)**"""

q5 = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?animal
WHERE {
?animal rdf:type <http://somewhere#Animal> .
?animal foaf:knows ?anotherAnimal .
?anotherAnimal rdf:type <http://somewhere#Animal> .
FILTER(?animal != ?anotherAnimal) # Ensure it's a different animal
}
"""
print("\nAnimals who know at least another animal:")
for r in g.query(q5):
print(r)

"""**Task 7.6: List the age of all living things in descending order (in SPARQL only)**"""

q6 = """
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?livingThing ?age
WHERE {
?livingThing rdf:type <http://somewhere#LivingThing> .
?livingThing <http://somewhere#age> ?age .
}
ORDER BY DESC(?age)
"""
print("\nAge of all living things in descending order:")
for r in g.query(q6):
print(r)