1

I am trying to find all Wikidata items whose P18 property is an URL that has the word "Montage" anywhere in its filename.

Example:

enter image description here

I managed to find items by their complete P18 filename:

SELECT ?item
WHERE 
{
  ?item wdt:P18 <http://commons.wikimedia.org/wiki/Special:FilePath/Montage%20Columbus%201.jpg>.
}

But now I would like to add wildcards to that. My attempts with * and contains/regex all failed.

How to achieve that?

  • w.wiki/7gq 416 results – Stanislav Kralin Aug 30 at 19:15
  • 1
    @StanislavKralin: Wonderful, it works, thanks! And the hint:Query trick is gold. Feel free to post an answer containing the query, so that I can accept it. If not I will post and accept myself ^_^ – Nicolas Raoul Aug 31 at 6:21
  • please feel free to post an answer yourself! – Stanislav Kralin Sep 1 at 19:41
1

The trick is to use str inside the contains.

This query gives the expected result:

select ?item ?img
{
  hint:Query hint:maxParallel 400 .
  hint:Query hint:chunkSize  8000 .
  ?item wdt:P18 ?img . 
  filter contains(str(?img), "Montage")
}

Try it

Another way to achieve this is to set hint:Query hint:regexMatchNonString true and then use a normal regex.

(Huge thanks to Stanislav Kralin who found all this)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.