Skip to content

Commit

Permalink
dojson: fix work access point and title
Browse files Browse the repository at this point in the history
* Fixes work access points $t.
* Fixes bf:KeyTitle tag 222

Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep committed Apr 8, 2022
1 parent e92c579 commit 24769bf
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def marc21_to_part_of(self, key, value):
do_part_of(self, marc21, key, value)


@marc21.over('work_access_point', '(^130..|^700.2|^710.2|^730..)')
@marc21.over('work_access_point', '(^130..|^730..)')
@utils.for_each_value
@utils.ignore_value
def marc21_to_work_access_point(self, key, value):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def marc21_to_part_of(self, key, value):
do_part_of(self, marc21, key, value)


@marc21.over('work_access_point', '(^130..|^700.2|^710.2|^730..)')
@marc21.over('work_access_point', '(^130..|^730..)')
@utils.for_each_value
@utils.ignore_value
def marc21_to_work_access_point(self, key, value):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
get_field_items, not_repetitive, re_identified, \
remove_trailing_punctuation

from ..utils import _CONTRIBUTION_ROLE, do_acquisition_terms_from_field_037, \
do_copyright_date, do_credits, do_dissertation, do_edition_statement, \
from ..utils import _CONTRIBUTION_ROLE, do_abbreviated_title, \
do_acquisition_terms_from_field_037, do_copyright_date, do_credits, \
do_dissertation, do_edition_statement, \
do_electronic_locator_from_field_856, do_frequency_field_310_321, \
do_identified_by_from_field_020, do_identified_by_from_field_022, \
do_identified_by_from_field_024, do_identified_by_from_field_028, \
Expand Down Expand Up @@ -111,6 +112,13 @@ def marc21_to_title(self, key, value):
@utils.ignore_value
def marc21_to_contribution(self, key, value):
"""Get contribution."""
# exclude work access points
if key[:3] in ['700', '710'] and value.get('t'):
work_access_point = do_work_access_point(marc21, key, value)
if work_access_point:
self.setdefault('work_access_point', [])
self['work_access_point'].append(work_access_point)
return None
agent = {}
subfields_0 = utils.force_list(value.get('0'))
if subfields_0:
Expand Down Expand Up @@ -267,6 +275,14 @@ def marc21_to_copyright_date(self, key, value):
return copyright_dates or None


@marc21.over('title', '(^210|^222)..')
@utils.ignore_value
def marc21_to_abbreviated_title(self, key, value):
"""Get abbreviated title data."""
title_list = do_abbreviated_title(self, marc21, key, value)
return title_list or None


@marc21.over('editionStatement', '^250..')
@utils.for_each_value
@utils.ignore_value
Expand Down Expand Up @@ -1050,7 +1066,7 @@ def marc21_to_masked(self, key, value):
return value.get('a') == 'masked'


@marc21.over('work_access_point', '(^130..|^700.2|^710.2|^730..)')
@marc21.over('work_access_point', '(^130..|^730..)')
@utils.for_each_value
@utils.ignore_value
def marc21_to_work_access_point(self, key, value):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def marc21_to_part_of(self, key, value):
do_part_of(self, marc21, key, value)


@marc21.over('work_access_point', '(^130..|^700.2|^710.2|^730..)')
@marc21.over('work_access_point', '(^130..|^730..)')
@utils.for_each_value
@utils.ignore_value
def marc21_to_work_access_point(self, key, value):
Expand Down
43 changes: 23 additions & 20 deletions rero_ils/modules/documents/dojson/contrib/marc21tojson/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ def do_language(data, marc21):
def do_abbreviated_title(data, marc21, key, value):
"""Get abbreviated title data.
* bf:Title = 210|222
* bf:AbbreviatedTitle = 210
* bf:KeyTitle = 222
* mainTitle = $a
* subtitle = $e
* responsibilityStatement = $f|$g
Expand All @@ -376,8 +377,11 @@ def do_abbreviated_title(data, marc21, key, value):
if value.get('a'):
main_title = not_repetitive(
marc21.bib_id, marc21.bib_id, key, value, 'a')
title_type = 'bf:AbbreviatedTitle'
if key[:3] == '222':
title_type = 'bf:KeyTitle'
title = {
'type': 'bf:AbbreviatedTitle',
'type': title_type,
'mainTitle': [{'value': main_title}]
}
if value.get('b'):
Expand Down Expand Up @@ -595,6 +599,10 @@ def build_agent():

# exclude work access points
if key[:3] in ['700', '710'] and value.get('t'):
work_access_point = do_work_access_point(marc21, key, value)
if work_access_point:
data.setdefault('work_access_point', [])
data['work_access_point'].append(work_access_point)
return None

agent = {}
Expand All @@ -614,23 +622,22 @@ def build_agent():
agent = build_agent()

if value.get('4'):
roles = []
roles = set()
for role in utils.force_list(value.get('4')):
if len(role) != 3 and 'http' not in role:
role = role.split('/')[-1].lower()
if len(role) != 3:
error_print('WARNING CONTRIBUTION ROLE LENGTH:',
marc21.bib_id, marc21.rero_id, role)
role = role[:3]
if role == 'sce':
error_print('WARNING CONTRIBUTION ROLE SCE:',
marc21.bib_id, marc21.rero_id,
'sce --> aus')
role = 'aus'
role = role.lower()
if role not in _CONTRIBUTION_ROLE and 'http' not in role:
if role not in _CONTRIBUTION_ROLE:
error_print('WARNING CONTRIBUTION ROLE DEFINITION:',
marc21.bib_id, marc21.rero_id, role)
role = 'ctb'
roles.append(role)
roles.add(role)
else:
if key[:3] == '100':
roles = ['cre']
Expand All @@ -641,7 +648,7 @@ def build_agent():
if agent:
return {
'agent': agent,
'role': list(set(roles))
'role': list(roles)
}
return None

Expand Down Expand Up @@ -1647,20 +1654,17 @@ def do_work_access_point(marc21, key, value):
not_repetitive(marc21.bib_id, marc21.bib_id, key, value, 'b'))
dates = not_repetitive(marc21.bib_id, marc21.bib_id, key, value, 'd')
if dates:
dates = dates.rstrip(',')
dates = remove_trailing_punctuation(dates).split('-')
split_dates = dates.split('-')
date_of_birth = split_dates[0].strip()
if date_of_birth:
agent['date_of_birth'] = date_of_birth
try:
date_of_birth = dates[0].strip()
if date_of_birth:
agent['date_of_birth'] = date_of_birth
except Exception:
pass
try:
date_of_death = dates[1].strip()
date_of_death = split_dates[1].strip()
if date_of_death:
agent['date_of_death'] = date_of_death
except Exception:
pass

if value.get('c'):
agent['qualifier'] = remove_trailing_punctuation(
not_repetitive(marc21.bib_id, marc21.bib_id, key, value, 'c'))
Expand All @@ -1672,8 +1676,7 @@ def do_work_access_point(marc21, key, value):
agent['preferred_name'] = not_repetitive(
marc21.bib_id, marc21.bib_id, key, value, 'a')
if value.get('b'):
agent['subordinate_unit'] = not_repetitive(
marc21.bib_id, marc21.bib_id, key, value, 'b')
agent['subordinate_unit'] = list(utils.force_list(value.get('b')))
if agent:
work_access_point['agent'] = agent
if value.get(title_tag):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"title": "Title",
"description": "Title of the part, section, or supplement",
"type": "string",
"minLength": 3
"minLength": 1
}
}
}
Expand All @@ -130,13 +130,13 @@
"items": {
"title": "Medium of performance (music)",
"type": "string",
"minLength": 3
"minLength": 1
}
},
"arranged_statement_for_music": {
"title": "Arranged statement (music)",
"type": "string",
"minLength": 3
"minLength": 1
},
"key_for_music": {
"title": "Key (music)",
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/test_documents_dojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,11 @@ def test_marc21_to_contribution(mock_get):
<subfield code="d">1921-2014</subfield>
<subfield code="4">edt</subfield>
</datafield>
<datafield tag="700" ind1="1" ind2=" ">
<subfield code="a">Santamaría, Germán</subfield>
<subfield code="t">No morirás</subfield>
<subfield code="l">français</subfield>
</datafield>
<datafield tag="710" ind1=" " ind2=" ">
<subfield code="a">RERO</subfield>
</datafield>
Expand Down Expand Up @@ -5602,3 +5607,26 @@ def test_marc21_to_original_language():
marc21json = create_record(marc21xml)
data = marc21.do(marc21json)
assert data.get('originalLanguage') == ['eng']


def test_abbreviated_title(app, marc21_record):
"""Test abbreviated title to MARC21 transformation."""
marc21xml = """
<record>
<datafield tag="210" ind1="0" ind2=" ">
<subfield code="a">Günter Gianni Piontek Skulpt.</subfield>
</datafield>
<datafield tag="222" ind1=" " ind2="0">
<subfield code="a">Günter Gianni Piontek, Skulpturen</subfield>
</datafield>
</record>
"""
marc21json = create_record(marc21xml)
data = marc21.do(marc21json)
assert data.get('title') == [{
'type': 'bf:AbbreviatedTitle',
'mainTitle': [{'value': 'Günter Gianni Piontek Skulpt.'}]
}, {
'type': 'bf:KeyTitle',
'mainTitle': [{'value': 'Günter Gianni Piontek, Skulpturen'}]
}]
Loading

0 comments on commit 24769bf

Please sign in to comment.