SPARQL examples: Difference between revisions

From Dariah-Lab
Jump to navigation Jump to search
No edit summary
No edit summary
Line 28: Line 28:
</syntaxhighlight>
</syntaxhighlight>
[https://{{SERVERNAME}}/wdqs/#%23Humans%20%0A%23Lists%20all%20humans%20with%20values%20of%20selected%20fields%0ASELECT%20%3Fhuman%20%3FhumanLabel%20%3FfatherLabel%20%3FmotherLabel%20%3Fdate_of_birth%20WHERE%20%7B%0A%20%20%3Fhuman%20wdt%3AP47%20wd%3AQ32.%0A%20%20OPTIONAL%20%7B%20%3Fhuman%20wdt%3AP66%20%3Ffather.%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fhuman%20wdt%3AP68%20%3Fmother.%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fhuman%20wdt%3AP7%20%3Fdate_of_birth.%20%7D%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D Try it!]
[https://{{SERVERNAME}}/wdqs/#%23Humans%20%0A%23Lists%20all%20humans%20with%20values%20of%20selected%20fields%0ASELECT%20%3Fhuman%20%3FhumanLabel%20%3FfatherLabel%20%3FmotherLabel%20%3Fdate_of_birth%20WHERE%20%7B%0A%20%20%3Fhuman%20wdt%3AP47%20wd%3AQ32.%0A%20%20OPTIONAL%20%7B%20%3Fhuman%20wdt%3AP66%20%3Ffather.%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fhuman%20wdt%3AP68%20%3Fmother.%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fhuman%20wdt%3AP7%20%3Fdate_of_birth.%20%7D%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D Try it!]
=== <!--T:3--> Humans without parents===
<syntaxhighlight lang="SPARQL" class="mw-highlight mw-highlight-lang-sparql mw-content-ltr" dir="ltr">
#Lists all humans without parents
SELECT ?human ?humanLabel WHERE {
  ?human wdt:P47 wd:Q32. #find humans
  MINUS {
    ?human wdt:P68 [] . # without father
    ?human wdt:P66 [] . # without mother
    ?human wdt:P65 [] . # without any unspecified parent
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
</syntaxhighlight>
[https://{{SERVERNAME}}/wdqs/#%23Humans%20%0A%23Lists%20all%20humans%20without%20parents%0ASELECT%20%3Fhuman%20%3FhumanLabel%20WHERE%20%7B%0A%20%20%3Fhuman%20wdt%3AP47%20wd%3AQ32.%20%23find%20humans%0A%20%20MINUS%20%7B%0A%20%20%20%20%3Fhuman%20wdt%3AP68%20%5B%5D%20.%20%23%20without%20father%0A%20%20%20%20%3Fhuman%20wdt%3AP66%20%5B%5D%20.%20%23%20without%20mother%0A%20%20%20%20%3Fhuman%20wdt%3AP65%20%5B%5D%20.%20%23%20without%20any%20unspecified%20parent%0A%20%20%7D%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D Try it!]

Revision as of 11:15, 12 May 2022

This page is parsed by the web interface of the query service to fill the query example dialog.


Institutions

  SELECT ?institution ?institutionLabel 
  WHERE
  {
      ?institution wdt:P47 wd:Q467. # instance of Institution
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  }

Try it!

Humans

#Lists all humans with values of selected fields
SELECT ?human ?humanLabel ?fatherLabel ?motherLabel ?date_of_birth WHERE {
  ?human wdt:P47 wd:Q32.
  OPTIONAL { ?human wdt:P66 ?father. }
  OPTIONAL { ?human wdt:P68 ?mother. }
  OPTIONAL { ?human wdt:P7 ?date_of_birth. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Humans without parents

#Lists all humans without parents
SELECT ?human ?humanLabel WHERE {
  ?human wdt:P47 wd:Q32. #find humans
  MINUS {
    ?human wdt:P68 [] . # without father
    ?human wdt:P66 [] . # without mother
    ?human wdt:P65 [] . # without any unspecified parent
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!