1
0
mirror of https://github.com/gsi-upm/sitc synced 2026-02-19 12:48:16 +00:00

Update 00_SPARQL_Tutorial.ipynb

This commit is contained in:
Carlos A. Iglesias
2026-02-18 11:56:45 +01:00
committed by GitHub
parent ce2d08ebc3
commit 08d2621a98

View File

@@ -34,7 +34,7 @@
"* 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",
"* [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."
]
},
@@ -51,8 +51,8 @@
" \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",
"In RDF this relationship is known as a **property**.\n",
"Because RDF statements consist of three elements they are called **triples**.\n",
"In RDF, this relationship is known as a **property**.\n",
"Because RDF statements consist of three elements, they are called **triples**.\n",
"\n",
"Here are some examples of RDF triples (informally expressed in pseudocode):\n",
"\n",
@@ -97,7 +97,7 @@
"\n",
"To use the library, you need to:\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",
"\n",
"Let's try it!\n",
@@ -137,7 +137,7 @@
"cell_type": "markdown",
"metadata": {},
"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",
"\n",
"To do so, we will search for entities whose English \"human-readable representation\" (i.e., label) matches \"Fernando Torres\":"
@@ -166,7 +166,7 @@
"\n",
"Now we can start asking for more properties.\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",
"Let's go!"
]
@@ -202,13 +202,13 @@
"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",
"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",
"But don't forget the space before your separators (`;` and `.`).\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",
"\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",
"Let's see!"
]
@@ -240,7 +240,7 @@
"Great. Now it looks better.\n",
"Notice that we added a new prefix.\n",
"\n",
"Now, is Fuenlabrada is a big city?\n",
"Now, is Fuenlabrada a big city?\n",
"Let's find out.\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",
@@ -269,10 +269,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Well, it shows 39.1 km$^2$.\n",
"Well, it shows 39.41 km$^2$.\n",
"\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:"
]
},