Contributors
Silver, Liberty
(Singer).
lang, k.d. (Kathryn Dawn),
1961-
(Singer).
The Family Brown
(Performer).
Figure 9. Simplified HTML for Evergreen music album example
To encourage reuse and adoption, Scott wrote the JavaScript without using external libraries, and factored out the variable elements of the implementation into five CSS selector paths, per Figure 10:
/* Path for the schema.org type declaration */
var type_path = '[typeof~="MusicAlbum"]';
/* List of elements describing contributors */
var contributors_path = 'div[resource^="#schemacontrib"]';
/* Path to find the name within each contributor element */
var contributor_name = 'span[property="name"]';
/* Within each contributor element, where we can append a Wikidata clickable icon */
var name_path = 'span[property="description"]';
/* Path for appending the requested infocards */
var infocard_location = '#contributors';
Figure 10. CSS selector paths for finding contributors and appending infocards
Wikidata offers several different methods of accessing its data, but for this implementation Scott chose the SPARQL endpoint at https://query.wikidata.org/sparql, requesting the JSON-LD serialization for easy manipulation in JavaScript. The SPARQL query in Figure 11 is implemented as a UNION of three different subqueries, to find musicians, bands, or musical ensembles with names or aliases that match the requested contributor’s name, and to potentially return supplemental data to include in the infocard, along with a possible link to a corresponding Wikipedia entry (?wplink).
SELECT ?item ?itemLabel ?itemDescription ?image
(GROUP_CONCAT(DISTINCT ?instrumentLabel;separator="; ") AS ?instruments)
?birthPlace ?birthPlaceLabel ?website ?musicbrainz
?songKick ?twitter ?facebook ?wplink
WHERE {
?item rdfs:label|skos:altLabel|wdt:P1449 'A Tribe Called Red'@en .
# instance of = any subclass of band
{ ?item wdt:P31/wdt:P279* wd:Q215380 . }
UNION
# occupation = any subclass of musician
{ ?item wdt:P106/wdt:P279* wd:Q639669 . }
UNION
# instance of = any subclass of musical ensemble
{ ?item wdt:P31/wdt:P279* wd:Q2088357 . }
OPTIONAL { ?item wdt:P3478 ?songKick } .
OPTIONAL { ?item wdt:P19 ?birthPlace } .
OPTIONAL { ?item wdt:P1303 ?instrument } .
OPTIONAL { ?item wdt:P856 ?website } .
OPTIONAL { ?item wdt:P434 ?musicbrainz } .
OPTIONAL { ?item wdt:P2002 ?twitter } .
OPTIONAL { ?item wdt:P2013 ?facebook } .
OPTIONAL { ?item wdt:P18 ?image } .
OPTIONAL {
?wplink schema:about ?item .
?wplink schema:inLanguage "en" .
?wplink schema:isPartOf