{"id":684,"date":"2020-01-21T14:22:10","date_gmt":"2020-01-21T14:22:10","guid":{"rendered":"http:\/\/wikidata.wwwnlsrc4.supercp.com\/?p=684"},"modified":"2020-11-24T15:03:39","modified_gmt":"2020-11-24T15:03:39","slug":"retrieving-data-linked-to-values","status":"publish","type":"post","link":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/simple-queries\/data-linked-to-values\/retrieving-data-linked-to-values\/","title":{"rendered":"Retrieving data linked to values"},"content":{"rendered":"\n<h2>Retrieving data linked to values<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror cm-s-eclipse\" data-setting=\"{&quot;mode&quot;:&quot;sparql&quot;,&quot;mime&quot;:&quot;application\/sparql-query&quot;,&quot;theme&quot;:&quot;eclipse&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true}\">#Star Wars films\n\nSELECT ?item  ?itemLabel ?directorLabel ?pobLabel\nWHERE \n{ \n  ?item wdt:P179 wd:Q22092344. # item is part of the series Star Wars (film series)\n  ?item wdt:P57 ?director.     # item\u2019s director property\u2019s value is collected by the director variable\n  ?director wdt:P19 ?pob.      # the place of birth of the director is collected in the ?pob variable\n SERVICE wikibase:label { bd:serviceParam wikibase:language &quot;[AUTO_LANGUAGE]&quot;. }\n}<\/pre><\/div>\n\n\n\n<p>The query selects items that are part of the star wars series, and retrieves each film\u2019s director, and the director\u2019s P19 (place of birth) property and its value.<\/p>\n\n\n\n<p><strong>Importantly, P19 and its value are linked to the director \u2013 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<\/strong>.<\/p>\n\n\n\n<p>Here is a graph view of the data for the film Star Wars Episode V: The Empire Strikes Back (Q181795):<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" width=\"523\" height=\"267\" src=\"https:\/\/wdqs-tutorial.toolforge.org\/wp-content\/uploads\/2020\/01\/diagram2-2.png\" alt=\"\" class=\"wp-image-760\" srcset=\"https:\/\/wdqs-tutorial.toolforge.org\/wp-content\/uploads\/2020\/01\/diagram2-2.png 523w, https:\/\/wdqs-tutorial.toolforge.org\/wp-content\/uploads\/2020\/01\/diagram2-2-300x153.png 300w\" sizes=\"(max-width: 523px) 100vw, 523px\" \/><figcaption>  A graph view showing Q119348 (Irving Kershner) as both the object (Value) of the statement regarding the director property of Q181795, and the subject (Item) of the statement regarding the place of birth property.  <\/figcaption><\/figure><\/div>\n\n\n\n<p>Item Q181795 is the subject (shown in blue) in the Item-Property-Value statement:<br>Q181795 \u2013 P57 (director) \u2013 Q119348 (Irvin Kershner).<br>Item Q119348 is the value or object (shown in green) of the director property (shown in black).<br><br>Item Q119348 is also the subject of the statement:<br>Q119348 \u2013 P19 (place of birth) \u2013 Q1345 (Philadelphia)<\/p>\n\n\n\n<p>Now run the query:<\/p>\n\n\n\n<iframe class=\"\" src=\"https:\/\/query.wikidata.org\/#%23Star%20Wars%20films%0A%0ASELECT%20%3Fitem%20%20%3FitemLabel%20%3FdirectorLabel%20%3FpobLabel%0AWHERE%20%0A%7B%20%0A%20%20%3Fitem%20wdt%3AP179%20wd%3AQ22092344.%20%23%20item%20is%20part%20of%20the%20series%20Star%20Wars%20%28film%20series%29%0A%20%20%3Fitem%20wdt%3AP57%20%3Fdirector.%20%20%20%20%20%23%20item%E2%80%99s%20director%20property%E2%80%99s%20value%20is%20collected%20by%20the%20director%20variable%0A%20%20%3Fdirector%20wdt%3AP19%20%3Fpob.%20%20%20%20%20%20%23%20the%20place%20of%20birth%20of%20the%20director%20is%20collected%20in%20the%20%3Fpob%20variable%0A%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%22.%20%7D%0A%7D\" style=\"width:100%;max-width:100%;height:450px\" frameborder=\"0\"><\/iframe>\n\n\n\n<h5 id=\"syntax\"> # A little bit of syntax<\/h5>\n\n\n\n<p>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:<br>?item wdt:P57 ?director.\u00a0<br>?director wdt:P19 ?dob.<br><br>We write: <br>?item wdt:P57 [wdt:P19 ?dob].\u00a0 <\/p>\n\n\n\n<iframe class=\"\" src=\"https:\/\/query.wikidata.org\/#%23Star%20Wars%20film%20directors%27%20place%20of%20birth%0A%0ASELECT%20%3Fitem%20%20%3FitemLabel%20%3FdirectorLabel%20%3FpobLabel%0AWHERE%20%0A%7B%20%0A%20%20%3Fitem%20wdt%3AP179%20wd%3AQ22092344.%20%20%20%20%20%23%20item%20is%20part%20of%20the%20series%20Star%20Wars%20%28film%20series%29%0A%20%20%3Fitem%20wdt%3AP57%20%5Bwdt%3AP19%20%3Fpob%5D.%20%20%20%20%23%20the%20place%20of%20birth%20of%20the%20director%20is%20collected%20in%20the%20%3Fpob%20variable%0A%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%22.%20%7D%0A%7D\" style=\"width:100%;max-width:100%;height:450px\" frameborder=\"0\"><\/iframe>\n\n\n\n<p> What has changed in the results? Why?<br> <br>This syntax omits the ?director variable, so ?directorLabel is empty.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Retrieving data linked to values 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. The query selects items that are part of the star wars series, and retrieves each [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":""},"categories":[14],"tags":[],"_links":{"self":[{"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/posts\/684"}],"collection":[{"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/comments?post=684"}],"version-history":[{"count":13,"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/posts\/684\/revisions"}],"predecessor-version":[{"id":1769,"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/posts\/684\/revisions\/1769"}],"wp:attachment":[{"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/media?parent=684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/categories?post=684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wdqs-tutorial.toolforge.org\/index.php\/wp-json\/wp\/v2\/tags?post=684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}