Skip to content

Commit 5488969

Browse files
authored
MBS-9987: JSON-LD: Use "Concept URI" for Wikidata (metabrainz#1938)
These are the IDs Wikidata itself uses for RDF / SPARQL, so it makes linked data usage a lot easier by avoiding the user having to put the right URI together. They redirect to the standard page when loaded in the browser, so it shouldn't make things harder for data users otherwise.
1 parent 50837c5 commit 5488969

File tree

2 files changed

+10
-4
lines changed
  • lib/MusicBrainz/Server/WebService/Serializer/JSON/LD/Role
  • t/lib/t/MusicBrainz/Server/Controller/Artist

2 files changed

+10
-4
lines changed

lib/MusicBrainz/Server/WebService/Serializer/JSON/LD/Role/SameAs.pm

+7-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ sub sameas_url {
8787
if ($acceptable{$rel->link->type->gid // ''} ||
8888
$acceptable_parents{$rel->link->type->parent_id // ''} ||
8989
$acceptable_parents{$rel->link->type->id // ''}) {
90-
return $rel->target->url->as_string;
90+
91+
my $url = $rel->target->url->as_string;
92+
93+
# Use the Wikidata RDF concept URIs rather than the default site URL (MBS-9987)
94+
$url =~ s/^https?:\/\/(?:www\.)?wikidata\.org\/wiki\//http:\/\/www\.wikidata\.org\/entity\//;
95+
96+
return $url;
9197
}
9298
}
9399

t/lib/t/MusicBrainz/Server/Controller/Artist/Show.pm

+3-3
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ test 'Embedded JSON-LD sameAs & performsAs' => sub {
237237
'http://musicbrainz.org/artist/f90e8b26-9e52-4669-a5c9-e28529c47894',
238238
'http://snooplion.com/',
239239
'http://www.discogs.com/artist/2859872',
240-
'http://www.wikidata.org/wiki/Q6096',
240+
'http://www.wikidata.org/entity/Q6096',
241241
'https://www.allmusic.com/artist/mn0002979185',
242242
]
243243
};
@@ -282,7 +282,7 @@ test 'Embedded JSON-LD dates & origins for people' => sub {
282282
'http://viaf.org/viaf/263782738',
283283
'http://viaf.org/viaf/32197206',
284284
'http://www.discogs.com/artist/95546',
285-
'http://www.wikidata.org/wiki/Q254',
285+
'http://www.wikidata.org/entity/Q254',
286286
'https://www.allmusic.com/artist/mn0000026350',
287287
'https://www.bbc.co.uk/music/artists/b972f589-fb0e-474e-b64a-803b0364fa75',
288288
'https://www.imdb.com/name/nm0003665/',
@@ -393,7 +393,7 @@ test 'Embedded JSON-LD for groups' => sub {
393393
'http://www.secondhandsongs.com/artist/41',
394394
'http://www.thebeatles.com/',
395395
'http://www.whosampled.com/The-Beatles/',
396-
'http://www.wikidata.org/wiki/Q1299',
396+
'http://www.wikidata.org/entity/Q1299',
397397
'https://www.allmusic.com/artist/mn0000754032',
398398
'https://www.bbc.co.uk/music/artists/b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d',
399399
'https://www.imdb.com/name/nm1397313/',

0 commit comments

Comments
 (0)