query-f0ea07fbc3840cbf7e850be35bf1d84b

rq turtle/ttl

title: Current ministers of Iceland (should be 12) SELECT ?item ?itemLabel ?currentMinister ?currentMinisterLabel ?startTime { ?item wdt:P31 wd:Q294414 . ?item wdt:P279 wd:Q83307 . ?item wdt:P361 wd:Q12351757 . ?item wdt:P17/wdt:P1001 wd:Q189 .

MINUS { ?item wdt:P576 [] }

# Get ministers and their start times ?item p:P1308 ?statement . ?statement ps:P1308 ?currentMinister . ?statement pq:P580 ?startTime . ?currentMinister rdfs:label ?currentMinisterLabel . FILTER(LANG(?currentMinisterLabel) = "en")

# Current ministers are the ones that have the most recent start time FILTER NOT EXISTS { ?item p:P1308 ?otherStatement . ?otherStatement ps:P1308 ?otherMinister . ?otherStatement pq:P580 ?otherStartTime . FILTER (?otherStartTime > ?startTime) }

SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#title: Current ministers of Iceland (should be 12)
SELECT ?item ?itemLabel ?currentMinister ?currentMinisterLabel ?startTime {
  ?item wdt:P31 wd:Q294414 .
  ?item wdt:P279* wd:Q83307 .
  ?item wdt:P361 wd:Q12351757 .
  ?item wdt:P17/wdt:P1001* wd:Q189 .

  MINUS { ?item wdt:P576 [] }

  # Get ministers and their start times
  ?item p:P1308 ?statement .
  ?statement ps:P1308 ?currentMinister .
  ?statement pq:P580 ?startTime .
  ?currentMinister rdfs:label ?currentMinisterLabel .
  FILTER(LANG(?currentMinisterLabel) = "en")

  # Current ministers are the ones that have the most recent start time
  FILTER NOT EXISTS {
    ?item p:P1308 ?otherStatement .
    ?otherStatement ps:P1308 ?otherMinister .
    ?otherStatement pq:P580 ?otherStartTime .
    FILTER (?otherStartTime > ?startTime)
  }

  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; v8("?currentMinister"):::projected v6("?currentMinisterLabel"):::projected v3("?item"):::projected v5("?otherMinister") v1("?otherStartTime") v4("?otherStatement") v2("?startTime"):::projected v7("?statement") a2((" ")) a1((" ")) c8(["wd:Q83307"]):::iri c10(["wd:Q12351757"]):::iri c17(["bd:serviceParam"]):::iri c6(["wd:Q294414"]):::iri c19(["#91;AUTO_LANGUAGE#93;,en"]):::literal c13(["wd:Q189"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0f0[["?otherStartTime > ?startTime"]] e0f0 --> e0v1 e0f0 --> e0v2 e0v3 --"p:P1308"--> e0v4 e0v4 --"p:statement/P1308"--> e0v5 e0v4 --"p:qualifier/P580"--> e0v1 e0v3("?item"):::projected e0v5("?otherMinister"):::projected e0v1("?otherStartTime"):::projected e0v4("?otherStatement"):::projected e0v2("?startTime"):::projected end f0--EXISTS--> f0e0 f0 --> v1 f0 --> v2 f0 --> v3 f0 --> c1 f0 --> v4 f0 --> c2 f0 --> v5 f0 --> c3 f1[["?otherStartTime > ?startTime"]] f1 --> v1 f1 --> v2 v3 --"p:P1308"--> v4 v4 --"p:statement/P1308"--> v5 v4 --"p:qualifier/P580"--> v1 f2[["?currentMinisterLabel = 'en'"]] f2 --> v6 v3 --"p:direct/P31"--> c6 v3 --"p:direct/P279"--> c8 v3 --"p:direct/P361"--> c10 v3 --"p:direct/P17"--> a1 a1 --"p:direct/P1001"--> c13 subgraph minus3["MINUS"] style minus3 stroke-width:6px,fill:pink,stroke:red; v3 --"p:direct/P576"--> a2 end v3 --"p:P1308"--> v7 v7 --"p:statement/P1308"--> v8 v7 --"p:qualifier/P580"--> v2 v8 --"rdfs:label"--> v6 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c17 --"wikibase:language"--> c19 end