Discussion:
image re-use information available via a SPARQL query?
(too old to reply)
Bob DuCharme
2018-08-28 18:36:24 UTC
Permalink
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
Loading Image...
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
Jan Macura
2018-08-28 20:16:32 UTC
Permalink
Hello Bob,

As far as I know, I am afraid that this is not possible, and won't be
possible until the Structured data on Commons
<https://commons.wikimedia.org/wiki/Commons:Structured_data> will come to
life.

Regards,
Jan
Lucas Werkmeister
2018-08-29 15:57:32 UTC
Permalink
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%20WHERE%20%7B%0A%20%20BIND%28wd%3AQ9188%20AS%20%3Fitem%29%0A%20%20%3Fitem%20wdt%3AP18%20%3Fimage.%0A%20%20BIND%28REPLACE%28wikibase%3AdecodeUri%28CONCAT%28%22File%3A%22%2C%20STRAFTER%28STR%28%3Fimage%29%2C%20%22%2Fwiki%2FSpecial%3AFilePath%2F%22%29%29%29%2C%20%22%20%22%2C%20%22_%22%29%20AS%20%3FimageTitle%29%0A%20%20SERVICE%20wikibase%3Amwapi%20%7B%0A%20%20%20%20bd%3AserviceParam%20wikibase%3Aapi%20%22Categories%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wikibase%3Aendpoint%20%22commons.wikimedia.org%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mwapi%3Atitles%20%3FimageTitle.%0A%20%20%20%20%3FcategoryTitle%20wikibase%3AapiOutput%20mwapi%3Acategory.%0A%20%20%7D%0A%20%20BIND%28STRAFTER%28%3FcategoryTitle%2C%20%22Category%3A%22%29%20AS%20%3FcategoryName%29%0A%20%20FILTER%28STRSTARTS%28%3FcategoryName%2C%20%22CC-%22%29%29%0A%7D
[3]: https://commons.wikimedia.org/wiki/Commons:Structured_data
Post by Bob DuCharme
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_of_the_Rock.jpg
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
https://lists.wikimedia.org/mailman/listinfo/wikidata
Bob DuCharme
2018-09-01 14:26:56 UTC
Permalink
Thanks Lukas, I will give that a shot.

Bob
Post by Lucas Werkmeister
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).
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
https://query.wikidata.org/#SELECT%20%3Fitem%20%3Fimage%20%3FcategoryName%20WHERE%20%7B%0A%20%20BIND%28wd%3AQ9188%20AS%20%3Fitem%29%0A%20%20%3Fitem%20wdt%3AP18%20%3Fimage.%0A%20%20BIND%28REPLACE%28wikibase%3AdecodeUri%28CONCAT%28%22File%3A%22%2C%20STRAFTER%28STR%28%3Fimage%29%2C%20%22%2Fwiki%2FSpecial%3AFilePath%2F%22%29%29%29%2C%20%22%20%22%2C%20%22_%22%29%20AS%20%3FimageTitle%29%0A%20%20SERVICE%20wikibase%3Amwapi%20%7B%0A%20%20%20%20bd%3AserviceParam%20wikibase%3Aapi%20%22Categories%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wikibase%3Aendpoint%20%22commons.wikimedia.org%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mwapi%3Atitles%20%3FimageTitle.%0A%20%20%20%20%3FcategoryTitle%20wikibase%3AapiOutput%20mwapi%3Acategory.%0A%20%20%7D%0A%20%20BIND%28STRAFTER%28%3FcategoryTitle%2C%20%22Category%3A%22%29%20AS%20%3FcategoryName%29%0A%20%20FILTER%28STRSTARTS%28%3FcategoryName%2C%20%22CC-%22%29%29%0A%7D
[3]: https://commons.wikimedia.org/wiki/Commons:Structured_data
Post by Bob DuCharme
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_of_the_Rock.jpg
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
https://lists.wikimedia.org/mailman/listinfo/wikidata
_______________________________________________
Wikidata mailing list
https://lists.wikimedia.org/mailman/listinfo/wikidata
Loading...