query-25f6c7b3793bf7f3d7b3ebab23ca6987

rq turtle/ttl

sorting labels with an WITH and INCLUDEThis is a cut down version of a much more complicated query, which for speed is coded this way with include logic that is actually more complicated

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 DISTINCT ?item 
  (GROUP_CONCAT(DISTINCT ?classlist;    SEPARATOR = "#") AS ?classes)
  WHERE {
  {
    SELECT DISTINCT ?item ?class ?classLabel WHERE {
      {
        SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
        { {SELECT ?item WHERE {
VALUES ?item {
  wd:Q820477   # mine
}

} }}

        OPTIONAL {
                {?item wdt:P279 ?class}
          UNION {?class wdt:P279 ?item.
            OPTIONAL {?item wdt:P31 ?instance1}
            OPTIONAL {?class wdt:P31 ?instance2}
            FILTER (!(BOUND(?instance1) && BOUND(?instance2) && ?instance1 != ?instance2))
          }
        }
      }
    }
  }
  BIND(CONCAT(?classLabel) AS ?classlist)
}
GROUP BY ?item
ORDER BY ASC(?classes)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?class") v7("?classes") v6("?classlist"):::projected v4("?instance1") v5("?instance2") v2("?item"):::projected c2(["bd:serviceParam"]):::iri c4(["en"]):::literal subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c4 end bind0[/VALUES ?item/] bind0-->v2 bind00(["wd:Q820477"]) bind00 --> bind0 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; f1[["not bound(?instance1)bound(?instance2)?instance1 != ?instance2"]] f1 --> v4 f1 --> v5 v3 -."wdt:P279".-> v2 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."wdt:P31".-> v4 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v3 -."wdt:P31".-> v5 end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v2 --"wdt:P279"--> v3 end union0r <== or ==> union0l end end bind2[/"concat(?classLabel)"/] null --o bind2 bind2 --as--o v6 bind4[/"?classlist"/] v6 --o bind4 bind4 --as--o v7