User:TweetsFactsAndQueries/Queries/image license without Structured Commons
Originally posted on wikidata-l, subsequently also on Twitter.
# try to determine the license of an image
SELECT ?item ?image ?categoryName WHERE {
BIND(wd:Q9188 AS ?item) # example
?item wdt:P18 ?image.
BIND(REPLACE(wikibase:decodeUri(CONCAT("File:", STRAFTER(STR(?image), "/wiki/Special:FilePath/"))), " ", "_") AS ?imageTitle)
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:api "Categories";
wikibase:endpoint "commons.wikimedia.org";
mwapi:titles ?imageTitle.
?categoryTitle wikibase:apiOutput mwapi:category.
}
BIND(STRAFTER(?categoryTitle, "Category:") AS ?categoryName)
FILTER(STRSTARTS(?categoryName, "CC-") || REGEX(?categoryName, "^PD[- ]"))
}
One day, Structured Commons shall deliver us from this madness.