query-89865c0dbdef4f503a816c2ee71e8586

rq turtle/ttl

.on Mastodon and on TwitterOriginally posted

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#>
# US governors by eye color
#defaultView:Map{ "hide": ["?rgb", "?shape"] }
SELECT ?state ?stateLabel ?governor ?governorLabel ?eyeColor ?eyeColorLabel (?eyeColorRgb AS ?rgb) ?shape
WHERE {
  ?state wdt:P31 wd:Q35657;
         wdt:P6 ?governor;
         wdt:P3896 ?shape.
  ?governor wdt:P31 wd:Q5;
            wdt:P1340 ?eyeColor.
   {
  SELECT ?eyeColor (SAMPLE(?eyeColorRgb) AS ?eyeColorRgb) WHERE {
    [] wdt:P1340 ?eyeColor.
    OPTIONAL { ?eyeColor wdt:P465 ?eyeColorDirectRgb. }
    OPTIONAL { ?eyeColor wdt:P462/wdt:P465 ?eyeColorIndirectRgb. }
    BIND(COALESCE(?eyeColorDirectRgb, ?eyeColorIndirectRgb) AS ?eyeColorRgb)
  }
  GROUP BY ?eyeColor
}
  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; v4("?eyeColor"):::projected v5("?eyeColorDirectRgb") v6("?eyeColorIndirectRgb") v8("?eyeColorRgb"):::projected v2("?governor"):::projected v8("?rgb") v3("?shape"):::projected v1("?state"):::projected a1((" ")) a2((" ")) c10(["bd:serviceParam"]):::iri c5(["wd:Q5"]):::iri c12(["#91;AUTO_LANGUAGE#93;,en"]):::literal c2(["wd:Q35657"]):::iri v1 --"wdt:P31"--> c2 v1 --"wdt:P6"--> v2 v1 --"wdt:P3896"--> v3 v2 --"wdt:P31"--> c5 v2 --"wdt:P1340"--> v4 a1 --"wdt:P1340"--> v4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."wdt:P465".-> v5 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v4 -."wdt:P462".-> a2 a2 --"wdt:P465"--> v6 end bind0[/"?eyeColorDirectRgb?eyeColorIndirectRgb"/] v5 --o bind0 v6 --o bind0 bind0 --as--o v8 bind2[/"sample(?eyeColorRgb)"/] v8 --o bind2 bind2 --as--o v8 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c10 --"wikibase:language"--> c12 end bind3[/"?eyeColorRgb"/] v8 --o bind3 bind3 --as--o v8