query-5a1ae8d206e06b42778ace0f67762664

rq turtle/ttl

Tree view of images that use depicts (P180) and main subject (P921) and their values

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Tree
SELECT DISTINCT
  ?image
  ?imageLabel
  ?url
  ?property
  ?propertyLabel
  ?value
  ?valueLabel
# Subquery for getting images that have a "depict" (P180) and a
# "main subject" (P921) statements.
#
# A LIMIT is used to avoid searching all images in Wikimedia Commons
# since that requires a lot of time. The subquery stops searching
# when the given number of images are found. Change the number of
# LIMIT as needed, but note that the higher the number, the longer
# the subquery will take to finish.
{
   {
  SELECT DISTINCT ?image {
    ?image p:P180 [];
           p:P921 [].
  }
  LIMIT 10
}

  # Get the URL of the image so that a thumbnail is shown per each
  # image in #defaultView:Tree

  ?image schema:url ?url.

  # Get the properties that will be shown for each image

  {?image p:P921 [ ps:P921 ?value; ?ps [] ]}
  UNION
  {?image p:P180 [ ps:P180 ?value; ?ps [] ]}

  # Get the label of the properties and the items

  SERVICE <https://query.wikidata.org/sparql> {
    ?property wikibase:statementProperty ?ps.
    {
      SELECT ?property ?propertyLabel ?value ?valueLabel {
        SERVICE wikibase:label {bd:serviceParam wikibase:language "en"}.
      }
    }
  }

  SERVICE wikibase:label {bd:serviceParam wikibase:language "en"}.
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?image"):::projected v5("?property"):::projected v4("?ps") v2("?url"):::projected v3("?value"):::projected a1((" ")) a2((" ")) a4((" ")) a3((" ")) a5((" ")) a6((" ")) c9(["bd:serviceParam"]):::iri c11(["en"]):::literal v1 --"p:P180"--> a1 v1 --"p:P921"--> a2 v1 --"schema:url"--> v2 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; a5 --"p:statement/P180"--> v3 a5 -->v4--> a6 v1 --"p:P180"--> a5 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; a3 --"p:statement/P921"--> v3 a3 -->v4--> a4 v1 --"p:P921"--> a3 end union0r <== or ==> union0l end subgraph s1["https://query.wikidata.org/sparql"] style s1 stroke-width:4px; v5 --"wikibase:statementProperty"--> v4 subgraph s2["http://wikiba.se/ontology#label"] style s2 stroke-width:4px; c9 --"wikibase:language"--> c11 end end subgraph s2["http://wikiba.se/ontology#label"] style s2 stroke-width:4px; c9 --"wikibase:language"--> c11 end