Skip to content

Commit 24769bf

Browse files
committed
dojson: fix work access point and title
* Fixes work access points $t. * Fixes bf:KeyTitle tag 222 Co-Authored-by: Peter Weber <[email protected]>
1 parent e92c579 commit 24769bf

File tree

8 files changed

+236
-29
lines changed

8 files changed

+236
-29
lines changed

rero_ils/modules/documents/dojson/contrib/marc21tojson/dnb/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def marc21_to_part_of(self, key, value):
490490
do_part_of(self, marc21, key, value)
491491

492492

493-
@marc21.over('work_access_point', '(^130..|^700.2|^710.2|^730..)')
493+
@marc21.over('work_access_point', '(^130..|^730..)')
494494
@utils.for_each_value
495495
@utils.ignore_value
496496
def marc21_to_work_access_point(self, key, value):

rero_ils/modules/documents/dojson/contrib/marc21tojson/kul/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def marc21_to_part_of(self, key, value):
502502
do_part_of(self, marc21, key, value)
503503

504504

505-
@marc21.over('work_access_point', '(^130..|^700.2|^710.2|^730..)')
505+
@marc21.over('work_access_point', '(^130..|^730..)')
506506
@utils.for_each_value
507507
@utils.ignore_value
508508
def marc21_to_work_access_point(self, key, value):

rero_ils/modules/documents/dojson/contrib/marc21tojson/rero/model.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
get_field_items, not_repetitive, re_identified, \
2929
remove_trailing_punctuation
3030

31-
from ..utils import _CONTRIBUTION_ROLE, do_acquisition_terms_from_field_037, \
32-
do_copyright_date, do_credits, do_dissertation, do_edition_statement, \
31+
from ..utils import _CONTRIBUTION_ROLE, do_abbreviated_title, \
32+
do_acquisition_terms_from_field_037, do_copyright_date, do_credits, \
33+
do_dissertation, do_edition_statement, \
3334
do_electronic_locator_from_field_856, do_frequency_field_310_321, \
3435
do_identified_by_from_field_020, do_identified_by_from_field_022, \
3536
do_identified_by_from_field_024, do_identified_by_from_field_028, \
@@ -111,6 +112,13 @@ def marc21_to_title(self, key, value):
111112
@utils.ignore_value
112113
def marc21_to_contribution(self, key, value):
113114
"""Get contribution."""
115+
# exclude work access points
116+
if key[:3] in ['700', '710'] and value.get('t'):
117+
work_access_point = do_work_access_point(marc21, key, value)
118+
if work_access_point:
119+
self.setdefault('work_access_point', [])
120+
self['work_access_point'].append(work_access_point)
121+
return None
114122
agent = {}
115123
subfields_0 = utils.force_list(value.get('0'))
116124
if subfields_0:
@@ -267,6 +275,14 @@ def marc21_to_copyright_date(self, key, value):
267275
return copyright_dates or None
268276

269277

278+
@marc21.over('title', '(^210|^222)..')
279+
@utils.ignore_value
280+
def marc21_to_abbreviated_title(self, key, value):
281+
"""Get abbreviated title data."""
282+
title_list = do_abbreviated_title(self, marc21, key, value)
283+
return title_list or None
284+
285+
270286
@marc21.over('editionStatement', '^250..')
271287
@utils.for_each_value
272288
@utils.ignore_value
@@ -1050,7 +1066,7 @@ def marc21_to_masked(self, key, value):
10501066
return value.get('a') == 'masked'
10511067

10521068

1053-
@marc21.over('work_access_point', '(^130..|^700.2|^710.2|^730..)')
1069+
@marc21.over('work_access_point', '(^130..|^730..)')
10541070
@utils.for_each_value
10551071
@utils.ignore_value
10561072
def marc21_to_work_access_point(self, key, value):

rero_ils/modules/documents/dojson/contrib/marc21tojson/slsp/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def marc21_to_part_of(self, key, value):
512512
do_part_of(self, marc21, key, value)
513513

514514

515-
@marc21.over('work_access_point', '(^130..|^700.2|^710.2|^730..)')
515+
@marc21.over('work_access_point', '(^130..|^730..)')
516516
@utils.for_each_value
517517
@utils.ignore_value
518518
def marc21_to_work_access_point(self, key, value):

rero_ils/modules/documents/dojson/contrib/marc21tojson/utils.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ def do_language(data, marc21):
363363
def do_abbreviated_title(data, marc21, key, value):
364364
"""Get abbreviated title data.
365365
366-
* bf:Title = 210|222
366+
* bf:AbbreviatedTitle = 210
367+
* bf:KeyTitle = 222
367368
* mainTitle = $a
368369
* subtitle = $e
369370
* responsibilityStatement = $f|$g
@@ -376,8 +377,11 @@ def do_abbreviated_title(data, marc21, key, value):
376377
if value.get('a'):
377378
main_title = not_repetitive(
378379
marc21.bib_id, marc21.bib_id, key, value, 'a')
380+
title_type = 'bf:AbbreviatedTitle'
381+
if key[:3] == '222':
382+
title_type = 'bf:KeyTitle'
379383
title = {
380-
'type': 'bf:AbbreviatedTitle',
384+
'type': title_type,
381385
'mainTitle': [{'value': main_title}]
382386
}
383387
if value.get('b'):
@@ -595,6 +599,10 @@ def build_agent():
595599

596600
# exclude work access points
597601
if key[:3] in ['700', '710'] and value.get('t'):
602+
work_access_point = do_work_access_point(marc21, key, value)
603+
if work_access_point:
604+
data.setdefault('work_access_point', [])
605+
data['work_access_point'].append(work_access_point)
598606
return None
599607

600608
agent = {}
@@ -614,23 +622,22 @@ def build_agent():
614622
agent = build_agent()
615623

616624
if value.get('4'):
617-
roles = []
625+
roles = set()
618626
for role in utils.force_list(value.get('4')):
619-
if len(role) != 3 and 'http' not in role:
627+
role = role.split('/')[-1].lower()
628+
if len(role) != 3:
620629
error_print('WARNING CONTRIBUTION ROLE LENGTH:',
621630
marc21.bib_id, marc21.rero_id, role)
622-
role = role[:3]
623631
if role == 'sce':
624632
error_print('WARNING CONTRIBUTION ROLE SCE:',
625633
marc21.bib_id, marc21.rero_id,
626634
'sce --> aus')
627635
role = 'aus'
628-
role = role.lower()
629-
if role not in _CONTRIBUTION_ROLE and 'http' not in role:
636+
if role not in _CONTRIBUTION_ROLE:
630637
error_print('WARNING CONTRIBUTION ROLE DEFINITION:',
631638
marc21.bib_id, marc21.rero_id, role)
632639
role = 'ctb'
633-
roles.append(role)
640+
roles.add(role)
634641
else:
635642
if key[:3] == '100':
636643
roles = ['cre']
@@ -641,7 +648,7 @@ def build_agent():
641648
if agent:
642649
return {
643650
'agent': agent,
644-
'role': list(set(roles))
651+
'role': list(roles)
645652
}
646653
return None
647654

@@ -1647,20 +1654,17 @@ def do_work_access_point(marc21, key, value):
16471654
not_repetitive(marc21.bib_id, marc21.bib_id, key, value, 'b'))
16481655
dates = not_repetitive(marc21.bib_id, marc21.bib_id, key, value, 'd')
16491656
if dates:
1650-
dates = dates.rstrip(',')
1651-
dates = remove_trailing_punctuation(dates).split('-')
1657+
split_dates = dates.split('-')
1658+
date_of_birth = split_dates[0].strip()
1659+
if date_of_birth:
1660+
agent['date_of_birth'] = date_of_birth
16521661
try:
1653-
date_of_birth = dates[0].strip()
1654-
if date_of_birth:
1655-
agent['date_of_birth'] = date_of_birth
1656-
except Exception:
1657-
pass
1658-
try:
1659-
date_of_death = dates[1].strip()
1662+
date_of_death = split_dates[1].strip()
16601663
if date_of_death:
16611664
agent['date_of_death'] = date_of_death
16621665
except Exception:
16631666
pass
1667+
16641668
if value.get('c'):
16651669
agent['qualifier'] = remove_trailing_punctuation(
16661670
not_repetitive(marc21.bib_id, marc21.bib_id, key, value, 'c'))
@@ -1672,8 +1676,7 @@ def do_work_access_point(marc21, key, value):
16721676
agent['preferred_name'] = not_repetitive(
16731677
marc21.bib_id, marc21.bib_id, key, value, 'a')
16741678
if value.get('b'):
1675-
agent['subordinate_unit'] = not_repetitive(
1676-
marc21.bib_id, marc21.bib_id, key, value, 'b')
1679+
agent['subordinate_unit'] = list(utils.force_list(value.get('b')))
16771680
if agent:
16781681
work_access_point['agent'] = agent
16791682
if value.get(title_tag):

rero_ils/modules/documents/jsonschemas/documents/document_work_access_point-v0.0.1.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"title": "Title",
109109
"description": "Title of the part, section, or supplement",
110110
"type": "string",
111-
"minLength": 3
111+
"minLength": 1
112112
}
113113
}
114114
}
@@ -130,13 +130,13 @@
130130
"items": {
131131
"title": "Medium of performance (music)",
132132
"type": "string",
133-
"minLength": 3
133+
"minLength": 1
134134
}
135135
},
136136
"arranged_statement_for_music": {
137137
"title": "Arranged statement (music)",
138138
"type": "string",
139-
"minLength": 3
139+
"minLength": 1
140140
},
141141
"key_for_music": {
142142
"title": "Key (music)",

tests/unit/test_documents_dojson.py

+28
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,11 @@ def test_marc21_to_contribution(mock_get):
13491349
<subfield code="d">1921-2014</subfield>
13501350
<subfield code="4">edt</subfield>
13511351
</datafield>
1352+
<datafield tag="700" ind1="1" ind2=" ">
1353+
<subfield code="a">Santamaría, Germán</subfield>
1354+
<subfield code="t">No morirás</subfield>
1355+
<subfield code="l">français</subfield>
1356+
</datafield>
13521357
<datafield tag="710" ind1=" " ind2=" ">
13531358
<subfield code="a">RERO</subfield>
13541359
</datafield>
@@ -5602,3 +5607,26 @@ def test_marc21_to_original_language():
56025607
marc21json = create_record(marc21xml)
56035608
data = marc21.do(marc21json)
56045609
assert data.get('originalLanguage') == ['eng']
5610+
5611+
5612+
def test_abbreviated_title(app, marc21_record):
5613+
"""Test abbreviated title to MARC21 transformation."""
5614+
marc21xml = """
5615+
<record>
5616+
<datafield tag="210" ind1="0" ind2=" ">
5617+
<subfield code="a">Günter Gianni Piontek Skulpt.</subfield>
5618+
</datafield>
5619+
<datafield tag="222" ind1=" " ind2="0">
5620+
<subfield code="a">Günter Gianni Piontek, Skulpturen</subfield>
5621+
</datafield>
5622+
</record>
5623+
"""
5624+
marc21json = create_record(marc21xml)
5625+
data = marc21.do(marc21json)
5626+
assert data.get('title') == [{
5627+
'type': 'bf:AbbreviatedTitle',
5628+
'mainTitle': [{'value': 'Günter Gianni Piontek Skulpt.'}]
5629+
}, {
5630+
'type': 'bf:KeyTitle',
5631+
'mainTitle': [{'value': 'Günter Gianni Piontek, Skulpturen'}]
5632+
}]

0 commit comments

Comments
 (0)