query-56e94d1d196518bff09143c195453e56
EpicPupper
Use at
- https://query.wikidata.org/sparql
PREFIX mwapi: <http://wikiba.se/ontology#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?P18_value ?contentUrl
WHERE
{
SERVICE <https://query.wikidata.org/sparql>
{
SERVICE wikibase:mwapi
{
bd:serviceParam wikibase:endpoint "commons.wikipedia.org" .
bd:serviceParam wikibase:api "Generator" .
bd:serviceParam mwapi:generator "categorymembers" .
bd:serviceParam mwapi:gcmtitle "Category:Portraits of men with moustaches" .
bd:serviceParam mwapi:gcmlimit "max" .
bd:serviceParam mwapi:gcmnamespace "6" .
?category_member wikibase:apiOutput mwapi:title.
}
BIND (SUBSTR(STR(?category_member), 6) AS ?filename)
BIND (URI(CONCAT("http://commons.wikimedia.org/wiki/Special:FilePath/", ENCODE_FOR_URI(?filename))) AS ?P18_value)
OPTIONAL { ?stm ps:P18 ?P18_value . }
FILTER BOUND (?stm)
BIND (REPLACE(?filename, " ", "_") AS ?filename_)
BIND (MD5(?filename_) AS ?MD5)
BIND (URI(CONCAT("https://upload.wikimedia.org/wikipedia/commons/",
SUBSTR(?MD5, 1, 1), "/",
SUBSTR(?MD5, 1, 2), "/", ENCODE_FOR_URI(?filename_)
)
) AS ?contentUrl)
}
FILTER NOT EXISTS { ?file schema:contentUrl ?contentUrl . }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?MD5")
v6("?P18_value"):::projected
v4("?category_member")
v9("?contentUrl"):::projected
v1("?file")
v5("?filename")
v7("?filename_")
v3("?stm")
c6(["commons.wikipedia.org"]):::literal
c12(["Category:Portraits of men with moustaches"]):::literal
c14(["max"]):::literal
c10(["categorymembers"]):::literal
c4(["bd:serviceParam"]):::iri
c16(["6"]):::literal
c18(["mwapi:title"]):::iri
c8(["Generator"]):::literal
f0[["not "]]
subgraph f0e0["Exists Clause"]
e0v1 --"schema:contentUrl"--> e0v2
e0v2("?contentUrl"):::projected
e0v1("?file"):::projected
end
f0--EXISTS--> f0e0
f0 --> v1
f0 --> c1
f0 --> v9
v1 --"schema:contentUrl"--> v9
subgraph s1["https://query.wikidata.org/sparql"]
style s1 stroke-width:4px;
f1[["bound(?stm)"]]
f1 --> v3
subgraph s2["http://wikiba.se/ontology#mwapi"]
style s2 stroke-width:4px;
c4 --"mwapi:endpoint"--> c6
c4 --"mwapi:api"--> c8
c4 --"mwapi:generator"--> c10
c4 --"mwapi:gcmtitle"--> c12
c4 --"mwapi:gcmlimit"--> c14
c4 --"mwapi:gcmnamespace"--> c16
v4 --"mwapi:apiOutput"--> c18
end
bind2[/"substring(str(?category_member),'6^^xsd:integer')"/]
v4 --o bind2
bind2 --as--o v5
bind3[/"concat('http://commons.wikimedia.org/wiki/Special:FilePath/',encode-for-uri(?filename))"/]
v5 --o bind3
bind3 --as--o v6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."ps:P18".-> v6
end
bind4[/"replace(?filename,' ','_')"/]
v5 --o bind4
bind4 --as--o v7
bind5[/"MD5(?filename_)"/]
v7 --o bind5
bind5 --as--o v8
bind6[/"concat('https://upload.wikimedia.org/wikipedia/commons/',substring(?MD5,'1^^xsd:integer','1^^xsd:integer'),'/',substring(?MD5,'1^^xsd:integer','2^^xsd:integer'),'/',encode-for-uri(?filename_))"/]
v8 --o bind6
v7 --o bind6
bind6 --as--o v9
end