Compare commits
9 Commits
ce2d08ebc3
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d01f26e72 | ||
|
|
8e177963af | ||
|
|
ecd53ceee5 | ||
|
|
99f8032d05 | ||
|
|
470a3d692d | ||
|
|
d66bb25245 | ||
|
|
f10e6650c9 | ||
|
|
c9d16bdda3 | ||
|
|
08d2621a98 |
@@ -34,7 +34,7 @@
|
|||||||
"* This notebook, which explains basic concepts of RDF and SPARQL\n",
|
"* This notebook, which explains basic concepts of RDF and SPARQL\n",
|
||||||
"* [A notebook](01_SPARQL_Introduction.ipynb) that provides an introduction to SPARQL through a collection of exercises of increasing difficulty.\n",
|
"* [A notebook](01_SPARQL_Introduction.ipynb) that provides an introduction to SPARQL through a collection of exercises of increasing difficulty.\n",
|
||||||
"* [An optional notebook](02_SPARQL_Custom_Endpoint.ipynb) with queries to a custom dataset.\n",
|
"* [An optional notebook](02_SPARQL_Custom_Endpoint.ipynb) with queries to a custom dataset.\n",
|
||||||
"The dataset is meant to be done after the [RDF exercises](../rdf/RDF.ipynb) and it is out of the scope of this course.\n",
|
"The dataset is meant to be done after the [RDF exercises](../rdf/RDF.ipynb), and it is out of the scope of this course.\n",
|
||||||
"You can consult it if you are interested."
|
"You can consult it if you are interested."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -51,8 +51,8 @@
|
|||||||
" \n",
|
" \n",
|
||||||
"An RDF statement expresses a relationship between two resources. The **subject** and the **object** represent the two resources being related; the **predicate** represents the nature of their relationship.\n",
|
"An RDF statement expresses a relationship between two resources. The **subject** and the **object** represent the two resources being related; the **predicate** represents the nature of their relationship.\n",
|
||||||
"The relationship is phrased in a directional way (from subject to object).\n",
|
"The relationship is phrased in a directional way (from subject to object).\n",
|
||||||
"In RDF this relationship is known as a **property**.\n",
|
"In RDF, this relationship is known as a **property**.\n",
|
||||||
"Because RDF statements consist of three elements they are called **triples**.\n",
|
"Because RDF statements consist of three elements, they are called **triples**.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Here are some examples of RDF triples (informally expressed in pseudocode):\n",
|
"Here are some examples of RDF triples (informally expressed in pseudocode):\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"To use the library, you need to:\n",
|
"To use the library, you need to:\n",
|
||||||
"\n",
|
"\n",
|
||||||
"1. Import `sparql` from helpers (i.e., `helpers.py`, a file that is available in the github repository)\n",
|
"1. Import `sparql` from helpers (i.e., `helpers.py`, a file that is available in the GitHub repository)\n",
|
||||||
"2. Use the `%%sparql` magic command to indicate the SPARQL endpoint and then the SPARQL code.\n",
|
"2. Use the `%%sparql` magic command to indicate the SPARQL endpoint and then the SPARQL code.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Let's try it!\n",
|
"Let's try it!\n",
|
||||||
@@ -137,7 +137,7 @@
|
|||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Well, it worked, but the results are not particulary interesting. \n",
|
"Well, it worked, but the results are not particularly interesting. \n",
|
||||||
"Let's search for a famous football player, Fernando Torres.\n",
|
"Let's search for a famous football player, Fernando Torres.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"To do so, we will search for entities whose English \"human-readable representation\" (i.e., label) matches \"Fernando Torres\":"
|
"To do so, we will search for entities whose English \"human-readable representation\" (i.e., label) matches \"Fernando Torres\":"
|
||||||
@@ -166,7 +166,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"Now we can start asking for more properties.\n",
|
"Now we can start asking for more properties.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"To do so, go to http://dbpedia.org/resource/Fernando_Torres and you will see all the information available about Fernando Torres. Pay attention to the names of predicates to be able to create new queries. For example, we are interesting in knowing where Fernando Torres was born (`dbo:birthPlace`).\n",
|
"To do so, go to http://dbpedia.org/resource/Fernando_Torres, and you will see all the information available about Fernando Torres. Pay attention to the names of predicates to be able to create new queries. For example, we are interesting in knowing where Fernando Torres was born (`dbo:birthPlace`).\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Let's go!"
|
"Let's go!"
|
||||||
]
|
]
|
||||||
@@ -202,13 +202,13 @@
|
|||||||
"Now take a closer look at the **WHERE** section.\n",
|
"Now take a closer look at the **WHERE** section.\n",
|
||||||
"We said earlier that triples are made out of three elements and each triple pattern should finish with a period (`.`) (although the last pattern can omit this).\n",
|
"We said earlier that triples are made out of three elements and each triple pattern should finish with a period (`.`) (although the last pattern can omit this).\n",
|
||||||
"However, when two or more triple patterns share the same subject, we omit it all but the first one, and use ` ;` as separator.\n",
|
"However, when two or more triple patterns share the same subject, we omit it all but the first one, and use ` ;` as separator.\n",
|
||||||
"If if both the subject and predicate are the same, we could use a coma `,` instead.\n",
|
"If both the subject and predicate are the same, we could use a coma `,` instead.\n",
|
||||||
"This allows us to avoid repetition and make queries more readable.\n",
|
"This allows us to avoid repetition and make queries more readable.\n",
|
||||||
"But don't forget the space before your separators (`;` and `.`).\n",
|
"But don't forget the space before your separators (`;` and `.`).\n",
|
||||||
"\n",
|
"\n",
|
||||||
"The result is interesting, we know he was born in Fuenlabrada, but we see an additional (wrong) value, the Spanish national football team. The conversion process from Wikipedia to DBPedia should still be tuned :).\n",
|
"The result is interesting, we know he was born in Fuenlabrada, but we see an additional (wrong) value, the Spanish national football team. The conversion process from Wikipedia to DBPedia should still be tuned :).\n",
|
||||||
"\n",
|
"\n",
|
||||||
"We can *fix* it, by adding some more constaints.\n",
|
"We can *fix* it by adding some more constraints.\n",
|
||||||
"In our case, only want a birthplace that is also a municipality (i.e., its type is `http://dbpedia.org/resource/Municipalities_of_Spain`).\n",
|
"In our case, only want a birthplace that is also a municipality (i.e., its type is `http://dbpedia.org/resource/Municipalities_of_Spain`).\n",
|
||||||
"Let's see!"
|
"Let's see!"
|
||||||
]
|
]
|
||||||
@@ -240,7 +240,7 @@
|
|||||||
"Great. Now it looks better.\n",
|
"Great. Now it looks better.\n",
|
||||||
"Notice that we added a new prefix.\n",
|
"Notice that we added a new prefix.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Now, is Fuenlabrada is a big city?\n",
|
"Now, is Fuenlabrada a big city?\n",
|
||||||
"Let's find out.\n",
|
"Let's find out.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"**Hint**: you can find more subject / object / predicate nodes related to [Fuenlabrada])http://dbpedia.org/resource/Fuenlabrada) in the RDF graph just as we did before.\n",
|
"**Hint**: you can find more subject / object / predicate nodes related to [Fuenlabrada])http://dbpedia.org/resource/Fuenlabrada) in the RDF graph just as we did before.\n",
|
||||||
@@ -269,10 +269,10 @@
|
|||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Well, it shows 39.1 km$^2$.\n",
|
"Well, it shows 39.41 km$^2$.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Let's go back to our Fernando Torres.\n",
|
"Let's go back to our Fernando Torres.\n",
|
||||||
"What we are really insterested in is the name of the city he was born in, not its IRI.\n",
|
"What we are really interested in is the name of the city he was born in, not its IRI.\n",
|
||||||
"As we saw before, the human-readable name is provided by the `rdfs:label` property:"
|
"As we saw before, the human-readable name is provided by the `rdfs:label` property:"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
157
lod/01_1_SPARQL_Server.ipynb
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"<header style=\"width:100%;position:relative\">\n",
|
||||||
|
" <div style=\"width:80%;float:right;\">\n",
|
||||||
|
" <h1>Course Notes for Learning Intelligent Systems</h1>\n",
|
||||||
|
" <h2>Department of Telematic Engineering Systems</h2>\n",
|
||||||
|
" <h3>Universidad Politécnica de Madrid. © Carlos A. Iglesias </h3>\n",
|
||||||
|
" </div>\n",
|
||||||
|
" <img style=\"width:15%;\" src=\"https://github.com/gsi-upm/sitc/blob/9844820e6653b0e169113a06538f8e54554c4fbc/images/EscUpmPolit_p.gif?raw=true\" alt=\"UPM\" />\n",
|
||||||
|
"</header>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Introduction\n",
|
||||||
|
"\n",
|
||||||
|
"This lecture explains how to run the SPARQL Server Fuseki using Docker."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# Installing Fuseki with Docker\n",
|
||||||
|
"This section is taken from [[1](#1), [2](#2)].\n",
|
||||||
|
"\n",
|
||||||
|
"## Install Docker if not installed\n",
|
||||||
|
"You should have installed **Docker**. If not, refer to the [docker install guide](https://docs.docker.com/engine/install/).\n",
|
||||||
|
"\n",
|
||||||
|
"## Install fuseki image\n",
|
||||||
|
"In a terminal, run\n",
|
||||||
|
"```\n",
|
||||||
|
"docker run -p 3030:3030 --name fuseki -e ADMIN_PASSWORD=fuseki -it stain/jena-fuseki\n",
|
||||||
|
"```\n",
|
||||||
|
"You can change the admin password to anyone that you want, or the ports.\n",
|
||||||
|
"\n",
|
||||||
|
"You should see the logs in the terminal.\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"## Access admin UI\n",
|
||||||
|
"Now open a browser to [http://localhost:3030](http://localhost:3030) and log in as user *admin* with password *fuseki* (or the password you set earlier).\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"## Load data\n",
|
||||||
|
"Download this dataset to your computer.\n",
|
||||||
|
"\n",
|
||||||
|
"[Beatles dataset](https://github.com/gsi-upm/sitc/blob/master/lod/BeatlesMusicians.ttl).\n",
|
||||||
|
"\n",
|
||||||
|
"At the bottom of the UI, you can see 'No datasets created - add one'. Click on *add one*. Set *beatles* as the dataset name and in-memory as the dataset type.\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"Click the *create dataset* button.\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"Click the *add data* button. In the new screen, select the button *select files* and click on the file you have previously downloaded, and click on the *upload now* button.\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"Now the *query* tab.\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"You see a generic query to list triples, click on the *Play* button (a triangle on the SPARQL query's right).\n",
|
||||||
|
"\n",
|
||||||
|
"Scroll down to see the query results.\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"Congratulations! You have a SPARQL server running, serving a dataset!!"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## References"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"* <a id=\"1\">[1]</a> [SPARQL by Example. A Tutorial. Lee Feigenbaum. W3C, 2009](https://hub.docker.com/r/stain/jena-fuseki)\n",
|
||||||
|
"* <a id=\"2\">[2]</a> [SPARQL queries of Beatles recording sessions](http://www.snee.com/bobdc.blog/2017/11/sparql-queries-of-beatles-reco.html)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Licence\n",
|
||||||
|
"The notebook is freely licensed under the [Creative Commons Attribution Share-Alike license](https://creativecommons.org/licenses/by/2.0/). \n",
|
||||||
|
"\n",
|
||||||
|
"© Carlos A. Iglesias, Universidad Politécnica de Madrid."
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"datacleaner": {
|
||||||
|
"position": {
|
||||||
|
"top": "50px"
|
||||||
|
},
|
||||||
|
"python": {
|
||||||
|
"varRefreshCmd": "try:\n print(_datacleaner.dataframe_metadata())\nexcept:\n print([])"
|
||||||
|
},
|
||||||
|
"window_display": false
|
||||||
|
},
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3 (ipykernel)",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.12.2"
|
||||||
|
},
|
||||||
|
"latex_envs": {
|
||||||
|
"LaTeX_envs_menu_present": true,
|
||||||
|
"autocomplete": true,
|
||||||
|
"bibliofile": "biblio.bib",
|
||||||
|
"cite_by": "apalike",
|
||||||
|
"current_citInitial": 1,
|
||||||
|
"eqLabelWithNumbers": true,
|
||||||
|
"eqNumInitial": 1,
|
||||||
|
"hotkeys": {
|
||||||
|
"equation": "Ctrl-E",
|
||||||
|
"itemize": "Ctrl-I"
|
||||||
|
},
|
||||||
|
"labels_anchors": false,
|
||||||
|
"latex_user_defs": false,
|
||||||
|
"report_style_numbering": false,
|
||||||
|
"user_envs_cfg": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 4
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
"editable": false,
|
"editable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"checksum": "7276f055a8c504d3c80098c62ed41a4f",
|
"checksum": "91ddca8e4ff354f86a8bdbfee755a886",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-0bfe38f97f6ab2d2",
|
"grade_id": "cell-0bfe38f97f6ab2d2",
|
||||||
"locked": true,
|
"locked": true,
|
||||||
@@ -19,10 +19,10 @@
|
|||||||
"<header style=\"width:100%;position:relative\">\n",
|
"<header style=\"width:100%;position:relative\">\n",
|
||||||
" <div style=\"width:80%;float:right;\">\n",
|
" <div style=\"width:80%;float:right;\">\n",
|
||||||
" <h1>Course Notes for Learning Intelligent Systems</h1>\n",
|
" <h1>Course Notes for Learning Intelligent Systems</h1>\n",
|
||||||
" <h3>Department of Telematic Engineering Systems</h3>\n",
|
" <h2>Department of Telematic Engineering Systems</h2>\n",
|
||||||
" <h5>Universidad Politécnica de Madrid</h5>\n",
|
" <h3>Universidad Politécnica de Madrid</h3>\n",
|
||||||
" </div>\n",
|
" </div>\n",
|
||||||
" <img style=\"width:15%;\" src=\"../logo.jpg\" alt=\"UPM\" />\n",
|
" <img style=\"width:15%;\" src=\"https://github.com/gsi-upm/sitc/blob/9844820e6653b0e169113a06538f8e54554c4fbc/images/EscUpmPolit_p.gif?raw=true\" alt=\"UPM\" />\n",
|
||||||
"</header>"
|
"</header>"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
"editable": false,
|
"editable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"checksum": "40ccd05ad0704781327031a84dfb9939",
|
"checksum": "5760eec341771cfd3ebd91627da0a481",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-4f8492996e74bf20",
|
"grade_id": "cell-4f8492996e74bf20",
|
||||||
"locked": true,
|
"locked": true,
|
||||||
@@ -71,10 +71,10 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"* This notebook\n",
|
"* This notebook\n",
|
||||||
"* External SPARQL editors (optional)\n",
|
"* External SPARQL editors (optional)\n",
|
||||||
" * YASGUI-GSI http://yasgui.gsi.upm.es\n",
|
" * *YASGUI* https://yasgui.org/\n",
|
||||||
" * DBpedia virtuoso http://dbpedia.org/sparql\n",
|
" * *DBpedia Virtuoso* http://dbpedia.org/sparql\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Using the YASGUI-GSI editor has several advantages over other options.\n",
|
"Using the YASGUI editor has several advantages over other options.\n",
|
||||||
"It features:\n",
|
"It features:\n",
|
||||||
"\n",
|
"\n",
|
||||||
"* Selection of data source, either by specifying the URL or by selecting from a dropdown menu\n",
|
"* Selection of data source, either by specifying the URL or by selecting from a dropdown menu\n",
|
||||||
@@ -96,7 +96,7 @@
|
|||||||
"editable": false,
|
"editable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"checksum": "81894e9d65e5dd9f3b6e1c5f66804bf6",
|
"checksum": "b1285fb82e4438a22e05ff134d1e080d",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-70ac24910356c3cf",
|
"grade_id": "cell-70ac24910356c3cf",
|
||||||
"locked": true,
|
"locked": true,
|
||||||
@@ -107,13 +107,15 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## Instructions\n",
|
"## Instructions\n",
|
||||||
"\n",
|
"\n",
|
||||||
"We will be using a semantic server, available at: http://fuseki.gsi.upm.es/sitc.\n",
|
"We will use an available semantic server. There are two possible settings:\n",
|
||||||
|
"* A local server available at [http://fuseki.gsi.upm.es/sitc]( http://fuseki.gsi.upm.es/sitc/)\n",
|
||||||
|
"* Install the SPARQL server yourself and run it locally. To do this, follow the instructions in the notebook [how to install a SPARQL Server](01_1_SPARQL_Server.ipynb). In this case, your server is available at [http://localhost:3030](http://localhost:3030).\n",
|
||||||
"\n",
|
"\n",
|
||||||
"This server contains a dataset about [Beatles songs](http://www.snee.com/bobdc.blog/2017/11/sparql-queries-of-beatles-reco.html), which we will query with SPARQL.\n",
|
"This server contains a dataset about [Beatles songs](http://www.snee.com/bobdc.blog/2017/11/sparql-queries-of-beatles-reco.html), which we will query with SPARQL.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"We will provide you some example code to get you started, the *question* you will have to answer using SPARQL, a template for the answer.\n",
|
"We will provide you with some example code to get you started, along with the *question* you will have to answer using SPARQL and a template for the answer.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"After every query, you will find some python code to test the results of the query.\n",
|
"After every query, you will find some Python code to test the results of the query.\n",
|
||||||
"**Make sure you've run the tests before moving to the next exercise**.\n",
|
"**Make sure you've run the tests before moving to the next exercise**.\n",
|
||||||
"If the test gives you an error, you've probably done something wrong.\n",
|
"If the test gives you an error, you've probably done something wrong.\n",
|
||||||
"You do not need to understand or modify the test code."
|
"You do not need to understand or modify the test code."
|
||||||
@@ -126,7 +128,7 @@
|
|||||||
"editable": false,
|
"editable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"checksum": "1d332d3d11fd6b57f0ec0ac3c358c6cb",
|
"checksum": "a5918241a0b402cb091a85d245aaa3fd",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-eb13908482825e42",
|
"grade_id": "cell-eb13908482825e42",
|
||||||
"locked": true,
|
"locked": true,
|
||||||
@@ -138,7 +140,7 @@
|
|||||||
"For convenience, the examples in the notebook are executable (using the `%%sparql` magic command), and they are accompanied by some code to test the results.\n",
|
"For convenience, the examples in the notebook are executable (using the `%%sparql` magic command), and they are accompanied by some code to test the results.\n",
|
||||||
"If the tests pass, you probably got the answer right.\n",
|
"If the tests pass, you probably got the answer right.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"**Run this line to enable the `%%sparql` magic command.**"
|
"### Run this line to enable the `%%sparql` magic command.**"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -200,7 +202,7 @@
|
|||||||
"editable": false,
|
"editable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"checksum": "34710d3bb8e2cf826833a43adb7fb448",
|
"checksum": "77cd823ca5a1556311f3dcf7e1533bce",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-2a44c0da2c206d01",
|
"grade_id": "cell-2a44c0da2c206d01",
|
||||||
"locked": true,
|
"locked": true,
|
||||||
@@ -216,10 +218,23 @@
|
|||||||
"In addition to running queries from your browser, they provide useful features such as syntax highlighting and autocompletion.\n",
|
"In addition to running queries from your browser, they provide useful features such as syntax highlighting and autocompletion.\n",
|
||||||
"Some examples are:\n",
|
"Some examples are:\n",
|
||||||
"\n",
|
"\n",
|
||||||
"* DBpedia's virtuoso query editor https://dbpedia.org/sparql\n",
|
"* DBpedia's Virtuoso query editor https://dbpedia.org/sparql\n",
|
||||||
"* A javascript based client hosted at GSI: http://yasgui.gsi.upm.es/\n",
|
"* A JavaScript-based client: https://yasgui.org/\n",
|
||||||
"\n",
|
"\n",
|
||||||
"[^1]: http://www.snee.com/bobdc.blog/2017/11/sparql-queries-of-beatles-reco.html"
|
"[^1]: http://www.snee.com/bobdc.blog/2017/11/sparql-queries-of-beatles-reco.html\n",
|
||||||
|
"\n",
|
||||||
|
"### Set your SPARQL server"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"## Set your Fuseki server URL\n",
|
||||||
|
"\n",
|
||||||
|
"fuseki = 'http://localhost:3030/beatles/sparql'"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -250,7 +265,7 @@
|
|||||||
"editable": false,
|
"editable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"checksum": "f7428fe79cd33383dfd3b09a0d951b6e",
|
"checksum": "1d6bd8b03621fb0b2d74c80b91e9b91a",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-8391a5322a9ad4a7",
|
"grade_id": "cell-8391a5322a9ad4a7",
|
||||||
"locked": true,
|
"locked": true,
|
||||||
@@ -259,7 +274,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"source": [
|
"source": [
|
||||||
"#### First select - Exploring the dataset\n",
|
"### First select - Exploring the dataset\n",
|
||||||
"\n"
|
"\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -324,7 +339,7 @@
|
|||||||
"editable": false,
|
"editable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "3bc71f851a33fa401d18ea3ab02cf61f",
|
"checksum": "3b3a78b2676844ff59d3555a5f7690a0",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-8ce8c954513f17e7",
|
"grade_id": "cell-8ce8c954513f17e7",
|
||||||
"locked": true,
|
"locked": true,
|
||||||
@@ -334,7 +349,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"SELECT ?entity ?type\n",
|
"SELECT ?entity ?type\n",
|
||||||
"WHERE {\n",
|
"WHERE {\n",
|
||||||
@@ -388,7 +403,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "65be7168bedb4f6dc2f19e2138bab232",
|
"checksum": "1879bf78f30a1ec22499eec5f975803d",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-6e904d692b5facad",
|
"grade_id": "cell-6e904d692b5facad",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -398,7 +413,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"SELECT ?entity ?prop\n",
|
"SELECT ?entity ?prop\n",
|
||||||
"WHERE {\n",
|
"WHERE {\n",
|
||||||
@@ -454,7 +469,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"SELECT ?type\n",
|
"SELECT ?type\n",
|
||||||
"WHERE {\n",
|
"WHERE {\n",
|
||||||
@@ -479,7 +494,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"SELECT DISTINCT ?type\n",
|
"SELECT DISTINCT ?type\n",
|
||||||
"WHERE {\n",
|
"WHERE {\n",
|
||||||
@@ -522,7 +537,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "35563ff455c7e8b1c91f61db97b2011b",
|
"checksum": "73cbbe78a138e5f927f18155106c0761",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-e615f9a77c4bc9a5",
|
"grade_id": "cell-e615f9a77c4bc9a5",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -532,7 +547,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"SELECT DISTINCT ?property\n",
|
"SELECT DISTINCT ?property\n",
|
||||||
"WHERE {\n",
|
"WHERE {\n",
|
||||||
@@ -585,7 +600,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
||||||
@@ -655,7 +670,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "069811507dbac4b86dc5d3adc82ba4ec",
|
"checksum": "79d1ab4722a04ee11b1f892cd4434510",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-0223a51f609edcf9",
|
"grade_id": "cell-0223a51f609edcf9",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -665,7 +680,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
||||||
@@ -725,7 +740,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "b68a279085a1ed087f5e474a6602299e",
|
"checksum": "47ad334640472eeec3d52ee87035fc60",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-8f43547dd788bb33",
|
"grade_id": "cell-8f43547dd788bb33",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -735,7 +750,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
||||||
@@ -812,7 +827,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "335403f01e484ce5563ff059e9764ff4",
|
"checksum": "ac6cb33399d7efab311bd58479a75929",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-a0f0b9d9b05c9631",
|
"grade_id": "cell-a0f0b9d9b05c9631",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -822,7 +837,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
||||||
@@ -891,7 +906,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "8fb253675d2e8510e2c6780b960721e5",
|
"checksum": "d2ed010ea9127e45edc81b2c1a8c94d9",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-523b963fa4e288d0",
|
"grade_id": "cell-523b963fa4e288d0",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -901,7 +916,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
||||||
@@ -971,7 +986,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "c7b6620f5ba28b482197ab693cb7142a",
|
"checksum": "390eea10127829419f4026f292d907ad",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-e89d08031e30b299",
|
"grade_id": "cell-e89d08031e30b299",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -981,7 +996,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX m: <http://learningsparql.com/ns/musician/>\n",
|
"PREFIX m: <http://learningsparql.com/ns/musician/>\n",
|
||||||
@@ -1039,7 +1054,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"Once results are grouped, they can be aggregated using any aggregation function, such as `COUNT`.\n",
|
"Once results are grouped, they can be aggregated using any aggregation function, such as `COUNT`.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Using `GROUP BY` and `COUNT`, get the count of songs in which Ringo Starr has played each of the instruments:"
|
"Using `GROUP BY` and `COUNT`, get the count of songs that use each instrument:"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1049,7 +1064,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "7556bacb20c1fbd059dec165c982908d",
|
"checksum": "899b2cf4ee7d010e5e5d02ca28ead13d",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-1429e4eb5400dbc7",
|
"grade_id": "cell-1429e4eb5400dbc7",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -1059,7 +1074,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX m: <http://learningsparql.com/ns/musician/>\n",
|
"PREFIX m: <http://learningsparql.com/ns/musician/>\n",
|
||||||
@@ -1123,7 +1138,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
||||||
@@ -1156,7 +1171,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "3139d9b7e620266946ffe1ae0cf67581",
|
"checksum": "24f94cc322288f4c467af5bfadd6a4c9",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-ee208c762d00da9c",
|
"grade_id": "cell-ee208c762d00da9c",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -1166,7 +1181,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n",
|
||||||
@@ -1228,7 +1243,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX i: <http://learningsparql.com/ns/instrument/>\n",
|
"PREFIX i: <http://learningsparql.com/ns/instrument/>\n",
|
||||||
@@ -1263,7 +1278,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX i: <http://learningsparql.com/ns/instrument/>\n",
|
"PREFIX i: <http://learningsparql.com/ns/instrument/>\n",
|
||||||
@@ -1297,7 +1312,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "3bc508872193750d57d07efbf334c212",
|
"checksum": "513916421ec8451b8a10a6923fde775b",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-dcd68c45c1608a28",
|
"grade_id": "cell-dcd68c45c1608a28",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -1307,7 +1322,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX i: <http://learningsparql.com/ns/instrument/>\n",
|
"PREFIX i: <http://learningsparql.com/ns/instrument/>\n",
|
||||||
@@ -1381,7 +1396,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "300df0a3cf9729dd4814b3153b2fedb4",
|
"checksum": "7b6c7de8beb6cd78b99fbc8eaa1b2c87",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-0c7cc924a13d792a",
|
"grade_id": "cell-0c7cc924a13d792a",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -1391,7 +1406,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX i: <http://learningsparql.com/ns/instrument/>\n",
|
"PREFIX i: <http://learningsparql.com/ns/instrument/>\n",
|
||||||
@@ -1456,7 +1471,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "e4e898c8a16b8aa5865dfde2f6e68ec6",
|
"checksum": "f4b8b1601e9cd1c05464ebad8e6836a6",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-d750b6d64c6aa0a7",
|
"grade_id": "cell-d750b6d64c6aa0a7",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -1466,7 +1481,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
@@ -1521,7 +1536,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "fade6ab714376e0eabfa595dd6bd6a8b",
|
"checksum": "b3a570ae42656d907a1ce60f199fdbec",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-2f5aa516f8191787",
|
"grade_id": "cell-2f5aa516f8191787",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -1531,7 +1546,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
@@ -1577,7 +1592,7 @@
|
|||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"### Which songs had Ringo in drums OR Lennon in lead vocals? (UNION)"
|
"### Which songs had Ringo in dums OR Lennon in lead vocals? (UNION)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1612,7 +1627,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "09262d81449c498c37e4b9d9b1dcdfed",
|
"checksum": "4c1d0eaf45f7e69233bb998f5dfb9a48",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-d3a742bd87d9c793",
|
"grade_id": "cell-d3a742bd87d9c793",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -1622,7 +1637,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
@@ -1643,7 +1658,7 @@
|
|||||||
"editable": false,
|
"editable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "11061e79ec06ccb3a9c496319a528366",
|
"checksum": "d583b30a1e00960df3a4411b6854c8c8",
|
||||||
"grade": true,
|
"grade": true,
|
||||||
"grade_id": "cell-409402df0e801d09",
|
"grade_id": "cell-409402df0e801d09",
|
||||||
"locked": true,
|
"locked": true,
|
||||||
@@ -1654,7 +1669,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"assert len(solution()['tuples']) == 209"
|
"assert len(solution()['tuples']) == 246"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1695,7 +1710,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "9ddd2d1f50f841b889bfd29b175d06da",
|
"checksum": "161fd1c6ed06206d4661e4e6c3e255c7",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-9d1ec854eb530235",
|
"grade_id": "cell-9d1ec854eb530235",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -1705,7 +1720,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"\n",
|
"\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -1789,7 +1804,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "d18e8b6e1d32aed395a533febb29fcb5",
|
"checksum": "16d79b02f510bbfffcb2cc36af159081",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-7ea1f5154cdd8324",
|
"grade_id": "cell-7ea1f5154cdd8324",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -1799,7 +1814,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX i: <http://learningsparql.com/ns/instrument/>\n",
|
"PREFIX i: <http://learningsparql.com/ns/instrument/>\n",
|
||||||
@@ -1836,7 +1851,7 @@
|
|||||||
"deletable": false,
|
"deletable": false,
|
||||||
"nbgrader": {
|
"nbgrader": {
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"checksum": "f926fa3a3568d122454a12312859cda1",
|
"checksum": "65cece835581895b44257668948a5130",
|
||||||
"grade": false,
|
"grade": false,
|
||||||
"grade_id": "cell-b6bee887a1b1fc60",
|
"grade_id": "cell-b6bee887a1b1fc60",
|
||||||
"locked": false,
|
"locked": false,
|
||||||
@@ -1846,7 +1861,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"%%sparql http://fuseki.gsi.upm.es/sitc/\n",
|
"%%sparql $fuseki\n",
|
||||||
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n",
|
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n",
|
||||||
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
"PREFIX s: <http://learningsparql.com/ns/schema/>\n",
|
||||||
"PREFIX i: <http://learningsparql.com/ns/instrument/>\n",
|
"PREFIX i: <http://learningsparql.com/ns/instrument/>\n",
|
||||||
@@ -1898,7 +1913,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.8.10"
|
"version": "3.12.2"
|
||||||
},
|
},
|
||||||
"toc": {
|
"toc": {
|
||||||
"base_numbering": 1,
|
"base_numbering": 1,
|
||||||
|
|||||||
BIN
lod/created-dataset.jpg
Normal file
|
After Width: | Height: | Size: 111 KiB |
BIN
lod/docker-run-jena-fuseki.jpg
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
lod/fuseki-running.jpg
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
lod/new-dataset.jpg
Normal file
|
After Width: | Height: | Size: 93 KiB |
BIN
lod/query-results.jpg
Normal file
|
After Width: | Height: | Size: 92 KiB |
BIN
lod/query-ui.jpg
Normal file
|
After Width: | Height: | Size: 95 KiB |
BIN
lod/upload-data.jpg
Normal file
|
After Width: | Height: | Size: 91 KiB |
@@ -330,7 +330,7 @@
|
|||||||
"# Saving the resulting axes as ax each time causes the resulting plot to be shown\n",
|
"# Saving the resulting axes as ax each time causes the resulting plot to be shown\n",
|
||||||
"# on top of the previous axes\n",
|
"# on top of the previous axes\n",
|
||||||
"ax = sns.boxplot(x=\"species\", y=\"petal length (cm)\", data=iris_df)\n",
|
"ax = sns.boxplot(x=\"species\", y=\"petal length (cm)\", data=iris_df)\n",
|
||||||
"ax = sns.stripplot(x=\"species\", y=\"petal length (cm)\", data=iris_df, jitter=True, edgecolor=\"gray\")"
|
"ax = sns.stripplot(x=\"species\", y=\"petal length (cm)\", data=iris_df, jitter=True, edgecolor=\"auto\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -348,7 +348,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"# A violin plot combines the benefits of the previous two plots and simplifies them\n",
|
"# A violin plot combines the benefits of the previous two plots and simplifies them\n",
|
||||||
"# Denser regions of the data are fatter, and sparser thinner in a violin plot\n",
|
"# Denser regions of the data are fatter, and sparser thinner in a violin plot\n",
|
||||||
"sns.violinplot(x=\"species\", y=\"petal length (cm)\", data=iris_df, size=6)"
|
"sns.violinplot(x=\"species\", y=\"petal length (cm)\", data=iris_df)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
"Machine learning algorithms are programs that learn a model from a dataset to make predictions or learn structures to organize the data.\n",
|
"Machine learning algorithms are programs that learn a model from a dataset to make predictions or learn structures to organize the data.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"In scikit-learn, machine learning algorithms take as input a *numpy* array (n_samples, n_features), where\n",
|
"In scikit-learn, machine learning algorithms take as input a *numpy* array (n_samples, n_features), where\n",
|
||||||
"* **n_samples**: number of samples. Each sample is an item to process (i.e., classify). A sample can be a document, a picture, a sound, a video, a row in a database or CSV file, or whatever you can describe with a fixed set of quantitative traits.\n",
|
"* **n_samples**: number of samples. Each sample is an item to be processed (i.e., classified). A sample can be a document, a picture, a sound, a video, a row in a database or CSV file, or whatever you can describe with a fixed set of quantitative traits.\n",
|
||||||
"* **n_features**: The number of features or distinct traits that can be used to describe each item quantitatively.\n",
|
"* **n_features**: The number of features or distinct traits that can be used to describe each item quantitatively.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"The number of features should be defined in advance. A specific type of feature set is high-dimensional (e.g., millions of features), but most values are zero for a given sample. Using (numpy) arrays, all those zero values would also take up memory. For this reason, these feature sets are often represented with sparse matrices (scipy.sparse) instead of (numpy) arrays.\n",
|
"The number of features should be defined in advance. A specific type of feature set is high-dimensional (e.g., millions of features), but most values are zero for a given sample. Using (numpy) arrays, all those zero values would also take up memory. For this reason, these feature sets are often represented with sparse matrices (scipy.sparse) instead of (numpy) arrays.\n",
|
||||||
@@ -112,7 +112,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"In *unsupervised machine learning models*, the machine learning model algorithm takes as input the feature vectors. It produces a predictive model that is used to fit its parameters to summarize the best regularities found in the data.\n",
|
"In *unsupervised machine learning models*, the machine learning model algorithm takes as input the feature vectors. It produces a predictive model that is used to fit its parameters to summarize the best regularities found in the data.\n",
|
||||||
""
|
""
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -140,7 +140,7 @@
|
|||||||
" * **model.fit_transform()**: Some estimators implement this method, which performs a fit and a transform on the same input data.\n",
|
" * **model.fit_transform()**: Some estimators implement this method, which performs a fit and a transform on the same input data.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
""
|
""
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,10 +53,10 @@ import matplotlib.pyplot as plt
|
|||||||
|
|
||||||
from sklearn.datasets import load_iris
|
from sklearn.datasets import load_iris
|
||||||
from sklearn.tree import DecisionTreeClassifier
|
from sklearn.tree import DecisionTreeClassifier
|
||||||
|
from sklearn.inspection import DecisionBoundaryDisplay
|
||||||
|
|
||||||
def plot_tree_iris():
|
def plot_tree_iris():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Taken fromhttp://scikit-learn.org/stable/auto_examples/tree/plot_iris.html
|
Taken fromhttp://scikit-learn.org/stable/auto_examples/tree/plot_iris.html
|
||||||
"""
|
"""
|
||||||
# Parameters
|
# Parameters
|
||||||
@@ -67,11 +67,11 @@ def plot_tree_iris():
|
|||||||
# Load data
|
# Load data
|
||||||
iris = load_iris()
|
iris = load_iris()
|
||||||
|
|
||||||
for pairidx, pair in enumerate([[0, 1], [0, 2], [0, 3],
|
for pairidx, pair in enumerate([[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]]):
|
||||||
[1, 2], [1, 3], [2, 3]]):
|
|
||||||
# We only take the two corresponding features
|
# We only take the two corresponding features
|
||||||
X = iris.data[:, pair]
|
X = iris.data[:, pair]
|
||||||
y = iris.target
|
y = iris.target
|
||||||
|
'''
|
||||||
|
|
||||||
# Shuffle
|
# Shuffle
|
||||||
idx = np.arange(X.shape[0])
|
idx = np.arange(X.shape[0])
|
||||||
@@ -84,34 +84,38 @@ def plot_tree_iris():
|
|||||||
mean = X.mean(axis=0)
|
mean = X.mean(axis=0)
|
||||||
std = X.std(axis=0)
|
std = X.std(axis=0)
|
||||||
X = (X - mean) / std
|
X = (X - mean) / std
|
||||||
|
'''
|
||||||
# Train
|
# Train
|
||||||
model = DecisionTreeClassifier(max_depth=3, random_state=1).fit(X, y)
|
clf = DecisionTreeClassifier(max_depth=3, random_state=1).fit(X, y)
|
||||||
|
|
||||||
# Plot the decision boundary
|
# Plot the decision boundary
|
||||||
plt.subplot(2, 3, pairidx + 1)
|
# Taken from https://scikit-learn.org/stable/auto_examples/tree/plot_iris_dtc.html
|
||||||
|
# Plot the decision boundary
|
||||||
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
|
ax = plt.subplot(2, 3, pairidx + 1)
|
||||||
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
|
plt.tight_layout(h_pad=0.5, w_pad=0.5, pad=2.5)
|
||||||
xx, yy = np.meshgrid(np.arange(x_min, x_max, plot_step),
|
DecisionBoundaryDisplay.from_estimator(
|
||||||
np.arange(y_min, y_max, plot_step))
|
clf,
|
||||||
|
X,
|
||||||
Z = model.predict(np.c_[xx.ravel(), yy.ravel()])
|
cmap=plt.cm.RdYlBu,
|
||||||
Z = Z.reshape(xx.shape)
|
response_method="predict",
|
||||||
cs = plt.contourf(xx, yy, Z, cmap=plt.cm.Paired)
|
ax=ax,
|
||||||
|
xlabel=iris.feature_names[pair[0]],
|
||||||
plt.xlabel(iris.feature_names[pair[0]])
|
ylabel=iris.feature_names[pair[1]],
|
||||||
plt.ylabel(iris.feature_names[pair[1]])
|
)
|
||||||
plt.axis("tight")
|
|
||||||
|
|
||||||
# Plot the training points
|
# Plot the training points
|
||||||
for i, color in zip(range(n_classes), plot_colors):
|
for i, color in zip(range(n_classes), plot_colors):
|
||||||
idx = np.where(y == i)
|
idx = np.asarray(y == i).nonzero()
|
||||||
plt.scatter(X[idx, 0], X[idx, 1], c=color, label=iris.target_names[i],
|
plt.scatter(
|
||||||
cmap=plt.cm.Paired)
|
X[idx, 0],
|
||||||
|
X[idx, 1],
|
||||||
|
c=color,
|
||||||
|
label=iris.target_names[i],
|
||||||
|
edgecolor="black",
|
||||||
|
s=15
|
||||||
|
)
|
||||||
plt.axis("tight")
|
plt.axis("tight")
|
||||||
|
|
||||||
plt.suptitle("Decision surface of a decision tree using paired features")
|
plt.suptitle("Decision surface of a decision tree using paired features")
|
||||||
plt.legend()
|
#plt.legend()
|
||||||
|
plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|||||||