Prefer URIs for relators in RDA fields
authorDan Scott <dscott@laurentian.ca>
Sun, 13 May 2018 14:22:16 +0000 (10:22 -0400)
committerDan Scott <dscott@laurentian.ca>
Sun, 13 May 2018 14:23:24 +0000 (10:23 -0400)
Signed-off-by: Dan Scott <dscott@laurentian.ca>
tools/ebooks/prep_ebook_records.py

index b9a4a02..d9fae25 100755 (executable)
@@ -491,7 +491,8 @@ def process_fields(record, options):
         record.add_ordered_field(note)
 
     add_marc_source(record, options) # 598
-    add_rda_fields(record, options) # 336,337,338
+    if record.get_fields('336') is None:
+        add_rda_fields(record, options) # 336,337,338
     publisher = add_publisher(record, options) # 710
     add_restriction(record, options, publisher) # 506
     add_platform(record, options) # 710
@@ -520,6 +521,10 @@ def process_fields(record, options):
         # Strip out 300 fields that only contain placeholders
         elif field.tag == '300' and field['a'] == 'p. cm.':
             pass
+        # Add relator URIs
+        elif field.tag.startswith('33') and field['0'] is None:
+            field = add_relator_uri(field)
+            new_record.add_ordered_field(field)
         # Strip out useless fields
         elif 'cut-field' in options and field.tag in options['cut-field']:
             pass
@@ -730,11 +735,15 @@ def add_publisher(record, options):
                 munge_publisher = True
                 for rel in sten.get_subfields('4'):
                     if rel == 'pbl':
+                        uri_for_relator = True
                         need_publisher = False
                         need_relator = False
 
-                if munge_publisher and need_relator:
-                    sten.add_subfield('4', 'pbl')
+                if munge_publisher:
+                    if need_relator:
+                        sten.add_subfield('4', 'http://id.loc.gov/vocabulary/relators/pbl')
+                    elif uri_for_relator:
+                        sten['4'] = 'http://id.loc.gov/vocabulary/relators/pbl'
                     need_publisher = False
 
     if need_publisher:
@@ -743,7 +752,7 @@ def add_publisher(record, options):
             indicators = ['2', ' '],
             subfields = [
                 'a', publisher,
-                '4', 'pbl'
+                '4', 'http://id.loc.gov/vocabulary/relators/pbl'
             ]
         )
         record.add_ordered_field(seven_ten)
@@ -958,7 +967,23 @@ def add_cat_source(record, options):
         )
         record.add_ordered_field(forty)
 
-def add_rda_fields(record, options):
+def add_relator_uri(field):
+    """
+    Add URIs to RDA 33x fields
+    """
+
+    if 'b' not in field:
+        pass
+    elif field.tag == '336':
+        field.add_subfield('0', 'http://id.loc.gov/vocabulary/contentTypes/' + field['b'])
+    elif field.tag == '337':
+        field.add_subfield('0', 'http://id.loc.gov/vocabulary/mediaTypes/' + field['b'])
+    elif field.tag == '338':
+        field.add_subfield('0', 'http://id.loc.gov/vocabulary/carriers/' + field['b'])
+
+    return field
+
+def add_rda_fields(record):
     """
     Add 336,337,338 fields identifying the content as an ebook
     """