Recupero dei dati collegati ai valori
So far the values we retrieved in our queries were directly related to the item we were selecting. Suppose we wanted to show the birthplace of the director of each of the Star Wars films.
#Star Wars films SELECT ?item ?itemLabel ?directorLabel ?pobLabel WHERE { ?item wdt:P179 wd:Q22092344. # item is part of the series Star Wars (film series) ?item wdt:P57 ?director. # item’s director property’s value is collected by the director variable ?director wdt:P19 ?pob. # the place of birth of the director is collected in the ?pob variable SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". } }
The query selects items that are part of the star wars series, and retrieves each film’s director, and the director’s P19 (place of birth) property and its value.
Importantly, P19 and its value are linked to the director – not to the film! We are retrieving the value (the place of birth) of a property (P19) of a value (the director) of a property (P57) of the item that we are selecting.
Here is a graph view of the data for the film Star Wars Episode V: The Empire Strikes Back (Q181795):
Item Q181795 is the subject (shown in blue) in the Item-Property-Value statement:
Q181795 – P57 (director) – Q119348 (Irvin Kershner).
Item Q119348 is the value or object (shown in green) of the director property (shown in black).
Item Q119348 is also the subject of the statement:
Q119348 – P19 (place of birth) – Q1345 (Philadelphia)
Now run the query:
# A little bit of syntax
A shorter way of formulating the above query is using square brackets to join the two match patterns on lines 7 and 8. So instead of:
?item wdt:P57 ?director.
?director wdt:P19 ?dob.
We write:
?item wdt:P57 [wdt:P19 ?dob].
What has changed in the results? Why?
This syntax omits the ?director variable, so ?directorLabel is empty.