From 3ee693bc9a0106b6dfe4403477c2e9d0f8bc2ef5 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Mon, 15 Dec 2014 23:29:35 -0500 Subject: [PATCH] Add the ability to link out to sameAs entities Look for standard identifiers with known URIs, such as LCCNs, OCLC numbers, and URIs identified in 024 fields, and add http://schema.org/sameAs properties to the record. This helps us link out to the broader linked data world, and should help those consuming our data to better understand what resources we have to offer. Signed-off-by: Dan Scott --- Open-ILS/src/templates/opac/parts/misc_util.tt2 | 26 +++++++++++++++++++++++ Open-ILS/src/templates/opac/parts/record/body.tt2 | 3 +++ 2 files changed, 29 insertions(+) diff --git a/Open-ILS/src/templates/opac/parts/misc_util.tt2 b/Open-ILS/src/templates/opac/parts/misc_util.tt2 index da7c958205..5ad5b61338 100644 --- a/Open-ILS/src/templates/opac/parts/misc_util.tt2 +++ b/Open-ILS/src/templates/opac/parts/misc_util.tt2 @@ -150,6 +150,32 @@ END; args.upc = args.upcs.0; # use first UPC as the default + # These are URIs that link out to related works for linked data purposes, + # such as OCLC Work Entities like http://worldcat.org/entity/work/id/415491 + args.links = []; + FOR link_node IN xml.findnodes('//*[@tag="024"]/*[@code="2" and text()="uri"]'); + my_parent = link_node.parentNode(); + FOR link IN my_parent.findnodes('./*[@code="a"]'); + link_uri = textContent | trim; + args.links.push(link_uri); + END; + END; + FOR lccn IN xml.findnodes('//*[@tag="010"]/*[@code="a"]'); + lccn_num = lccn.textContent | trim; + args.links.push('http://lccn.loc.gov/' _ lccn_num); + END; + FOR oclcnum IN xml.findnodes('//*[@tag="035"]/*[@code="a"]'); + oclcnum = oclcnum.textContent | trim; + NEXT UNLESS oclcnum.search('^\(OCoLC\)'); + oclcnum = oclcnum | remove('\(OCoLC\)'); + # These prefixes are often included in the 035, even though they should not be + oclcnum = oclcnum | remove('ocm'); + oclcnum = oclcnum | remove('ocn'); + oclcnum = oclcnum | remove('on') | trim; + args.links.push('http://www.worldcat.org/oclc/' _ oclcnum); + END; + args.links = args.links.unique; + args.issns = []; FOR sub IN xml.findnodes('//*[@tag="022"]/*[@code="a"]'); args.issns.push(sub.textContent); diff --git a/Open-ILS/src/templates/opac/parts/record/body.tt2 b/Open-ILS/src/templates/opac/parts/record/body.tt2 index 216f8f96ed..d758846eca 100644 --- a/Open-ILS/src/templates/opac/parts/record/body.tt2 +++ b/Open-ILS/src/templates/opac/parts/record/body.tt2 @@ -5,6 +5,9 @@ ctx.record_attrs = attrs; # capture for JS %]
+[%- FOREACH link IN args.links; %] + +[%- END; %] [%- INCLUDE "opac/parts/record/navigation.tt2" %] [%- IF ctx.bib_is_dead %]
-- 2.11.0