🐛 modstool: Fix handling multiple <mods:language>

There may be multiple <mods:language> tags with mods:languageTerm children,
that should be merged into one language_languageTerm column
master
Gerber, Mike 3 years ago
parent 5c48541dee
commit 75ff143a25

@ -320,8 +320,8 @@ def mods_to_dict(mods, raise_errors=True):
value['language_{}'.format(sub_tag)] = s
elif tag == '{http://www.loc.gov/mods/v3}languageTerm':
value['languageTerm'] = TagGroup(tag, group) \
.is_singleton().has_attributes({'authority': 'iso639-2b', 'type': 'code'}) \
.text()
.has_attributes({'authority': 'iso639-2b', 'type': 'code'}) \
.text_set()
elif tag == '{http://www.loc.gov/mods/v3}scriptTerm':
value['scriptTerm'] = TagGroup(tag, group) \
.fix_script_term() \

@ -9,9 +9,20 @@ def dict_fromstring(x):
"""Helper function to parse a MODS XML string to a flattened dict"""
return flatten(mods_to_dict(ET.fromstring(x)))
def test_languageTerm():
def test_single_language_languageTerm():
d = dict_fromstring("""
<mods:mods xmlns:mods="http://www.loc.gov/mods/v3">
<mods:language>
<mods:languageTerm authority="iso639-2b" type="code">lat</mods:languageTerm>
<mods:languageTerm authority="iso639-2b" type="code">ger</mods:languageTerm>
</mods:language>
</mods:mods>
""")
assert d['language_languageTerm'] == {'ger', 'lat'}
def test_multitple_language_languageTerm():
"""
Different languages have multiple mods:language elements.
Different languages MAY have multiple mods:language elements.
See MODS-AP 2.3.1
"""
d = dict_fromstring("""

Loading…
Cancel
Save