I am trying to return results for a set of persons (Edinburgh University alumni) who have held political office. I would like to return the title label of the office held, along with the start and end dates for each office, with many individuals holding multiple positions. I seem to be able to get one or the other or can get it to work if the person only held one position, but can't get the two to come together where multiple offices were held.
My current version of the query is below. This will give me the start and end dates, but rather than the label if the political office, such as Member of the [x] Parliament of the United Kingdom, ?officeLabel returns a value such as: statement/Q4668868-E3734C7D-40F0-4D4A-8208-E3D6B8C944CB
SELECT DISTINCT ?alumni ?fullName ?roleLabel ?officeLabel ?start ?end WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?alumni wdt:P69 wd:Q160302.
?alumni rdfs:label ?fullName.
?alumni wdt:P106 ?role.
#Use Values to separate out politicians - Q82955
VALUES (?role) {
(wd:Q82955)
}
#Select only where position of office is stated but make dates optional
?alumni p:P39 ?office.
OPTIONAL { ?office pq:P580 ?start. }
OPTIONAL { ?office pq:P582 ?end. }
FILTER(LANGMATCHES(LANG(?fullName), "en"))
FILTER(NOT EXISTS { FILTER(LANGMATCHES(LANG(?fullName), "en-ca")) })
FILTER(NOT EXISTS { FILTER(LANGMATCHES(LANG(?fullName), "en-gb")) })
}
ORDER BY ?fullName
LIMIT 10