query-5f58a91715bcc03035b976199e55a2bc

rq turtle/ttl

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

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT
  ?image
  ?mainSubjects
  ?depicts
# 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.
#
# Get value of "depict" statements
#
#
# Get value of the "main subject" statements
#
#
# Concatenate the "depict" statements
#
#
# Concatenate the "main subject" statements
#
{
   {
  SELECT
    ?image
    (GROUP_CONCAT(DISTINCT CONCAT(?depictLabel, " (", ?depictQid, ")"); SEPARATOR = ', ') AS ?depicts)
  {
     {
  SELECT DISTINCT ?image ?depict {
    INCLUDE %0.
    ?image p:P180 [ps:P180 ?depict].
  }
}

    BIND(SUBSTR(STR(?depict), 32) AS ?depictQid).

    SERVICE <https://query.wikidata.org/sparql> {
      SELECT ?depict ?depictLabel {
        SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
      }
    }
  }
  GROUP BY ?image
}
   {
  SELECT
    ?image
    (GROUP_CONCAT(DISTINCT CONCAT(?mainSubjectLabel, " (", ?mainSubjectQid, ")"); SEPARATOR = ', ') AS ?mainSubjects)
  {
     {
  SELECT DISTINCT ?image ?mainSubject {
    INCLUDE %0.
    ?image p:P921 [ps:P921 ?mainSubject].
  }
}

    BIND(SUBSTR(STR(?mainSubject), 32) AS ?mainSubjectQid).

    SERVICE <https://query.wikidata.org/sparql> {
      SELECT ?mainSubject ?mainSubjectLabel {
        SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
      }
    }
  }
  GROUP BY ?image
}
}

Query found at