generated from FacultadInformatica-LinkedData/Template-Curso
-
Notifications
You must be signed in to change notification settings - Fork 23
Assigment4 - Guillermo Diaz #70
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
Open
gdiazbenito
wants to merge
2
commits into
FacultadInformatica-LinkedData:master
Choose a base branch
from
gdiazbenito:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
|
|
||
| #1 | ||
|
|
||
| select distinct ?prop | ||
| where { | ||
| ?politician rdf:type <http://dbpedia.org/ontology/Politician>. | ||
| ?politician ?prop ?values | ||
|
|
||
| } | ||
| LIMIT 100 | ||
|
|
||
| #2 | ||
|
|
||
| select distinct ?prop | ||
| where { | ||
| ?politician rdf:type <http://dbpedia.org/ontology/Politician>. | ||
| ?politician ?prop ?values. | ||
| FILTER(?prop != rdf:type) | ||
| } | ||
| LIMIT 100 | ||
|
|
||
| #3 | ||
| select distinct ?values | ||
| where { | ||
| ?politician rdf:type <http://dbpedia.org/ontology/Politician>. | ||
| ?politician ?prop ?values. | ||
| FILTER(?prop != rdf:type) | ||
| } | ||
| LIMIT 100 | ||
|
|
||
| #4 | ||
| select distinct ?prop ?values | ||
| where { | ||
| ?politician rdf:type <http://dbpedia.org/ontology/Politician>. | ||
| ?politician ?prop ?values. | ||
| FILTER(?prop != rdf:type) | ||
| } | ||
| LIMIT 100 | ||
|
|
||
| #5 | ||
| select distinct ?prop COUNT(?values) | ||
| where { | ||
| ?politician rdf:type <http://dbpedia.org/ontology/Politician>. | ||
| ?politician ?prop ?values. | ||
| FILTER(?prop != rdf:type) | ||
| } | ||
| LIMIT 100 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """Task06.ipynb | ||
|
|
||
| Automatically generated by Colaboratory. | ||
|
|
||
| Original file is located at | ||
| https://colab.research.google.com/drive/1hSv61ejXESrp34CUz1PqZCsoA43tzc8y | ||
|
|
||
| **Task 06: Modifying RDF(s)** | ||
| """ | ||
|
|
||
| #pip install rdflib | ||
| github_storage = "https://raw.githubusercontent.com/FacultadInformatica-LinkedData/Curso2020-2021/master/Assignment4" | ||
|
|
||
| """Leemos el fichero RDF de la forma que lo hemos venido haciendo""" | ||
|
|
||
| from rdflib import Graph, Namespace, Literal, XSD | ||
| from rdflib.namespace import RDF, RDFS | ||
|
|
||
| with open('example5.rdf', 'r') as f: | ||
| 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(f, 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"** | ||
|
|
||
| **TASK 6.2: Add "Researcher" as a subclass of "Person"** | ||
|
|
||
| **TASK 6.3: Create a new individual of Researcher named "Jane Smith"** | ||
|
|
||
| **TASK 6.4: Add to the individual JaneSmith the fullName, given and family names** | ||
|
|
||
| **TASK 6.5: Add UPM as the university where John Smith works** | ||
| """ | ||
|
|
||
| "TASK 6.1:" | ||
| g.add((ns.University, RDF.type, RDFS.Class)) | ||
| #for s,p,o in g: | ||
| # print(s,p,o) | ||
|
|
||
| "TASK 6.2:" | ||
| g.add((ns.Researcher, RDFS.subClassOf, ns.Person)) | ||
| #for s,p,o in g: | ||
| #print(s,p,o) | ||
|
|
||
| "TASK 6.3:" | ||
| g.add((ns.JaneSmith,RDF.type,ns.Researcher)) | ||
| #for s,p,o in g: | ||
| #print(s,p,o) | ||
|
|
||
| "TASK 6.4:" | ||
| VCARD = Namespace("http://www.w3.org/2001/vcard-rdf/3.0#") | ||
| g.add((ns.JaneSmith, VCARD.FN, Literal('Jane Smith', datatype=XSD.string))) | ||
| g.add((ns.JaneSmith, VCARD.Family, Literal('Smith', datatype=XSD.string))) | ||
| g.add((ns.JaneSmith, VCARD.Given, Literal('Jane', datatype=XSD.string))) | ||
| #for s,p,o in g: | ||
| #print(s,p,o) | ||
|
|
||
| "TASK 6.5:" | ||
| g.add((ns.UPM, RDF.type, ns.University)) | ||
| g.add((ns.JohnSmith, VCARD.Works, ns.UPM)) | ||
| for s,p,o in g: | ||
| print(s,p,o) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """Task07.ipynb | ||
|
|
||
| Automatically generated by Colaboratory. | ||
|
|
||
| Original file is located at | ||
| https://colab.research.google.com/drive/1tV5j-DRcpPtoJGoMj8v2DSqR_9wyXeiE | ||
|
|
||
| **Task 07: Querying RDF(s)** | ||
| """ | ||
|
|
||
| #pip install rdflib | ||
| github_storage = "https://raw.githubusercontent.com/FacultadInformatica-LinkedData/Curso2020-2021/master/Assignment4" | ||
|
|
||
| """Leemos el fichero RDF de la forma que lo hemos venido haciendo""" | ||
|
|
||
| from rdflib import Graph, Namespace, Literal | ||
| from rdflib.namespace import RDF, RDFS | ||
| from rdflib.plugins.sparql import prepareQuery | ||
|
|
||
| with open('../python/example6.rdf', 'r') as f: | ||
| 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(f, format="xml") | ||
| """**TASK 7.1: List all subclasses of "Person" with RDFLib and SPARQL** | ||
|
|
||
| **TASK 7.2: List all individuals of "Person" with RDFLib and SPARQL (remember the subClasses)** | ||
|
|
||
| **TASK 7.3: List all individuals of "Person" and all their properties including their class with RDFLib and SPARQL** | ||
| """ | ||
|
|
||
| "TASK 7.1:" | ||
| ns = Namespace("http://somewhere#") | ||
| #Con RDFLib | ||
| for s,p,o in g.triples((None, RDFS.subClassOf, ns.Person)): | ||
| print(s,p,o) | ||
| #Con SPRQL | ||
| q1 = prepareQuery(''' | ||
| SELECT | ||
| ?Subclass | ||
| WHERE { | ||
| ?Subclass RDFS:subClassOf ns:Person. | ||
| } | ||
| ''', | ||
| initNs={"RDFS": RDFS, "ns": ns} | ||
| ) | ||
| for r in g.query(q1): | ||
| print(r.Subclass) | ||
|
|
||
|
|
||
| "TASK 7.2:" | ||
| #Con RDFLib | ||
| for s,p,o in g.triples((None, RDF.type , ns.Person)): | ||
| print(s,p,o) | ||
| for s,p,o in g.triples((None, RDFS.subClassOf, ns.Person)): | ||
| for s2,p2,o2 in g.triples((None,RDF.type,s)): | ||
| print(s2,p2,o2) | ||
| #Con SPRQL | ||
| q1= prepareQuery(''' | ||
| SELECT | ||
| ?Persons | ||
| WHERE { | ||
| ?Persons RDF:type ns:Person. | ||
| } | ||
| ''', | ||
| initNs={"RDF": RDF, "ns": ns} | ||
| ) | ||
| #subclases | ||
| q2 = prepareQuery(''' | ||
| SELECT | ||
| ?Persons | ||
| WHERE { | ||
| ?Subclass RDFS:subClassOf ns:Person. | ||
| ?Persons RDF:type ns:Person. | ||
| } | ||
| ''', | ||
| initNs={"RDFS": RDFS, "ns": ns, "RDF":RDF} | ||
| ) | ||
| for r in g.query(q1): | ||
| print(r.Persons) | ||
|
|
||
| for r in g.query(q2): | ||
| print(r.Persons) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing task 7.3