query-47cff199da152672b21da3be3f977a2c

rq turtle/ttl

Ralfalfa83

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?country ?countryLabel  ?capital ?capitalLabel ?continent ?continentLabel ?continent_is_unknown
WHERE
{

{
  SELECT ?country (SAMPLE(?continent) AS ?country_continent) (COUNT(?continent) = 1 AS ?one_continent)
  WHERE
  {

{
  SELECT DISTINCT ?country
  WHERE
  {
    ?country wdt:P31 / wdt:P279* wd:Q6256 .
  }
}    OPTIONAL { ?country wdt:P30 ?continent . }
  }
  GROUP BY ?country
}  OPTIONAL
  {
    ?country wdt:P36 ?capital .
    OPTIONAL { ?capital wdt:P30 ?capital_continent . }
  }
  BIND (COALESCE(?capital_continent, ?country_continent) AS ?continent)
  BIND (! BOUND(?capital_continent) && ! ?one_continent AS ?continent_is_unknown)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?_anon_42b5416610844a34809f33a099ae9de1102361") v6("?capital"):::projected v7("?capital_continent") v8("?continent"):::projected v8("?continent_is_unknown"):::projected v1("?country"):::projected v4("?country_continent") v5("?one_continent") a1((" ")) c7(["bd:serviceParam"]):::iri c9(["#91;AUTO_LANGUAGE#93;,en"]):::literal c3(["wd:Q6256"]):::iri v1 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c3 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P30".-> v8 end bind2[/"count(?continent)"/] v8 --o bind2 bind2 --as--o v3 bind3[/"sample(?continent)"/] v8 --o bind3 bind3 --as--o v4 bind4[/" = '1^^xsd:integer'"/] null --o bind4 bind4 --as--o v5 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v1 -."wdt:P36".-> v6 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v6 -."wdt:P30".-> v7 end end bind5[/"?capital_continent?country_continent"/] v7 --o bind5 v4 --o bind5 bind5 --as--o v8 bind6[/"not bound(?capital_continent)not ?one_continent"/] v7 --o bind6 v5 --o bind6 bind6 --as--o v8 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c7 --"wikibase:language"--> c9 end