TPAC: Fix schema.org name / dates for authors
authorDan Scott <dscott@laurentian.ca>
Fri, 5 Apr 2013 20:10:01 +0000 (16:10 -0400)
committerMike Rylander <mrylander@gmail.com>
Thu, 18 Apr 2013 19:18:09 +0000 (15:18 -0400)
Per http://schema.org/Person, the birth date and death date are not
supposed to be part of the name of a Person. We can separate these out
correctly based on subfield d for 100 fields.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/opac/parts/record/authors.tt2

index 43a3060..94a887b 100644 (file)
@@ -28,7 +28,10 @@ BLOCK build_author_links;
         qterm = '';
         iprop = '';
         tlabel = '';
+        birthdate = '';
+        deathdate = '';
         graphics = [];
+        tag = node.getAttribute('tag');
         FOR subfield IN node.childNodes;
             NEXT UNLESS subfield.nodeName == "subfield";
             code = subfield.getAttribute('code');
@@ -37,17 +40,27 @@ BLOCK build_author_links;
                 tlabel = relators.$relcode || label;
             END;
             IF code == '6';
+               target_field = tag;
                linked_fields = [subfield.textContent()];
-               target_field = node.getAttribute('tag');
                get_linked_880s;
             END;
             NEXT UNLESS code.match('[a-z]');
             sf = subfield.textContent | html;
-            term = term _ ' ' _ sf;
             IF code.match('[acdq]');
                 sf_raw = subfield.textContent.replace('[#"^$\+\-,\.:;&|\[\]()]', ' ');
                 qterm = qterm _ ' ' _ sf_raw;
             END;
+            # Only Persons have birth/death dates in schema.org
+            IF code.match('d') && tag.substr(1,2) == '00';
+                IF subfield.textContent.match('^\s*\d{4}');
+                    birthdate = subfield.textContent.replace('^\s*(\d{4}).*$', '$1');
+                END;
+                IF subfield.textContent.match('-\d{4}\s*$');
+                    deathdate = subfield.textContent.replace('^\s*.{4}\-(\d{4})\s*$', '$1');
+                END;
+            ELSE;
+                term = term _ ' ' _ sf;
+            END;
         END;
         url = mkurl(ctx.opac_root _ '/results', {query => qterm, qtype => 'author'}, ['page', 'expand']);
         author_type = (tlabel || label) | html;
@@ -57,7 +70,7 @@ BLOCK build_author_links;
             IF args.schema.itemtype && args.schema.itemtype.match('MusicAlbum');
                 iprop = ' itemtype="http://schema.org/MusicGroup" itemscope itemprop="byArtist"';
             ELSE;
-                iprop = ' itemprop="accountablePerson"';
+                iprop = ' itemtype="http://schema.org/Person" itemscope itemprop="author"';
             END;
         ELSIF type == 'added';
             iprop = ' itemprop="contributor"';
@@ -66,6 +79,12 @@ BLOCK build_author_links;
         IF iprop; '<span itemprop="name">'; END;
         term.replace('^\s+', '');
         IF iprop; '</span>'; END;
+        IF birthdate;
+            ' <span itemprop="birthDate">' _ birthdate _ '</span>-';
+        END;
+        IF deathdate;
+            '<span itemprop="deathDate">' _ deathdate _ '</span>';
+        END;
         '</a>';
         FOREACH link880 IN graphics;
             diratt = '';