This is very strange. Commons Media values are not supposed to be strings in RDF –
the documentation confirms that they’re supposed to be Special:FilePath URIs, and for most images, this is the case:
SELECT (STR(?image) AS ?str) (ISIRI(?image) AS ?isIri) WHERE {
wd:Q33231166 wdt:P18 ?image.
}
(The query service UI then rewrites that URL into a different one when showing the result, sending you to the file description page instead of directly to the file.)
To search for an image by its name, you can construct that URL in the query:
PREFIX commons: <
http://commons.wikimedia.org/wiki/Special:FilePath/>
SELECT * WHERE {
hint:Query hint:optimizer "None".
BIND("1936-ChirkovAntonNikolaevich.jpg" AS ?fileName)
BIND(IRI(CONCAT(STR(commons:), ENCODE_FOR_URI(?fileName))) AS ?image)
?item wdt:P18 ?image.
}
I have no idea why your simple query, searching for the file name as a string, actually works sometimes. I assume this must be a bug – I’ve created
T258782 to track it. (Your first example, Q16718402 / 1936-ChirkovAntonNikolaevich.jpg, is now a URL – Lydia edited the item to see if that resolved the issue, and after the query service updater re-imported the item, the issue was gone.)
Hope this helps,
Lucas