Skip to content

Commit

Permalink
partial MARC21 role code expansion, include $4+$e
Browse files Browse the repository at this point in the history
  • Loading branch information
hornc committed Sep 20, 2024
1 parent 2cf44af commit c4f59fc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
22 changes: 21 additions & 1 deletion openlibrary/catalog/marc/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@
re_bracket_field = re.compile(r'^\s*(\[.*\])\.?\s*$')


ROLES = {
# MARC 21 realtor codes
# https://www.loc.gov/marc/relators/relacode.html
'art': 'Artist',
'aut': 'Author',
'clr': 'Colorist',
'com': 'Compiler',
'edt': 'Editor',
'ill': 'Illustrator',
'ltr': 'Letterer',
'trl': 'Translator',
# Non-standard terms from $e
'ed': 'Editor',
'comp': 'Compiler',
}


def strip_foc(s: str) -> str:
foc = '[from old catalog]'
return s[: -len(foc)].rstrip() if s.endswith(foc) else s
Expand Down Expand Up @@ -425,7 +442,7 @@ def read_author_person(field: MarcFieldBase, tag: str = '100') -> dict[str, Any]
and returns an author import dict.
"""
author: dict[str, Any] = {}
contents = field.get_contents('abcde6')
contents = field.get_contents('abcde46')
if 'a' not in contents and 'c' not in contents:
# Should have at least a name or title.
return author
Expand All @@ -438,6 +455,7 @@ def read_author_person(field: MarcFieldBase, tag: str = '100') -> dict[str, Any]
('b', 'numeration'),
('c', 'title'),
('e', 'role'),
('4', 'role'),
]
for subfield, field_name in subfields:
if subfield in contents:
Expand All @@ -452,6 +470,8 @@ def read_author_person(field: MarcFieldBase, tag: str = '100') -> dict[str, Any]
):
author['alternate_names'] = [author['name']]
author['name'] = name_from_list(name)
if author.get('role') in ROLES:
author['role'] = ROLES[author['role']]
return author


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{
"birth_date": "1969",
"name": "Garlini, Alberto",
"role": "Author",
"entity_type": "person"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"birth_date": "1767",
"death_date": "1832",
"name": "Beauchamp, Alph. de",
"role": "ed",
"role": "Editor",
"entity_type": "person"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"birth_date": "1849",
"name": "Cowles, Calvin D.",
"entity_type": "person",
"role": "comp"
"role": "Compiler"
},
{
"entity_type": "org",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"name": "Schlosberg, Leon",
"date": "d. 1899",
"entity_type": "person",
"role": "ed"
"role": "Editor"
}
],
"publish_places": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"birth_date": "1849",
"name": "Cowles, Calvin D.",
"entity_type": "person",
"role": "comp"
"role": "Compiler"
},
{
"entity_type": "org",
Expand Down

0 comments on commit c4f59fc

Please sign in to comment.