query-473933a3eb25e15431d3eab4f3d7413d

rq turtle/ttl

TODO

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?category ?wiki ?wikiLabel ?topic ?topicLabel {
  {
    SELECT DISTINCT ?wiki (COALESCE(SAMPLE(?topic), '?') as ?topic) {
      ?wiki wdt:P31/wdt:P279* wd:Q15633582.
      OPTIONAL {?wiki wdt:P921 ?topic}
      FILTER NOT EXISTS  { ?wiki wdt:P31/wdt:P279* wd:Q33120876 }
    } GROUP BY ?wiki
  }

  BIND(
    IF(?topic != '?',
      IF(EXISTS {?topic wdt:P31 wd:Q7889} || EXISTS {?topic wdt:P31 wd:Q7058673} || EXISTS {?topic wdt:P31 wd:Q1121542}, 'game',
      IF(EXISTS {?topic wdt:P31 wd:Q196600}, 'franchise',
     '(unknown category)'
      )),
    '(no topic)'
    ) as ?category)

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ?category

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?_anon_d00291b7e9a143df8ec0be8c8ebd714c144805") v5("?category"):::projected v5("?topic"):::projected v2("?wiki"):::projected a2((" ")) a1((" ")) c7(["bd:serviceParam"]):::iri c4(["wd:Q15633582"]):::iri c9(["#91;AUTO_LANGUAGE#93;,en"]):::literal c3(["wd:Q33120876"]):::iri f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"wdt:P31"--> e0a1 e0a1 --"wdt:P279"--> e0c3 e0v1("?wiki"):::projected e0a1((" ")):::projected e0c3(["wd:Q33120876"]):::iri end f0--EXISTS--> f0e0 f0 --> v2 f0 --> c1 f0 --> a1 f0 --> c2 f0 --> c3 v2 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c3 v2 --"wdt:P31"--> a2 a2 --"wdt:P279"--> c4 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P921".-> v5 end bind2[/"sample(?topic)"/] v5 --o bind2 bind2 --as--o v4 bind3[/"'?'"/] null --o bind3 bind3 --as--o v5 v5 --"wdt:P31"--> null v5 --"wdt:P31"--> null v5 --"wdt:P31"--> null v5 --"wdt:P31"--> null bind4[/"if(?topic != '?',if(( || ( || )),'game',if( ,'franchise','(unknown category)')),'(no topic)')"/] subgraph bind4e1["Exists Clause"] e1v1 --"wdt:P31"--> e1c2 e1v1("?topic"):::projected e1c2(["wd:Q7889"]):::iri end bind4--EXISTS--> bind4e1 subgraph bind4e2["Exists Clause"] e2v1 --"wdt:P31"--> e2c2 e2v1("?topic"):::projected e2c2(["wd:Q7058673"]):::iri end bind4--EXISTS--> bind4e2 subgraph bind4e3["Exists Clause"] e3v1 --"wdt:P31"--> e3c2 e3v1("?topic"):::projected e3c2(["wd:Q1121542"]):::iri end bind4--EXISTS--> bind4e3 subgraph bind4e4["Exists Clause"] e4v1 --"wdt:P31"--> e4c2 e4v1("?topic"):::projected e4c2(["wd:Q196600"]):::iri end bind4--EXISTS--> bind4e4 v5 --o bind4 c1 --o bind4 null --o bind4 null --o bind4 null --o bind4 null --o bind4 bind4 --as--o v5 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c7 --"wikibase:language"--> c9 end