From 9074b70b9284954977a41fb25fbb6afa549d35af Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Sun, 12 Jan 2020 20:47:52 -0500 Subject: [PATCH] Wikidata music cards: use RWO URIs from $1 if available If the bib record contains a $1 subfield that points to a Wikidata Real World URI, such as http://www.wikidata.org/entity/Q709024, surface that in the author's RDfa as a schema.org/sameAs relation. For music cards, the presence of a Wikidata RWO URI enables us to skip searching by name and serve up the data directly based on the RWO URI. The explicit RWO URI avoids disambiguation problems as arises with names such as "Alexander Young" who is both a Scottish musician and an English tenor, and sets the stage for expanding the Wikidata entity card functionality outside of the domain of music. Signed-off-by: Dan Scott --- .../src/templates/opac/parts/record/authors.tt2 | 11 ++++++++ .../web/js/ui/default/opac/wikidata_music_card.js | 32 ++++++++++++++++++---- test_wikidata.html | 2 +- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/templates/opac/parts/record/authors.tt2 b/Open-ILS/src/templates/opac/parts/record/authors.tt2 index 25dac9a5cc..0b0e978419 100644 --- a/Open-ILS/src/templates/opac/parts/record/authors.tt2 +++ b/Open-ILS/src/templates/opac/parts/record/authors.tt2 @@ -61,6 +61,7 @@ BLOCK build_author_links; birthdate = ''; deathdate = ''; graphics = []; + rwo_uris = []; tag = node.getAttribute('tag'); FOR subfield IN node.childNodes; indexed_term = ''; @@ -79,6 +80,10 @@ BLOCK build_author_links; linked_fields = [subfield.textContent()]; get_linked_880s; END; + # Gather $1 Real World Object (RWO) URIs - per http://www.loc.gov/marc/bibliographic/ecbdcntf.html + IF code == '1'; + rwo_uris.push( subfield.textContent() ); + END; NEXT UNLESS code.match('[a-z]'); sf = subfield.textContent | html; @@ -172,6 +177,12 @@ BLOCK build_author_links; authtml = authtml _ ''; END; authtml = authtml _ ' (' _ author_type _ '). '; + + # Embed RWO URIs + FOREACH rwo_uri IN rwo_uris; + authtml = authtml _ ''; + END; + authtml = authtml _ ''; # End author span authlist.push(authtml); END; diff --git a/Open-ILS/web/js/ui/default/opac/wikidata_music_card.js b/Open-ILS/web/js/ui/default/opac/wikidata_music_card.js index 2e4bb13afc..6596818b02 100644 --- a/Open-ILS/web/js/ui/default/opac/wikidata_music_card.js +++ b/Open-ILS/web/js/ui/default/opac/wikidata_music_card.js @@ -62,6 +62,14 @@ } } + function getWikidataId(node) { + var wikidata_id = node.querySelector("link[property='sameAs'][href^='http://www.wikidata.org/entity']"); + if (wikidata_id) { + wikidata_id = wikidata_id.href.substring(wikidata_id.href.lastIndexOf('/') + 1); + } + return wikidata_id; + } + function getContribName(node) { var raw_name = node.querySelector(contributor_name).textContent.trim(); var lastchar = raw_name[raw_name.length - 1]; @@ -78,25 +86,37 @@ } function perform(e) { + var wikidata_id = getWikidataId(this.parentNode); var entity_name = getContribName(this.parentNode); - findPerformer(icon_node, entity_name); + findPerformer(icon_node, entity_name, wikidata_id); e.preventDefault(); e.stopPropagation(); } - function findPerformer(icon_node, entity_name) { + function findPerformer(icon_node, entity_name, wikidata_id) { var url = 'https://query.wikidata.org/sparql'; - var query = 'SELECT DISTINCT ?item ?itemLabel ?itemDescription ?image ' + + var query = Object; + query.select = 'SELECT DISTINCT ?item ?itemLabel ?itemDescription ?image ' + '(GROUP_CONCAT(DISTINCT ?instrumentLabel;separator="; ") AS ?instruments) ' + '?birthPlace ?birthPlaceLabel ' + '?website ?musicbrainz ?songKick ?twitter ?facebook ?wplink ' + - 'WHERE { ' + + 'WHERE { '; + + // Default: search by entity name + query.where = '?item rdfs:label|skos:altLabel|wdt:P1449 "' + entity_name + '"@en . ' + '{ ?item wdt:P31/wdt:P279* wd:Q215380 . } ' + // instance of = any subclass of band 'UNION ' + '{ ?item wdt:P106/wdt:P279* wd:Q639669 . } ' + // occupation = any subclass of musician 'UNION ' + - '{ ?item wdt:P31/wdt:P279* wd:Q2088357 . } ' + // instance of = any subclass of musical ensemble + '{ ?item wdt:P31/wdt:P279* wd:Q2088357 . } '; // instance of = any subclass of musical ensemble + + // We have a Wikidata QID? Wonderful! + if (wikidata_id) { + query.where = 'VALUES ?item { wd:' + wikidata_id + ' }. '; + } + + query.rest = 'OPTIONAL { ?item wdt:P3478 ?songKick } . ' + 'OPTIONAL { ?item wdt:P19 ?birthPlace } . ' + 'OPTIONAL { ?item wdt:P1303 ?instrument } . ' + @@ -120,7 +140,7 @@ '} ' + 'GROUP BY ?item ?itemLabel ?itemDescription ?image ?birthPlace ?birthPlaceLabel ?website ?musicbrainz ?songKick ?twitter ?facebook ?wplink' 'LIMIT 10'; - var q = '?query=' + encodeURIComponent(query); + var q = '?query=' + encodeURIComponent(query.select + query.where + query.rest); var req = new window.XMLHttpRequest(); req.open('GET', url + q); diff --git a/test_wikidata.html b/test_wikidata.html index 3383a22d58..ca9fe42acd 100644 --- a/test_wikidata.html +++ b/test_wikidata.html @@ -82,7 +82,7 @@

The 1985 Juno Awards collection

-
Adams, Bryan (Singer). Hart, Corey (Singer). Silver, Liberty (Singer). McLauchlan, Murray (Singer). Thompson, Don (Instrumentalist). Luba (Singer). Janz, Paul (Singer). lang, k.d. (Kathryn Dawn), 1961- (Singer). Idle Eyes (Performer). The Family Brown (Performer). Parachute Club (Performer). Oxford String Quartet (Performer). +
Adams, Bryan (Singer). Hart, Corey (Singer). Silver, Liberty (Singer). McLauchlan, Murray (Singer). Thompson, Don (Instrumentalist). Luba (Singer). Janz, Paul (Singer). lang, k.d. (Kathryn Dawn), 1961- (Singer). Idle Eyes (Performer). The Family Brown (Performer). Parachute Club (Performer). Oxford String Quartet (Performer).
-- 2.11.0