There is a solution, but it’s a bit hacky. You can get the categories of the file via the MWAPI service [1] and then try to match those categories that denote a license (for example, a category starting with “CC-” *probably* indicates a Creative Commons license).
Here’s a query using the example image you mentioned [2]:
SELECT ?item ?image ?categoryName WHERE { BIND(wd:Q9188 AS ?item) ?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-")) }
In the future, this should become much easier, thanks to Structured Commons [3].
Cheers, Lucas
[1]: https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual/MWAPI [2]: https://query.wikidata.org/#SELECT%20%3Fitem%20%3Fimage%20%3FcategoryName%20... [3]: https://commons.wikimedia.org/wiki/Commons:Structured_data
On 8/28/18 8:36 PM, Bob DuCharme wrote:
I know how to run SPARQL queries to find out various properties of the Empire State Building as shown on https://www.wikidata.org/wiki/Q9188, including the URL of the image shown there.
When I look at the https://commons.wikimedia.org/wiki/File:Empire_State_Building_from_the_Top_o... web page I see that the image has a CC-BY-SA-2.0 license, but I can't work out how to get to that in a query.
Can anyone show me a SPARQL query about this image where the query result would show me the license type?
Thanks,
Bob
Wikidata mailing list Wikidata@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikidata