0

Based on wikidata I want to make a list of all members of the European Parliament and I want some metadata about their membership like start date and the party they represent.

As a start I run the following query:

SELECT ?human ?humanLabel ?positionheldLabel
WHERE
{
# human position_held MembEuroParl
  ?human wdt:P39 wd:Q27169;
         wdt:P39 ?positionheld.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}

This returns a list of people who once were member of european parliament and the positions they held. However also if those positions were not Member of parliament. See image.

enter image description here

So I change the query to the following adding a line that the positionheld sould be member of parliament:

SELECT ?human ?humanLabel ?positionheld
WHERE
{
# ?human position_held MEP
  ?human wdt:P39 wd:Q27169;
         wdt:P39 ?positionheld.
  ?positionheld wdt:P31 wd:Q27169.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}

However, this last query does not return any results. Besides, it feels repetitive

My question how can I select only those rows where positionheld is member of parliament. The answer is probably trivial, yet currently I am left clueless. Something I wanted to take 1 minutes is taking an hour.

Ottotos
  • 633
  • 5
  • 14
  • 1
    What you first query asks for all items the held the position of MEP and since you ask about the positions held, it also lists other positions by the "people" were at least once MEPs. The second query does not return results as it restricts a variable, already bound to position held to be an instance of MEP. If we can talk about instance here, it is the usage of the property in the claim. You'd need that only if you are looking for things like start and end date and the way to retrieve it is different. – Ivo Velitchkov Apr 09 '20 at 13:13
  • Thank you. That is insightful. – Ottotos Apr 09 '20 at 13:55
  • 1
    `SELECT ?human ?humanLabel ?representedPartyLabel ?startDate WHERE { ?human p:P39 ?stmt. ?stmt ps:P39 wd:Q27169 . ?stmt pq:P1268 ?representedParty . ?stmt pq:P580 ?startDate SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". } }` - you can see sometimes multiple rows for the same person because the have been elected several times. If you don't want this, use aggregation `group_concat` and group by the `human` – UninformedUser Apr 09 '20 at 14:59
  • This is amazing. Thank you, exactly what I need. – Ottotos Apr 10 '20 at 06:37

0 Answers0