## Introduction into SPARQL
---
### SPARQL: Protocol and RDF Query Language
so what is RDF?
----
### RDF: Resource Description Framework
It is based upon the idea of making statements about resources [...] in the form of subject–predicate–object expressions, known as triples.
<img src="https://upload.wikimedia.org/wikipedia/commons/3/3d/Erd-entity-relationship-example1.svg" alt="subject–predicate–object" />
----
For example, one way to represent the notion "The sky has the color blue" in RDF is as the triple: a subject denoting "the sky", a predicate denoting "has the color", and an object denoting "blue".
---
<pre>
@prefix eric: <http://www.w3.org/People/EM/contact#> .
@prefix contact: <http://www.w3.org/2000/10/swap/pim/contact#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
eric:me contact:fullName "Eric Miller" .
eric:me contact:mailbox <mailto:e.miller123(at)example> .
eric:me contact:personalTitle "Dr." .
eric:me rdf:type contact:Person .
</pre>
----
<img src="https://upload.wikimedia.org/wikipedia/commons/7/72/ER_Diagram_MMORPG.png" />
---
### SPARQL: Queries
a query language like SQL.
----
### Fruit
```sparql=
SELECT ?fruit
WHERE
{
?fruit hasColor yellow.
?fruit tastes sour.
}
```
----
### Cats
The following query uses these:
Items: <a href="https://www.wikidata.org/wiki/Special:EntityPage/Q146">cat (Q146)</a>
Properties: <a href="https://www.wikidata.org/wiki/Special:EntityPage/P31">instance of (P31)</a>
```sparql=
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P31 wd:Q146.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
```
<a href="https://query.wikidata.org/#SELECT%20%3Fitem%20%3FitemLabel%20%0AWHERE%20%0A%7B%0A%20%20%3Fitem%20wdt%3AP31%20wd%3AQ146.%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D">try it</a>
---
- Help: https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/Wikidata_Query_Help
- Examples: https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples or https://query.wikidata.org
- Find properties: https://www.wikidata.org/wiki/Wikidata:List_of_properties
{"metaMigratedAt":"2023-06-14T14:29:04.584Z","metaMigratedFrom":"YAML","title":"Introduction into SPARQL","breaks":"true","slideOptions":"{\"theme\":\"moon\"}","contributors":"[]"}