query-31b421d9f1376e64c7b0ec61647d2040

rq turtle/ttl

Most common values for "depicts" (P180) SELECT ?sum ?class ?class_label ?instance ?instance_label ?sample

WITH { SELECT (COUNT(DISTINCT(?file)) AS ?count) ?value (SAMPLE(?file) AS ?example) WHERE { service bd:sample { ?file wdt:P180 ?value . bd:serviceParam bd:sample.limit 1000 . bd:serviceParam bd:sample.sampleType "RANDOM" . }
} GROUP BY ?value ORDER BY DESC(?count)

LIMIT 2000

} AS %values

WITH { SELECT (SUM(?count) AS ?sum) ?class (SAMPLE(?value) AS ?instance) (SAMPLE(?example) AS ?sample) WHERE { INCLUDE %values . service https://query.wikidata.org/sparql { ?value wdt:P31 ?class } } GROUP BY ?class } AS %classes

WHERE { INCLUDE %classes . service https://query.wikidata.org/sparql { OPTIONAL {?instance rdfs:label ?instance_label FILTER (lang(?instance_label) = 'en') } . OPTIONAL {?class rdfs:label ?class_label FILTER (lang(?class_label) = 'en') } . } } ORDER BY DESC(?sum)

Use at

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Most common values for "depicts" (P180)
SELECT ?sum ?class ?class_label ?instance ?instance_label ?sample



WHERE {
   {
  SELECT (SUM(?count) AS ?sum) ?class (SAMPLE(?value) AS ?instance) (SAMPLE(?example) AS ?sample) WHERE {
     { 
  SELECT (COUNT(DISTINCT(?file)) AS ?count) ?value (SAMPLE(?file) AS ?example) WHERE {
     service bd:sample {
       ?file wdt:P180 ?value . 
        bd:serviceParam bd:sample.limit 1000 .
        bd:serviceParam bd:sample.sampleType "RANDOM" .
     }  
  } GROUP BY ?value
  ORDER BY DESC(?count)
#  LIMIT 2000           
}.
    service <https://query.wikidata.org/sparql> {
         ?value wdt:P31 ?class
    }
  } GROUP BY ?class 
}. 
  service <https://query.wikidata.org/sparql> {
      OPTIONAL {?instance rdfs:label ?instance_label FILTER (lang(?instance_label) = 'en') } .
      OPTIONAL {?class rdfs:label ?class_label FILTER (lang(?class_label) = 'en') } .
  }
} 
ORDER BY DESC(?sum)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?class"):::projected v9("?class_label"):::projected v5("?count") v5("?example") v3("?file") v7("?instance"):::projected v10("?instance_label"):::projected v8("?sample"):::projected v7("?sum"):::projected v4("?value") c3(["bd:serviceParam"]):::iri c7(["RANDOM"]):::literal c5(["1000^^xsd:integer"]):::literal subgraph s1["http://www.bigdata.com/rdf#sample"] style s1 stroke-width:4px; v3 --"wdt:P180"--> v4 c3 --"bd:sample.limit"--> c5 c3 --"bd:sample.sampleType"--> c7 end bind2[/"count(?file)"/] v3 --o bind2 bind2 --as--o v5 bind3[/"sample(?file)"/] v3 --o bind3 bind3 --as--o v5 subgraph s2["https://query.wikidata.org/sparql"] style s2 stroke-width:4px; v4 --"wdt:P31"--> v6 end bind7[/"sum(?count)"/] v5 --o bind7 bind7 --as--o v7 bind8[/"sample(?value)"/] v4 --o bind8 bind8 --as--o v7 bind9[/"sample(?example)"/] v5 --o bind9 bind9 --as--o v8 subgraph s2["https://query.wikidata.org/sparql"] style s2 stroke-width:4px; subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v7 -."rdfs:label".-> v10 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v6 -."rdfs:label".-> v9 end end