sparqlwikipediadbpediawikidata

Getting members of a category from Wikidata


I would like to get all the members of a specific category from Wikidata. For example, I would like to get all the films (instances of film: P31 Q11424) from the category "Category:Films set in Stockholm" (Q7519614). However, I can't seem to find what the relationship would be. DBpedia uses "subject of" but the Wikidata equivalent (P805) doesn't return any results.

I also thought I could bootstrap my way to the answer with this query, but to no avail:

SELECT ?s ?p ?pLabel WHERE {
  ?s ?p wd:Q7519614.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Solution

  • May be an indirect answer, but worth trying

    When you look for the property related to an entity like Q7519614, it's often worth trying https://www.wikidata.org/wiki/Special:WhatLinksHere/Q7519614 (What links here?)

    In this case the answer is empty which means there IS NO relation encoded in WIKIDATA for this information. (it means you need to rely on 3rd parties tool to access WIKIPEDIA information)

    The second way to see your question is also encoded with P360 (is a list of)

    In this case it says that it's a list of Film with (Q11424) with filming location (P915) equal to Stockholm (Q1754)

    So the closest query you're looking at is

    SELECT ?film 
    WHERE { 
     ?film wdt:P31 wd:Q11424;
           wdt:P915 wd:Q506250.                    
    }