Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_mods_physical_description(mods, rec_type):
""" physicalDescription ->
extent_duration, extent_dimension, extent_pages, form, physical_description_notes, reformatting_quality
"""
result = {}
mods_physical_description = mods.find(xmletree.prefixtag("mods", "physicalDescription"))
if mods_physical_description is not None:
# digitalOrigin -> digital_origin
result.update(get_mods_element_text_and_set_key(mods_physical_description, "digitalOrigin", "digital_origin"))
# extent -> extent_duration, extent_dimension, extent_pages
extent = get_mods_element_text(mods_physical_description, "extent")
if extent:
if rec_type in ["AudioBook", "AudioBroadcast", "AudioRecording", "MusicRecording", "VideoBroadcast", "VideoRecording", "VideoPart"]:
result["extent_duration"] = extent
elif rec_type in ["PhysicalObject"]:
result["extent_dimension"] = extent
else:
result["extent_pages"] = extent
# form -> form
identifier_eissn["value"] = openurl_eissn.text
document.add_item_to_key(identifier_eissn, "identifiers")
# linkGroups
openurl_linkgroups = openurl_result.find(xmletree.prefixtag("ssopenurl", "linkGroups"))
if openurl_linkgroups is not None:
# linkGroup
openurl_linkgroup_list = openurl_linkgroups.findall(xmletree.prefixtag("ssopenurl", "linkGroup"))
if openurl_linkgroup_list is not None:
for openurl_linkgroup in openurl_linkgroup_list:
service_name = None
institution_name = None
period_begin = None
period_end = None
url = None
# holdingData
openurl_holdingdata = openurl_linkgroup.find(xmletree.prefixtag("ssopenurl", "holdingData"))
if openurl_holdingdata is not None:
# institution_name
openurl_providername = openurl_holdingdata.find(xmletree.prefixtag("ssopenurl", "providerName"))
if openurl_providername is not None:
institution_name = openurl_providername.text
# service_name
openurl_databasename = openurl_holdingdata.find(xmletree.prefixtag("ssopenurl", "databaseName"))
if openurl_databasename is not None:
service_name = openurl_databasename.text
# normalizedData
openurl_normalizeddata = openurl_holdingdata.find(xmletree.prefixtag("ssopenurl", "normalizedData"))
if openurl_normalizeddata is not None:
# startDate
openurl_startdate = openurl_normalizeddata.find(xmletree.prefixtag("ssopenurl", "startDate"))
if openurl_startdate is not None:
period_begin = openurl_startdate.text
def get_rml_emails(rml):
""" email -> emails """
result = {}
rml_emails = rml.findall(xmletree.prefixtag("rml", "email"))
if rml_emails is not None:
emails = []
for rml_email in rml_emails:
if rml_email is not None:
# @preferred -> preferred
preferred = xmletree.get_element_attribute_as_boolean(rml_email, "preferred")
# @relationType -> relation_type
relation_type = rml_email.get("relationType")
# @visible -> visible
visible = xmletree.get_element_attribute_as_boolean(rml_email, "visible")
# value
value = xmletree.get_element_text(rml_email)
#rml_homeurl_value = xmletree.get_element_text(rml_romeo.find(xmletree.prefixtag("rml", "homeurl")))
#if rml_homeurl_value:
# publisher["urls"] = [metajson_service.create_url(rml_homeurl_value, True, "work", None, None, True)]
# id -> publisher.identifiers[i]
#rml_id_value = xmletree.get_element_text(rml_romeo.find(xmletree.prefixtag("rml", "id")))
#if rml_id_value:
# publisher["identifiers"] = [metajson_service.create_identifier("romeo", rml_id_value)]
# name -> publisher.name
#publisher.update(get_rml_element_text_and_set_key(rml_romeo, "name", "name"))
#sap["publisher"] = publisher
# conditions.condition -> conditions[]
rml_conditions = rml_romeo.find(xmletree.prefixtag("rml", "conditions"))
if rml_conditions is not None:
rml_conditions_list = rml_conditions.findall(xmletree.prefixtag("rml", "condition"))
if rml_conditions_list is not None:
conditions = []
for rml_condition in rml_conditions_list:
value = xmletree.get_element_text(rml_condition)
if value:
conditions.append(value)
if conditions:
sap["conditions"] = conditions
# copyright -> copyright
sap.update(get_rml_element_text_and_set_key(rml_romeo, "copyright", "copyright"))
# copyrightlinks -> copyright_urls
rml_copyrightlinks = rml_romeo.find(xmletree.prefixtag("rml", "copyrightlinks"))
for term in terms:
result_keywords_dict[mods_subject_lang].append(term.strip())
else:
topics = []
for mods_topic in mods_topics:
if mods_topic.text is not None:
topics.append(mods_topic.text)
if topics:
subject["topics"] = topics
# cartographics -> cartographics[]
if mods_cartographicss is not None:
cartographics = []
for mods_cartographics in mods_cartographicss:
cartographic = {}
mods_coordinates = mods_cartographics.find(xmletree.prefixtag("mods", "coordinates"))
mods_scale = mods_cartographics.find(xmletree.prefixtag("mods", "scale"))
mods_projection = mods_cartographics.find(xmletree.prefixtag("mods", "projection"))
# coordinates -> coordinates[].latitude, coordinates[].longitude, coordinates[].altitude
if mods_coordinates is not None:
# todo : extract coordinates latitude, longitude, altitude of each points
coordinates = []
coordinate = {"latitude" : mods_coordinates.text}
coordinates.append(coordinate)
cartographic["coordinates"] = coordinates
# scale -> scale
if mods_scale is not None:
cartographic["scale"] = mods_scale.text
# projection -> projection
def get_rml_money_and_set_key(rml, element, key):
""" element -> key """
result = {}
rml_element = rml.find(xmletree.prefixtag("rml", element))
if rml_element is not None:
money = {}
# currency -> currency
money.update(xmletree.get_element_attribute_and_set_key(rml_element, "currency", "currency"))
# text -> value
money["value"] = xmletree.get_element_text(rml_element)
if money:
result[key] = money
return result
date_modified = convert_mods_date(mods_origin_info.find(xmletree.prefixtag("mods", "dateModified")))
if date_modified:
result["date_modified"] = date_modified
# copyrightDate -> date_copyrighted
date_copyrighted = convert_mods_date(mods_origin_info.find(xmletree.prefixtag("mods", "copyrightDate")))
if date_copyrighted:
result["date_copyrighted"] = date_copyrighted
# dateOther -> date_other
date_other = convert_mods_date(mods_origin_info.find(xmletree.prefixtag("mods", "dateOther")))
if date_other:
result["date_other"] = date_other
# edition -> edition
mods_edition = mods_origin_info.find(xmletree.prefixtag("mods", "edition"))
if mods_edition is not None:
result["edition"] = mods_edition.text.strip()
# frequency -> frequency
mods_frequency = mods_origin_info.find(xmletree.prefixtag("mods", "frequency"))
if mods_frequency is not None:
result["frequency"] = mods_frequency.text.strip()
# issuance -> issuance
mods_issuance = mods_origin_info.find(xmletree.prefixtag("mods", "issuance"))
if mods_issuance is not None:
result["issuance"] = mods_issuance.text.strip()
# place/placeTerm -> publication_countries, publication_places
mods_places = mods_origin_info.findall(xmletree.prefixtag("mods", "place"))
if mods_places is not None:
def get_mods_subjects(mods):
""" subject -> keywords, subjects """
result = {}
mods_subjects = mods.findall(xmletree.prefixtag("mods", "subject"))
if mods_subjects is not None:
result_subjects = []
result_keywords_dict = {}
for mods_subject in mods_subjects:
if mods_subject is not None:
# get mods data
mods_subject_authority = mods_subject.get("authority")
mods_subject_authority_uri = mods_subject.get("authorityURI")
mods_subject_lang = mods_subject.get("lang")
mods_cartographicss = mods_subject.findall(xmletree.prefixtag("mods", "cartographics"))
mods_genres = mods_subject.findall(xmletree.prefixtag("mods", "genre"))
mods_geographics = mods_subject.findall(xmletree.prefixtag("mods", "geographic"))
mods_geographic_codes = mods_subject.findall(xmletree.prefixtag("mods", "geographicCode"))
mods_hierarchical_geographics = mods_subject.findall(xmletree.prefixtag("mods", "hierarchicalGeographic"))
mods_names = mods_subject.findall(xmletree.prefixtag("mods", "name"))
mods_occupations = mods_subject.findall(xmletree.prefixtag("mods", "occupation"))