0

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)
Al Mac
  • 49
  • 1
  • To be honest, I didn't understand the question. First of all, with the query it's a bit difficult to debug or modify your query. moreover, the current result + the expected result make such questions much more understandable – UninformedUser Mar 14 '19 at 17:29
  • 1
    If you mean `?others` must not be the same as `?alumni`, then a FILTER != should do the trick. But as I said, I probably didn't understand the problem at all and can't run your query right now – UninformedUser Mar 14 '19 at 17:31
  • 1
    Yes, that was what I was asking, how to exclude the single value bound to ?alumni from the set of values bound to ?others. I thought I needed to use one of the paths, as I had done to create ?others. I tried FILTER (?others !=?alumni) . and it worked. I'm a relative beginner and hadn't used FILTER in this way before with a variable rather than a value, so thank you! – Al Mac Mar 15 '19 at 10:04
  • ah ok, yes I wasn't sure if that's what you meant because it looked to simple to me and thought you already tried it with the FILTER. Glad it helps, so you could provide it as an answer and accept your own question. Helps others – UninformedUser Mar 15 '19 at 10:43

0 Answers0