This is very strange. Commons Media values are not supposed to be strings in RDF – the documentation <https://www.mediawiki.org/wiki/Wikibase/Indexing/RDF_Dump_Format#Commons_media> 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. } str isIri http://commons.wikimedia.org/wiki/Special:FilePath/GuentherZ%202010-02-27%200207%20Wien10%20Scheunenstrasse2%20Bildstock.jpg true (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 <https://phabricator.wikimedia.org/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 Am Mo., 6. Juli 2020 um 18:34 Uhr schrieb Stephan Bösch-Plepelits < sk...@xover.mud.at>: > Hi! > > I have a problem with a SPARQL query. Hopefully you can help me. > > I'd like to get wikidata articles which use a specific image in the P18 > property. I'm using this simple query: > SELECT ?item WHERE { ?item wdt:P18 "item.jpg". } > > This works for some items, but not all. > > Example 1: > SELECT ?item > WHERE { ?item wdt:P18 "1936-ChirkovAntonNikolaevich.jpg". } > -> returns "wd:Q16718402" (https://www.wikidata.org/wiki/Q16718402) > > Example 2: > SELECT ?item > WHERE { ?item wdt:P18 "GuentherZ 2010-02-27 0207 Wien10 Scheunenstrasse2 > Bildstock.jpg". } > -> returns nothing, although it is used by > https://www.wikidata.org/wiki/Q33231166 > > This might be related to the following fact: > > Example 1A: > SELECT ?item ?image > WHERE { > ?item wdt:P18 ?image. > ?item wdt:P214 "307433452". > } > -> the field "image" shows a string "1936-ChirkovAntonNikolaevich.jpg" > > Example 2A: > SELECT ?item ?foo > WHERE { > ?item wdt:P18 ?image. > ?item wdt:P2951 "86578". > } > -> the field "image" shows a link to > > https://commons.wikimedia.org/wiki/File:GuentherZ%202010-02-27%200207%20Wien10%20Scheunenstrasse2%20Bildstock.jpg > with the text "commons:GuentherZ 2010-02-27 0207 Wien10 Scheunenstrasse2 > Bildstock.jpg" > > (I also tried prefixing the query image name by 'commons:', like "?item > wdt:P18 "commons:image.jpg") > > Please tell me if you have an idea how to solve this problem! > > greetings, > Stephan > -- > Seid unbequem, seid Sand, nicht Öl im Getriebe der Welt! - Günther Eich > ,----------------------------------------------------------------------. > | Stephan Bösch-Plepelits ❤ code ❤ urbanism ❤ free software ❤ cycling | > | Projects: | > | > OpenStreetMap: openstreetbrowser.org > openstreetmap.at | > | > Urbanism: Radlobby Wien > Platz für Wien | > | Contact: | > | > Mail: sk...@xover.mud.at > Blog: plepe.at > Code: github.com/plepe | > | > Twitter: twitter.com/plepe > Jabber: sk...@jabber.at | > | > Mastodon: @pl...@en.osm.town | > `----------------------------------------------------------------------' > > _______________________________________________ > Wikidata-tech mailing list > Wikidata-tech@lists.wikimedia.org > https://lists.wikimedia.org/mailman/listinfo/wikidata-tech > -- Lucas Werkmeister (he/er) Full Stack Developer Wikimedia Deutschland e. V. | Tempelhofer Ufer 23-24 | 10963 Berlin Phone: +49 (0)30 219 158 26-0 https://wikimedia.de Imagine a world in which every single human being can freely share in the sum of all knowledge. Help us to achieve our vision! https://spenden.wikimedia.de Wikimedia Deutschland - Gesellschaft zur Förderung Freien Wissens e. V. Eingetragen im Vereinsregister des Amtsgerichts Berlin-Charlottenburg unter der Nummer 23855 B. Als gemeinnützig anerkannt durch das Finanzamt für Körperschaften I Berlin, Steuernummer 27/029/42207.
_______________________________________________ Wikidata-tech mailing list Wikidata-tech@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikidata-tech