query-f23811dbc6c3897399cbd63a61982ab8
: It's a kludge, but it seems to work.Solidest@: Your method of dealing with the square brackets = much better than mine. I wondered about // but didn't get around to trying it. But I think maybe it leaves the anchor text a bit borked? We'll probably want to do some more on that? Solidest@Do you want to consolidate the country data into a single column? As it is, they seem to work in the below. which is not exposed in the SELECT? BIND( xsd:integer( STRAFTER( STR( ?item ), STR( wd:Q ) ) ) AS ?qid )Why do we have a Sorting: point me at the page this is being used on. I probably should know but...
Use at
- https://query.wikidata.org/sparql
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 ?P17 ?P17Label ?P495 ?P495Label (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) 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," ",?DgID,"]") as ?DgIDurl)}
OPTIONAL {?item wdt:P9219 ?DsID.
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)
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)}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} group by ?item ?P17 ?P17Label ?P495 ?P495Label
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v7("?DgID")
v8("?DgIDurl")
v9("?DsID")
v10("?DsIDurl")
v5("?P17"):::projected
v6("?P495"):::projected
v19("?amID")
v24("?am_url")
v20("?amurl"):::projected
v11("?discog"):::projected
v21("?discogs")
v4("?item"):::projected
v17("?mbID")
v23("?mb_url")
v18("?mburl"):::projected
v1("?propItemLabelam")
v2("?propItemLabelmb")
v3("?qid")
v12("?rymID")
v13("?rymID1")
v14("?rymID2")
v15("?rymID_fix")
v22("?rym_url")
v16("?rymurl"):::projected
a1((" "))
c16(["bd:serviceParam"]):::iri
c4(["wd:Q188451"]):::iri
c11(["wd:P8052"]):::iri
c14(["wd:P9185"]):::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 v3
v4 --"wdt:P31"--> a1
a1 --"wdt:P279"--> c4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v4 -."wdt:P17".-> v5
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v4 -."wdt:P495".-> v6
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v4 -."wdt:P9218".-> v7
bind1[/"concat('#91;https://www.discogs.com/genre/',?DgID,' ',?DgID,'#93;')"/]
v7 --o bind1
bind1 --as--o v8
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v4 -."wdt:P9219".-> v9
bind2[/"concat('#91;https://www.discogs.com/style/',?DsID,' ',?DsID,'#93;')"/]
v9 --o bind2
bind2 --as--o v10
end
bind3[/"if(bound(?DgIDurl)bound(?DsIDurl),concat(?DgIDurl,' ',?DsIDurl),if(bound(?DgIDurl),?DgIDurl,if(bound(?DsIDurl),?DsIDurl,'')))"/]
v8 --o bind3
v10 --o bind3
bind3 --as--o v11
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v4 -."wdt:P9173".-> v12
bind4[/"replace(?rymID,' ','%20')"/]
v12 --o bind4
bind4 --as--o v13
bind5[/"replace(?rymID1,'\#91;','%5B')"/]
v13 --o bind5
bind5 --as--o v14
bind6[/"replace(?rymID2,'\#93;','%5D')"/]
v14 --o bind6
bind6 --as--o v15
bind7[/"concat('#91;https://rateyourmusic.com/genre/',?rymID_fix,' ',?rymID_fix,'#93;')"/]
v15 --o bind7
bind7 --as--o v16
end
subgraph optional5["(optional)"]
style optional5 fill:#bbf,stroke-dasharray: 5 5;
v4 -."wdt:P8052".-> v17
c11 --"rdfs:label"--> v2
bind8[/"concat('#91;https://musicbrainz.org/genre/',?mbID,' ID#93;')"/]
v17 --o bind8
bind8 --as--o v18
end
subgraph optional6["(optional)"]
style optional6 fill:#bbf,stroke-dasharray: 5 5;
v4 -."wdt:P9185".-> v19
c14 --"rdfs:label"--> v1
bind9[/"concat('#91;https://www.allmusic.com/style/',?amID,' ID#93;')"/]
v19 --o bind9
bind9 --as--o v20
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c16 --"wikibase:language"--> c18
end
bind14[/"?discog"/]
v11 --o bind14
bind14 --as--o v21
bind15[/"?rymurl"/]
v16 --o bind15
bind15 --as--o v22
bind16[/"?mburl"/]
v18 --o bind16
bind16 --as--o v23
bind17[/"?amurl"/]
v20 --o bind17
bind17 --as--o v24