query-3d7c50c1d115c8cc29247a0b7822a74a

rq turtle/ttl

Vojtěch Dostál

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
SELECT (COUNT(DISTINCT ?image) AS ?images) (COUNT(DISTINCT ?file) AS ?files)
WHERE
{

{
  SELECT ?item ?image ?filename ?contentUrl
  WHERE
  {
    SERVICE <https://query.wikidata.org/sparql>
    {
      ?item wdt:P31 wd:Q5153359 .
      ?item wdt:P18 ?image .
    }
    BIND (REPLACE(wikibase:decodeUri(SUBSTR(STR(?image), 52)), " ", "_") AS ?filename)
    BIND (REPLACE(SUBSTR(STR(?image), 52), "%20", "_") AS ?filenameUnencoded)
    BIND (MD5(?filename) AS ?MD5)
    BIND (URI(CONCAT("https://upload.wikimedia.org/wikipedia/commons/", SUBSTR(?MD5, 1, 1), "/", SUBSTR(?MD5, 1, 2), "/", ?filenameUnencoded)) As ?contentUrl)
  }
}  OPTIONAL { ?file schema:contentUrl ?contentUrl . }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?MD5") v6("?contentUrl") v7("?file"):::projected v3("?filename") v4("?filenameUnencoded") v9("?files") v2("?image"):::projected v8("?images") v1("?item") c3(["wd:Q5153359"]):::iri subgraph s1["https://query.wikidata.org/sparql"] style s1 stroke-width:4px; v1 --"wdt:P31"--> c3 v1 --"wdt:P18"--> v2 end bind0[/"replace(http://wikiba.se/ontology#decodeUri(substring(str(?image),'52^^xsd:integer')),' ','_')"/] v2 --o bind0 bind0 --as--o v3 bind1[/"replace(substring(str(?image),'52^^xsd:integer'),'%20','_')"/] v2 --o bind1 bind1 --as--o v4 bind2[/"MD5(?filename)"/] v3 --o bind2 bind2 --as--o v5 bind3[/"concat('https://upload.wikimedia.org/wikipedia/commons/',substring(?MD5,'1^^xsd:integer','1^^xsd:integer'),'/',substring(?MD5,'1^^xsd:integer','2^^xsd:integer'),'/',?filenameUnencoded)"/] v5 --o bind3 v4 --o bind3 bind3 --as--o v6 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v7 -."schema:contentUrl".-> v6 end bind6[/"count(?image)"/] v2 --o bind6 bind6 --as--o v8 bind7[/"count(?file)"/] v7 --o bind7 bind7 --as--o v9