...
 
Commits (2)
  • Dan Scott's avatar
    Support any number of commas in a name · 32ab24bb
    Dan Scott authored
    We had been inverting names only if they contained a single comma (for example,
    "Silver, Liberty" would be converted to "Liberty Silver"). However, this left
    names like "Marriner, Neville, Sir" as simply being passed in their original
    comma-delimited order, which had no chance of finding a match in Wikidata.
    
    Instead, concatenate the results in inverse order, no matter how many commas
    there are. The test record now contains an example entry for this situation.
    Signed-off-by: 's avatarDan Scott <dscott@laurentian.ca>
    32ab24bb
  • Dan Scott's avatar
    Group and display instruments · dfb7690c
    Dan Scott authored
    For multi-instrumentalists like Joni Mitchell, this offers a better
    representation of their diverse skills. A side effect of the GROUP_CONCAT()
    is that a value is now always returned for the instruments variable, even
    if the performer has no associated instruments; avoid displaying it if it is
    nothing more than whitespace.
    Signed-off-by: 's avatarDan Scott <dscott@laurentian.ca>
    dfb7690c
......@@ -26,6 +26,8 @@
<span property="name">The Family Brown</span> (<span property="description">Performer</span>).</div>
<div typeof="Organization" property="contributor" resource="#schemacontrib11">
<span property="name">Parachute Club</span> (<span property="description">Performer</span>).</div>
<div typeof="Organization" property="contributor" resource="#schemacontrib11">
<span property="name">Marriner, Neville, Sir</span> (<span property="description">Performer</span>).</div>
</section>
<section id="record_details">
<h2>Record details</h2>
......
......@@ -60,16 +60,19 @@
}
function getContribName(node) {
var entity_name = node.querySelector(contributor_name).textContent.trim();
var lastchar = entity_name[entity_name.length - 1];
var raw_name = node.querySelector(contributor_name).textContent.trim();
var lastchar = raw_name[raw_name.length - 1];
var entity_name = '';
if (lastchar === '.' || lastchar === ',') {
entity_name = entity_name.slice(0, -1);
raw_name = raw_name.slice(0, -1);
}
var inverse = entity_name.split(',');
if (inverse.length === 2) {
entity_name = inverse[1].trim() + " " + inverse[0].trim();
/* Change "Silver, Liberty" to "Liberty Silver" for the lookup */
var inverse = raw_name.split(',');
for (x in inverse.reverse()) {
entity_name += inverse[x].trim() + " ";
}
return entity_name;
/* Trim final space */
return entity_name.trim();
}
function perform(e) {
......@@ -81,7 +84,9 @@
function findPerformer(icon_node, entity_name) {
var url = 'https://query.wikidata.org/sparql';
var query = 'SELECT DISTINCT ?item ?itemLabel ?itemDescription ?image ?instrumentLabel ?birthPlace ?birthPlaceLabel ' +
var query = 'SELECT DISTINCT ?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 "' + entity_name + '"@en . ' +
......@@ -103,8 +108,15 @@
'?wplink schema:inLanguage "en" . ' +
'?wplink schema:isPartOf <https://en.wikipedia.org/> . ' +
'} ' +
'SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } ' +
'SERVICE wikibase:label { ' +
' bd:serviceParam wikibase:language "en". ' +
' ?instrument rdfs:label ?instrumentLabel. ' +
' ?item rdfs:label ?itemLabel. ' +
' ?item schema:description ?itemDescription. ' +
' ?birthPlace rdfs:label ?birthPlaceLabel ' +
'} ' +
'} ' +
'GROUP BY ?item ?itemLabel ?itemDescription ?image ?birthPlace ?birthPlaceLabel ?website ?musicbrainz ?songKick ?twitter ?facebook ?wplink'
'LIMIT 10';
var q = '?query=' + encodeURIComponent(query);
......@@ -211,7 +223,7 @@
function addWDValue(property, propertyLabel, label, isLink, linkFormatter) {
var value = '';
if (r.hasOwnProperty(property)) {
if (r.hasOwnProperty(property) && r[property].value.trim()) {
value = r[property].value;
var valueDiv = document.createElement('div');
var labelText = value;
......@@ -250,7 +262,7 @@
}
}
addWDValue('instrumentLabel', 'Instrument: ', 'instrumentLabel', false);
addWDValue('instruments', 'Instruments: ', 'instruments', false);
addWDValue('birthPlace', 'Birth place: ', 'birthPlaceLabel', true);
addWDValue('website', 'Web site: ', null, true);
addWDValue('musicbrainz', null, 'Discography (Musicbrainz)', true, function(value) { return 'https://musicbrainz.org/artist/' + value });
......