I am querying Wikidata with the objective of creating a set of Edinburgh or Glasgow University alumni who are current members of the Scottish Parliament. What I would then like to do is return a list of which other positions of office they have held and, for each office, the names of other living persons who have held that office, whether or not they are alumni.
I have managed the above but the set of results for others holding the office - variable ?others - includes the original subject for the variable ?alumni in each case. I would like all OTHER office bearers, not including the person mapping to ?alumni. Query is rather long, so just including the relevant sections.
#associate ?alumni with positions of office
?alumni p:P39 ?officeStmnt .
?officeStmnt ps:P39 ?role .
?role rdfs:label ?roleLabel .
FILTER (langMatches(lang(?roleLabel ), "en")) .
FILTER NOT EXISTS
{
FILTER(langMatches(lang(?roleLabel ), "en-ca"))
}.
FILTER NOT EXISTS
{
FILTER(langMatches(lang(?roleLabel ), "en-gb"))
} .
#Filter for member of 5th Scottish Parliament
VALUES (?role)
{
(wd:Q30580546)
} .
?alumni p:P39 ?officeStmnts .
?officeStmnts ps:P39/rdfs:label ?rolesLabel .
FILTER (langMatches(lang(?rolesLabel ), "en")) .
FILTER (!regex (?rolesLabel,"Member of")) .
?rolesLabel ^rdfs:label ?roles .
?roles ^ps:P39/^p:P39 ?others .
?others rdfs:label ?othersLbl .
FILTER (langMatches(lang(?othersLbl ), "en")) .
BIND (xsd:string(?othersLbl) AS ?othersStr)