Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion openlibrary/catalog/marc/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
re_date = re.compile(r'^[0-9]+u*$')
re_question = re.compile(r'^\?+$')
re_lccn = re.compile(r'([ \dA-Za-z\-]{3}[\d/-]+).*')
re_lcnaf = re.compile(r'.*id.loc.gov/authorities/names/(n\w*\d)')
re_oclc = re.compile(r'^\(OCoLC\).*?0*(\d+)')
re_ocolc = re.compile('^ocolc *$', re.IGNORECASE)
re_ocn_or_ocm = re.compile(r'^oc[nm]0*(\d+) *$')
Expand Down Expand Up @@ -463,7 +464,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('abcde46')
contents = field.get_contents('abcde046')
if 'a' not in contents and 'c' not in contents:
# Should have at least a name or title.
return author
Expand All @@ -486,6 +487,10 @@ def read_author_person(field: MarcFieldBase, tag: str = '100') -> dict[str, Any]
del author['personal_name'] # DRY names
if 'q' in contents:
author['fuller_name'] = ' '.join(contents['q'])
if '0' in contents: # Authority record control number or standard number
for value in contents['0']:
if m := re_lcnaf.match(value):
author['remote_ids'] = {'lc_naf': m.group(1)}
if '6' in contents: # noqa: SIM102 - alternate script name exists
if (link := field.rec.get_linkage(tag, contents['6'][0])) and (
name := link.get_subfield_values('a')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
"birth_date": "1914",
"death_date": "1998",
"name": "林屋 辰三郎",
"entity_type": "person"
"entity_type": "person",
"remote_ids": {"lc_naf": "n81047233"}
},
{
"alternate_names": [
"Yokoi, Kiyoshi"
],
"name": "横井 清.",
"entity_type": "person"
"entity_type": "person",
"remote_ids": {"lc_naf": "n81089234"}
},
{
"alternate_names": [
Expand All @@ -36,7 +38,8 @@
"birth_date": "1940",
"death_date": "1960",
"name": "楢林 忠男",
"entity_type": "person"
"entity_type": "person",
"remote_ids": {"lc_naf": "n85206624"}
}
],
"subjects": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@
{
"name": "مودن، عبد الرحمن",
"entity_type": "person",
"remote_ids": {"lc_naf": "nr92001540"},
"alternate_names": [
"El Moudden, Abderrahmane"
]
},
{
"name": "بنحادة، عبد الرحيم",
"entity_type": "person",
"remote_ids": {"lc_naf": "nr97026593"},
"alternate_names": [
"Bin-Ḥāddah, ʻAbd al-Raḥīm"
]
},
{
"name": "غربي، محمد لزهر",
"entity_type": "person",
"remote_ids": {"lc_naf": "nr96019749"},
"alternate_names": [
"Gharbi, Mohamed Lazhar"
]
Expand Down
3 changes: 3 additions & 0 deletions openlibrary/catalog/marc/tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def test_read_author_person(self):
<datafield xmlns="http://www.loc.gov/MARC21/slim" tag="100" ind1="1" ind2="0">
<subfield code="a">Rein, Wilhelm,</subfield>
<subfield code="d">1809-1865.</subfield>
<subfield code="0">(uri) http://id.loc.gov/authorities/names/no2003007242</subfield>
<subfield code="0">(uri) http://viaf.org/viaf/sourceID/LC|no2003007242</subfield>
</datafield>"""
test_field = DataField(
None,
Expand All @@ -190,3 +192,4 @@ def test_read_author_person(self):
assert result['birth_date'] == '1809'
assert result['death_date'] == '1865'
assert result['entity_type'] == 'person'
assert result['remote_ids'] == {'lc_naf': 'no2003007242'}
Loading