query-16171f1a62dc7476e8caf295e44ece6e

rq turtle/ttl

Relations between images on Wikimedia Commons, Wikidata and KB website - for files in Category:Flora Batava - KB copy, Volume 1, 1800 SELECT DISTINCT ?title ?url ?depicts ?depictsLabel ?depictsIsALabel ?digrepofLabel ?mainsubject ?mainsubjectLabel ?mainsubjectIsALabel ?kbsourceurl WITH { SELECT ?file ?title WHERE { SERVICE wikibase:mwapi { bd:serviceParam wikibase:api "Generator" . bd:serviceParam wikibase:endpoint "commons.wikimedia.org" . bd:serviceParam mwapi:gcmtitle "Category:Flora Batava - KB copy, Volume 1, 1800" . bd:serviceParam mwapi:generator "categorymembers" . bd:serviceParam mwapi:gcmtype "file" . bd:serviceParam mwapi:gcmlimit "max" . ?title wikibase:apiOutput mwapi:title . ?pageid wikibase:apiOutput "@pageid" . } BIND (URI(CONCAT('https://commons.wikimedia.org/entity/M', ?pageid)) AS ?file) } } AS %get_files WHERE { INCLUDE %get_files ?file schema:url ?url.

OPTIONAL {?file wdt:P180 ?depicts. SERVICE https://query.wikidata.org/sparql { ?depicts rdfs:label ?depictsLabel FILTER (lang(?depictsLabel) = "en"). ?depicts wdt:P31 ?depictsIsA. FILTER (?depictsIsA = wd:Q11060274) # ?depicts must be instance of print/Q11060274 ?depictsIsA rdfs:label ?depictsIsALabel FILTER (lang(?depictsIsALabel) = "en").} }

OPTIONAL {?file wdt:P6243 ?digrepof. #digital representation of SERVICE https://query.wikidata.org/sparql { ?digrepof rdfs:label ?digrepofLabel FILTER (lang(?digrepofLabel) = "en").} }

OPTIONAL {?file wdt:P921 ?mainsubject. SERVICE https://query.wikidata.org/sparql { ?mainsubject rdfs:label ?mainsubjectLabel FILTER (lang(?mainsubjectLabel) = "la"). ?mainsubject wdt:P31 ?mainsubjectIsA. FILTER (?mainsubjectIsA = wd:Q16521) # ?mainsubject must be instance of taxon/Q16521 ?mainsubjectIsA rdfs:label ?mainsubjectIsALabel FILTER (lang(?mainsubjectIsALabel) = "en").} }

OPTIONAL {?file p:P7482 [ps:P7482 ?source; pq:P973 ?kbsourceurl].} } ORDER BY DESC (?depictsLabel)

Use at

PREFIX mwapi: <http://wikiba.se/ontology#>
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/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Relations between images on Wikimedia Commons, Wikidata and KB website - for files in Category:Flora Batava - KB copy, Volume 1, 1800
SELECT DISTINCT ?title ?url
?depicts ?depictsLabel ?depictsIsALabel
?digrepofLabel 
?mainsubject ?mainsubjectLabel ?mainsubjectIsALabel 
?kbsourceurl
WHERE
{

{
  SELECT ?file ?title
  WHERE
  {
   SERVICE wikibase:mwapi
    {
    bd:serviceParam wikibase:api "Generator" .
    bd:serviceParam wikibase:endpoint "commons.wikimedia.org" .
    bd:serviceParam mwapi:gcmtitle "Category:Flora Batava - KB copy, Volume 1, 1800" .
    bd:serviceParam mwapi:generator "categorymembers" .
    bd:serviceParam mwapi:gcmtype "file" .
    bd:serviceParam mwapi:gcmlimit "max" .
    ?title wikibase:apiOutput mwapi:title .
    ?pageid wikibase:apiOutput "@pageid" .
    }
    BIND (URI(CONCAT('https://commons.wikimedia.org/entity/M', ?pageid)) AS ?file)
  }
}  ?file schema:url ?url.

  OPTIONAL {?file wdt:P180 ?depicts.
    SERVICE <https://query.wikidata.org/sparql> {
      ?depicts rdfs:label ?depictsLabel FILTER (lang(?depictsLabel) = "en").
      ?depicts wdt:P31 ?depictsIsA.
      FILTER (?depictsIsA = wd:Q11060274)  # ?depicts must be instance of print/Q11060274
      ?depictsIsA rdfs:label ?depictsIsALabel FILTER (lang(?depictsIsALabel) = "en").}
    }

  OPTIONAL {?file wdt:P6243 ?digrepof. #digital representation of
    SERVICE <https://query.wikidata.org/sparql> {
      ?digrepof rdfs:label ?digrepofLabel FILTER (lang(?digrepofLabel) = "en").}
    }

  OPTIONAL {?file wdt:P921 ?mainsubject.
    SERVICE <https://query.wikidata.org/sparql> { 
      ?mainsubject rdfs:label ?mainsubjectLabel FILTER (lang(?mainsubjectLabel) = "la").
      ?mainsubject wdt:P31 ?mainsubjectIsA. 
      FILTER (?mainsubjectIsA = wd:Q16521) # ?mainsubject must be instance of taxon/Q16521
      ?mainsubjectIsA rdfs:label ?mainsubjectIsALabel FILTER (lang(?mainsubjectIsALabel) = "en").}
    }

  OPTIONAL {?file p:P7482 [ps:P7482 ?source; pq:P973 ?kbsourceurl].}
}
ORDER BY DESC (?depictsLabel)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?depicts"):::projected v8("?depictsIsA") v7("?depictsIsALabel"):::projected v1("?depictsLabel"):::projected v9("?digrepof") v10("?digrepofLabel"):::projected v4("?file") v16("?kbsourceurl"):::projected v11("?mainsubject"):::projected v13("?mainsubjectIsA") v12("?mainsubjectIsALabel"):::projected v14("?mainsubjectLabel"):::projected v3("?pageid") v15("?source") v2("?title"):::projected v5("?url"):::projected a1((" ")) c2(["bd:serviceParam"]):::iri c12(["file"]):::literal c6(["commons.wikimedia.org"]):::literal c17(["@pageid"]):::literal c14(["max"]):::literal c10(["categorymembers"]):::literal c8(["Category:Flora Batava - KB copy, Volume 1, 1800"]):::literal c16(["mwapi:title"]):::iri c4(["Generator"]):::literal subgraph s1["http://wikiba.se/ontology#mwapi"] style s1 stroke-width:4px; c2 --"mwapi:api"--> c4 c2 --"mwapi:endpoint"--> c6 c2 --"mwapi:gcmtitle"--> c8 c2 --"mwapi:generator"--> c10 c2 --"mwapi:gcmtype"--> c12 c2 --"mwapi:gcmlimit"--> c14 v2 --"mwapi:apiOutput"--> c16 v3 --"mwapi:apiOutput"--> c17 end bind0[/"concat('https://commons.wikimedia.org/entity/M',?pageid)"/] v3 --o bind0 bind0 --as--o v4 v4 --"schema:url"--> v5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P180".-> v6 subgraph s2["https://query.wikidata.org/sparql"] style s2 stroke-width:4px; f1[["?depictsIsALabel = 'en'"]] f1 --> v7 f2[["?depictsIsA = 'wd:Q11060274'"]] f2 --> v8 f3[["?depictsLabel = 'en'"]] f3 --> v1 v6 --"rdfs:label"--> v1 v6 --"p:direct/P31"--> v8 v8 --"rdfs:label"--> v7 end end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P6243".-> v9 subgraph s2["https://query.wikidata.org/sparql"] style s2 stroke-width:4px; f4[["?digrepofLabel = 'en'"]] f4 --> v10 v9 --"rdfs:label"--> v10 end end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v4 -."p:direct/P921".-> v11 subgraph s2["https://query.wikidata.org/sparql"] style s2 stroke-width:4px; f5[["?mainsubjectIsALabel = 'en'"]] f5 --> v12 f6[["?mainsubjectIsA = 'wd:Q16521'"]] f6 --> v13 f7[["?mainsubjectLabel = 'la'"]] f7 --> v14 v11 --"rdfs:label"--> v14 v11 --"p:direct/P31"--> v13 v13 --"rdfs:label"--> v12 end end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; a1 -."p:statement/P7482".-> v15 a1 --"p:qualifier/P973"--> v16 v4 --"p:P7482"--> a1 end