query-3ba2daf18c227efdd9cf5e79550443c2

rq turtle/ttl

All UK and pre-Union MPs - England to 1707, GB 1707-1801, and UK 1801-date

SELECT DISTINCT ?person ?personLabel (sample(?born) AS ?born_sample) (sample(?died) AS ?died_sample) (sample(?fl) AS ?fl_sample) WHERE { ?person wdt:P31 wd:Q5 . # this person is a real person (not fictional) ?person p:P39 ?ps . # this person has a position statement ?ps ... ?ps ps:P39 ?position . # and the statement is for a ?position which is... { ?position wdt:P279 wd:Q16707842 } # a UK MP or a subclass (specific period) UNION { ?position wdt:P279 wd:Q18015642 } # OR a GB MP or a subclass (specific period) UNION { ?position wdt:P279* wd:Q18018860 } # OR an English MP or a subclass (specific period) optional { ?person wdt:P569 ?b . BIND(YEAR(?b) AS ?born ) } # identify the year of birth optional { ?person wdt:P570 ?d . BIND(YEAR(?d) AS ?died ) } # identify the year of death optional { ?person (wdt:P1317|wdt:P2031|wdt:P2032) ?f . BIND(YEAR(?f) AS ?fl ) } # three different kinds of fl. date SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # name } GROUP BY ?person ?personLabel # needed for grouping

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 p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#All UK and pre-Union MPs - England to 1707, GB 1707-1801, and UK 1801-date

SELECT DISTINCT ?person ?personLabel (sample(?born) AS ?born_sample) (sample(?died) AS ?died_sample) (sample(?fl) AS ?fl_sample)
WHERE {
  ?person wdt:P31 wd:Q5 .                    # this person is a real person (not fictional)
  ?person p:P39 ?ps .                        # this person has a position statement ?ps ...
  ?ps ps:P39 ?position .                     # and the statement is for a ?position which is...
        { ?position wdt:P279* wd:Q16707842 }      # a UK MP or a subclass (specific period)
  UNION { ?position wdt:P279* wd:Q18015642 }      # OR a GB MP or a subclass (specific period)
  UNION { ?position wdt:P279* wd:Q18018860 }      # OR an English MP or a subclass (specific period)
  optional { ?person wdt:P569 ?b . BIND(YEAR(?b) AS ?born ) }      # identify the year of birth
  optional { ?person wdt:P570 ?d . BIND(YEAR(?d) AS ?died ) }      # identify the year of death
  optional { ?person (wdt:P1317|wdt:P2031|wdt:P2032) ?f . BIND(YEAR(?f) AS ?fl ) } # three different kinds of fl. date
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # name
} GROUP BY ?person ?personLabel # needed for grouping

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?b") v5("?born"):::projected v10("?born_sample") v6("?d") v7("?died"):::projected v11("?died_sample") v8("?f") v9("?fl"):::projected v12("?fl_sample") v1("?person"):::projected v3("?position") v2("?ps") c8(["wd:Q18018860"]):::iri c6(["wd:Q16707842"]):::iri c15(["bd:serviceParam"]):::iri c2(["wd:Q5"]):::iri c17(["#91;AUTO_LANGUAGE#93;,en"]):::literal c7(["wd:Q18015642"]):::iri v1 --"p:direct/P31"--> c2 v1 --"p:P39"--> v2 v2 --"p:statement/P39"--> v3 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P279"--> c8 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P279"--> c7 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v3 --"p:direct/P279"--> c6 end union0r <== or ==> union0l end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P569".-> v4 bind0[/"year-from-dateTime(?b)"/] v4 --o bind0 bind0 --as--o v5 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v1 -."p:direct/P570".-> v6 bind1[/"year-from-dateTime(?d)"/] v6 --o bind1 bind1 --as--o v7 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; subgraph union2[" Union "] subgraph union2l[" "] style union2l fill:#abf,stroke-dasharray: 3 3; subgraph union3[" Union "] subgraph union3l[" "] style union3l fill:#abf,stroke-dasharray: 3 3; v1 -."p:direct/P2032".-> v8 end subgraph union3r[" "] style union3r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P2031"--> v8 end union3r <== or ==> union3l end end subgraph union2r[" "] style union2r fill:#abf,stroke-dasharray: 3 3; v1 --"p:direct/P1317"--> v8 end union2r <== or ==> union2l end bind2[/"year-from-dateTime(?f)"/] v8 --o bind2 bind2 --as--o v9 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c15 --"wikibase:language"--> c17 end bind6[/"sample(?born)"/] v5 --o bind6 bind6 --as--o v10 bind7[/"sample(?died)"/] v7 --o bind7 bind7 --as--o v11 bind8[/"sample(?fl)"/] v9 --o bind8 bind8 --as--o v12