Skip to content

Instantly share code, notes, and snippets.

@hughlilly
Last active September 13, 2021 22:29
Show Gist options
  • Save hughlilly/a83aeaddffcab0c9dd5503f025750ae5 to your computer and use it in GitHub Desktop.
Save hughlilly/a83aeaddffcab0c9dd5503f025750ae5 to your computer and use it in GitHub Desktop.
Wikidata/WMC SPARQL queries for AM data
# https://wcqs-beta.wmflabs.org/
SELECT ?pageid ?file ?title
(GROUP_CONCAT(DISTINCT ?mi_label;separator="; ") as ?miLabel)
(GROUP_CONCAT(DISTINCT ?en_label;separator="; ") as ?enLabel)
WITH {
SELECT * WHERE {
SERVICE wikibase:mwapi
{
bd:serviceParam wikibase:api "Generator" .
bd:serviceParam wikibase:endpoint "commons.wikimedia.org" .
bd:serviceParam mwapi:gcmtitle "Category:1930s photographs in Auckland Museum" .
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 %files
WITH {
SELECT ?file ?title ?depicts WHERE {
INCLUDE %files .
?file wdt:P180 ?depicts .
}
} AS %depictions
WHERE {
INCLUDE %depictions .
INCLUDE %files .
SERVICE <https://query.wikidata.org/sparql> {
OPTIONAL {?depicts rdfs:label ?mi_label . filter(lang(?mi_label) = "mi")}
OPTIONAL {?depicts rdfs:label ?en_label . filter(lang(?en_label) = "en")}
}
}
GROUP BY ?pageid ?file ?title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment