query-71c3e9349ef2921339da372e5cc58ef3

rq turtle/ttl

TODO

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?item  ?discog (GROUP_CONCAT(DISTINCT ?identifier) as ?identifiers)  WHERE {
BIND( xsd:integer( STRAFTER( STR( ?item ), STR( wd:Q ) ) ) AS ?qid )
  ?item wdt:P31/wdt:P279* wd:Q188451.
#  OPTIONAL {?item wdt:P17 ?p17.} .
#  OPTIONAL {?item wdt:P495 ?p495.} .
  OPTIONAL {?item wdt:P9218 ?DgID. BIND(CONCAT("[https://www.discogs.com/genre/",?DgID," gID]") as ?DgIDurl)}
  OPTIONAL {?item wdt:P9219 ?DsID. BIND(CONCAT("[https://www.discogs.com/genre/",?DsID," sID]") as ?DsIDurl)}
  BIND(IF(BOUND(?DgIDurl) && BOUND(?DsIDurl),concat(?DgIDurl," ",?DsIDurl),"") as ?discog)
  OPTIONAL { 
    # Get external identifiers
    ?item ?prop ?id.
    ?propItem wikibase:directClaim ?prop.
    ?propItem wikibase:propertyType wikibase:ExternalId.
    ?propItem wdt:P31 wd:Q105672006 .
    ?propItem wdt:P1630 ?formatterurl . 
    ?propItem rdfs:label ?propItemLabel .
    filter (?propItem NOT IN (wd:P9218, wd:P9219))     
    FILTER (lang(?propItemLabel) = "en"). 
#  RYM genre ID link (P9173) and MusicBrainz ID link (P8052)
    BIND(IRI(REPLACE(?id, '^(.+)$', ?formatterurl)) AS ?url).
    BIND(IF(CONTAINS(str(?propItem),"P9173"),
      CONCAT("[", str(?url), " rymID]"),
      IF(CONTAINS(str(?propItem),"P8052"),
         CONCAT("[", str(?url), " mbID]"),
         CONCAT("[", str(?url), " ", ?propItemLabel, "]"))) as ?identifier)           
  } 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} group by ?item ?discog
 order by ?qid

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v5("?DgID") v6("?DgIDurl") v7("?DsID") v8("?DsIDurl") v9("?discog"):::projected v12("?formatterurl") v11("?id") v14("?identifier"):::projected v15("?identifiers") v4("?item"):::projected v10("?prop") v2("?propItem") v3("?propItemLabel") v4("?qid") v13("?url") a1((" ")) c11(["wikibase:ExternalId"]):::iri c12(["wd:Q105672006"]):::iri c16(["bd:serviceParam"]):::iri c6(["wd:Q188451"]):::iri c18(["#91;AUTO_LANGUAGE#93;,en"]):::literal bind0[/"http://www.w3.org/2001/XMLSchema#integer(substring-after(str(?item),str('wd:Q')))"/] v4 --o bind0 bind0 --as--o v4 v4 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c6 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."wdt:P9218".-> v5 bind1[/"concat('#91;https://www.discogs.com/genre/',?DgID,' gID#93;')"/] v5 --o bind1 bind1 --as--o v6 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v4 -."wdt:P9219".-> v7 bind2[/"concat('#91;https://www.discogs.com/genre/',?DsID,' sID#93;')"/] v7 --o bind2 bind2 --as--o v8 end bind3[/"if(bound(?DgIDurl)bound(?DsIDurl),concat(?DgIDurl,' ',?DsIDurl),'')"/] v6 --o bind3 v8 --o bind3 bind3 --as--o v9 subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v4 -->v10--> v11 v2 -."wikibase:directClaim".-> v10 v2 --"wikibase:propertyType"--> c11 v2 --"wdt:P31"--> c12 v2 --"wdt:P1630"--> v12 v2 --"rdfs:label"--> v3 bind4[/"replace(?id,'^(.+)$',?formatterurl)"/] v11 --o bind4 v12 --o bind4 bind4 --as--o v13 bind5[/"if(contains(str(?propItem),'P9173'),concat('#91;',str(?url),' rymID#93;'),if(contains(str(?propItem),'P8052'),concat('#91;',str(?url),' mbID#93;'),concat('#91;',str(?url),' ',?propItemLabel,'#93;')))"/] v2 --o bind5 v13 --o bind5 v3 --o bind5 bind5 --as--o v14 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c16 --"wikibase:language"--> c18 end bind7[/"?identifier"/] v14 --o bind7 bind7 --as--o v15