query-d4f47868abcb388e621aa210a238958a

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  (GROUP_CONCAT(DISTINCT ?discog) as ?discogs)  (GROUP_CONCAT(DISTINCT ?rymurl) as ?rym_url) (GROUP_CONCAT(DISTINCT ?mburl) as ?mb_url) (GROUP_CONCAT(DISTINCT ?amurl) as ?am_url)  (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. 
            # wd:P9218 rdfs:label ?propItemLabelg . FILTER (lang(?propItemLabelg) = "en"). 
            BIND(CONCAT("[https://www.discogs.com/genre/",?DgID," ",?DgID,"]") as ?DgIDurl)}
  OPTIONAL {?item wdt:P9219 ?DsID. 
            # wd:P9219 rdfs:label ?propItemLabels . FILTER (lang(?propItemLabels) = "en"). 
            BIND(CONCAT("[https://www.discogs.com/style/",?DsID," ",?DsID,"]") as ?DsIDurl)}
  BIND(IF(BOUND(?DgIDurl) && BOUND(?DsIDurl),concat(?DgIDurl," ",?DsIDurl),
          IF(BOUND(?DgIDurl),?DgIDurl,
            IF(BOUND(?DsIDurl),?DsIDurl,""))) as ?discog) 
  OPTIONAL {?item wdt:P9173 ?rymID. BIND(REPLACE(?rymID," ","%20") as ?rymID1)
            BIND(REPLACE(?rymID1,"%5B","[") as ?rymID2)
            BIND(REPLACE(?rymID2,"%5D","]") as ?rymID_fix)
            # wd:P9173 rdfs:label ?propItemLabelrym . FILTER (lang(?propItemLabelrym) = "en"). 
            BIND(CONCAT("[https://rateyourmusic.com/genre/",?rymID_fix," ",?rymID_fix,"]") as ?rymurl)}
  OPTIONAL {?item wdt:P8052 ?mbID. 
            wd:P8052 rdfs:label ?propItemLabelmb . FILTER (lang(?propItemLabelmb) = "en"). 
            BIND(CONCAT("[https://musicbrainz.org/genre/",?mbID," ID]") as ?mburl)}
  OPTIONAL {?item wdt:P9185 ?amID. 
            wd:P9185 rdfs:label ?propItemLabelam . FILTER (lang(?propItemLabelam) = "en"). 
            BIND(CONCAT("[https://www.allmusic.com/style/",?amID," ID]") as ?amurl)}
  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, wd:P9173, wd:P8052, wd:P9185))     
    FILTER (lang(?propItemLabel) = "en"). 
    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

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v9("?DgID") v10("?DgIDurl") v11("?DsID") v12("?DsIDurl") v21("?amID") v31("?am_url") v22("?amurl"):::projected v13("?discog"):::projected v28("?discogs") v25("?formatterurl") v24("?id") v27("?identifier"):::projected v32("?identifiers") v6("?item"):::projected v19("?mbID") v30("?mb_url") v20("?mburl"):::projected v7("?p17") v8("?p495") v23("?prop") v1("?propItem") v2("?propItemLabel") v3("?propItemLabelam") v4("?propItemLabelmb") v5("?qid") v14("?rymID") v15("?rymID1") v16("?rymID2") v17("?rymID_fix") v29("?rym_url") v18("?rymurl"):::projected v26("?url") a1((" ")) c24(["bd:serviceParam"]):::iri c20(["wikibase:ExternalId"]):::iri c21(["wd:Q105672006"]):::iri c9(["wd:Q188451"]):::iri c4(["wd:P8052"]):::iri c5(["wd:P9185"]):::iri c26(["#91;AUTO_LANGUAGE#93;,en"]):::literal bind0[/"http://www.w3.org/2001/XMLSchema#integer(substring-after(str(?item),str('wd:Q')))"/] v6 --o bind0 bind0 --as--o v5 v6 --"wdt:P31"--> a1 a1 --"wdt:P279"--> c9 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v6 -."wdt:P17".-> v7 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v6 -."wdt:P495".-> v8 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v6 -."wdt:P9218".-> v9 bind1[/"concat('#91;https://www.discogs.com/genre/',?DgID,' ',?DgID,'#93;')"/] v9 --o bind1 bind1 --as--o v10 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v6 -."wdt:P9219".-> v11 bind2[/"concat('#91;https://www.discogs.com/style/',?DsID,' ',?DsID,'#93;')"/] v11 --o bind2 bind2 --as--o v12 end bind3[/"if(bound(?DgIDurl)bound(?DsIDurl),concat(?DgIDurl,' ',?DsIDurl),if(bound(?DgIDurl),?DgIDurl,if(bound(?DsIDurl),?DsIDurl,'')))"/] v10 --o bind3 v12 --o bind3 bind3 --as--o v13 subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v6 -."wdt:P9173".-> v14 bind4[/"replace(?rymID,' ','%20')"/] v14 --o bind4 bind4 --as--o v15 bind5[/"replace(?rymID1,'%5B','#91;')"/] v15 --o bind5 bind5 --as--o v16 bind6[/"replace(?rymID2,'%5D','#93;')"/] v16 --o bind6 bind6 --as--o v17 bind7[/"concat('#91;https://rateyourmusic.com/genre/',?rymID_fix,' ',?rymID_fix,'#93;')"/] v17 --o bind7 bind7 --as--o v18 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v6 -."wdt:P8052".-> v19 c4 --"rdfs:label"--> v4 bind8[/"concat('#91;https://musicbrainz.org/genre/',?mbID,' ID#93;')"/] v19 --o bind8 bind8 --as--o v20 end subgraph optional6["(optional)"] style optional6 fill:#bbf,stroke-dasharray: 5 5; v6 -."wdt:P9185".-> v21 c5 --"rdfs:label"--> v3 bind9[/"concat('#91;https://www.allmusic.com/style/',?amID,' ID#93;')"/] v21 --o bind9 bind9 --as--o v22 end subgraph optional7["(optional)"] style optional7 fill:#bbf,stroke-dasharray: 5 5; v6 -->v23--> v24 v1 -."wikibase:directClaim".-> v23 v1 --"wikibase:propertyType"--> c20 v1 --"wdt:P31"--> c21 v1 --"wdt:P1630"--> v25 v1 --"rdfs:label"--> v2 bind10[/"replace(?id,'^(.+)$',?formatterurl)"/] v24 --o bind10 v25 --o bind10 bind10 --as--o v26 bind11[/"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;')))"/] v1 --o bind11 v26 --o bind11 v2 --o bind11 bind11 --as--o v27 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c24 --"wikibase:language"--> c26 end bind17[/"?discog"/] v13 --o bind17 bind17 --as--o v28 bind18[/"?rymurl"/] v18 --o bind18 bind18 --as--o v29 bind19[/"?mburl"/] v20 --o bind19 bind19 --as--o v30 bind20[/"?amurl"/] v22 --o bind20 bind20 --as--o v31 bind21[/"?identifier"/] v27 --o bind21 bind21 --as--o v32