Commons:Whose Knowledge?/VisibleWikiWomen/Queries

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

All files from a category with no depict statements

[edit]
# All files from a category with no depict statements 
SELECT DISTINCT ?file ?title
WITH
{
  SELECT DISTINCT ?file ?title  # Retrieve file links and titles...
  WHERE
  {
    SERVICE wikibase:mwapi
    {
      bd:serviceParam wikibase:api "Generator" .
      bd:serviceParam wikibase:endpoint "commons.wikimedia.org" .
      bd:serviceParam mwapi:gcmtitle "Category:VisibleWikiWomen 2020" .  # Specific VWW category you want for this query.
      bd:serviceParam mwapi:generator "categorymembers" .
      bd:serviceParam mwapi:gcmtype "file" .
      bd:serviceParam mwapi:gcmlimit "max" .
      ?title wikibase:apiOutput mwapi:title .
      ?pageid wikibase:apiOutput "@pageid" .
    }
    BIND (URI(CONCAT('https://commons.wikimedia.org/entity/M', ?pageid)) AS ?file)
  }
} AS %get_files
WHERE
{
  INCLUDE %get_files
  MINUS { ?file wdt:P180 ?depicted . }  # The files have not depict statements.
}

Try it!


All files from a category with individual human beings depicted

[edit]
# All files from a category with individual human beings depicted
SELECT DISTINCT ?file ?title ?depicted ?depictedLabel
WITH
{
  SELECT DISTINCT ?file ?title  # Retrieve file links and titles...
  WHERE
  {
    SERVICE wikibase:mwapi
    {
      bd:serviceParam wikibase:api "Generator" .
      bd:serviceParam wikibase:endpoint "commons.wikimedia.org" .
      bd:serviceParam mwapi:gcmtitle "Category:VisibleWikiWomen 2020" .  # Specific VWW category you want for this query.
      bd:serviceParam mwapi:generator "categorymembers" .
      bd:serviceParam mwapi:gcmtype "file" .
      bd:serviceParam mwapi:gcmlimit "max" .
      ?title wikibase:apiOutput mwapi:title .
      ?pageid wikibase:apiOutput "@pageid" .
    }
    BIND (URI(CONCAT('https://commons.wikimedia.org/entity/M', ?pageid)) AS ?file)
  }
} AS %get_files
WHERE
{
  INCLUDE %get_files
  ?file wdt:P180 ?depicted .  # The files have depict statements.
  
  SERVICE <https://query.wikidata.org/sparql>  
  {
    ?depicted wdt:P31 wd:Q5 .  # The items depicted are human beings.
    ?depicted rdfs:label ?depictedLabel .
    FILTER ( LANG(?depictedLabel) = "en" )
  }
}

Try it!