query-782b9d47abce7597efc12fad45819ae2

rq turtle/ttl

most common class combinations of items linked via “different from” statements SELECT ?class1 ?class2 ?class1Label ?class2Label ?count WITH { SELECT ?class1 ?class2 (COUNT(*) AS ?count) WHERE { ?item1 wdt:P1889 ?item2. OPTIONAL { ?item1 wdt:P31 ?class1. } OPTIONAL { ?item2 wdt:P31 ?class2. } FILTER(!BOUND(?class1) || !BOUND(?class2) || STR(?class1) <= STR(?class2)) } GROUP BY ?class1 ?class2 ORDER BY DESC(?count) LIMIT 50 } AS %results WHERE { INCLUDE %results. SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY DESC(?count)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# most common class combinations of items linked via “different from” statements
SELECT ?class1 ?class2 ?class1Label ?class2Label ?count WHERE {
   {
  SELECT ?class1 ?class2 (COUNT(*) AS ?count) WHERE {
    ?item1 wdt:P1889 ?item2.
    OPTIONAL { ?item1 wdt:P31 ?class1. }
    OPTIONAL { ?item2 wdt:P31 ?class2. }
    FILTER(!BOUND(?class1) || !BOUND(?class2) || STR(?class1) <= STR(?class2))
  }
  GROUP BY ?class1 ?class2
  ORDER BY DESC(?count)
  LIMIT 50
}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?count)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?class1"):::projected v3("?class2"):::projected v6("?count"):::projected v4("?item1") v5("?item2") c4(["bd:serviceParam"]):::iri c6(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["(not bound(?class1) || (not bound(?class2) || str(?class1) <= str(?class2)))"]] f0 --> v2 f0 --> v3 v4 --"wdt:P1889"--> v5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."wdt:P31".-> v2 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v5 -."wdt:P31".-> v3 end bind2[/"count(*)"/] bind2 --as--o v6 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c4 --"wikibase:language"--> c6 end