query-2e8ba890f5d5cceae7ffc5caec7a123d

rq turtle/ttl

Propertiesinstance of (P31)position held (P39)spouse (P26)start time (P580)end time (P582)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
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#>
SELECT 
?president ?presidentLabel 
?termStart ?termEnd
?spouse 
?relationshipStart ?relationshipEnd 
WHERE {

   ?president wdt:P31 wd:Q5 .

   ?president                p:P39     ?position_held_statement .
   ?position_held_statement ps:P39   wd:Q11696 .
   ?position_held_statement pq:P580    ?termStart .

   # current presiden will always miss it
   OPTIONAL {   
     ?position_held_statement pq:P582  ?termEnd
   } 

   # spouse is optional
   OPTIONAL {
      ?president             p:P26     ?spouseStatement .
      ?spouseStatement      ps:P26     ?spouse .
      ?spouseStatement      pq:P580    ?relationshipStart .

      # current spouse will always miss it
      OPTIONAL {   
        ?spouseStatement    pq:P582    ?relationshipEnd
      }
   }

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

 } ORDER BY ?termStart ?relationshipStart

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?position_held_statement") v3("?president"):::projected v8("?relationshipEnd"):::projected v2("?relationshipStart"):::projected v7("?spouse"):::projected v6("?spouseStatement") v5("?termEnd"):::projected v1("?termStart"):::projected c11(["bd:serviceParam"]):::iri c2(["wd:Q5"]):::iri c13(["#91;AUTO_LANGUAGE#93;,en"]):::literal c5(["wd:Q11696"]):::iri v3 --"p:direct/P31"--> c2 v3 --"p:P39"--> v4 v4 --"p:statement/P39"--> c5 v4 --"p:qualifier/P580"--> v1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:qualifier/P582".-> v5 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v3 -."p:P26".-> v6 v6 --"p:statement/P26"--> v7 v6 --"p:qualifier/P580"--> v2 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:qualifier/P582".-> v8 end end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c11 --"wikibase:language"--> c13 end