def get_rml_identifiers(rml): """ identifier -> identifiers """ result = {} rml_identifiers = rml.findall(xmletree.prefixtag("rml", "identifier")) if rml_identifiers is not None: identifiers = [] rec_id = None for rml_identifier in rml_identifiers: if rml_identifier is not None: # @type -> id_type id_type = rml_identifier.get("type") # value id_value = xmletree.get_element_text(rml_identifier) if id_type is None or id_type == "hdl": # rec_id rec_id = id_value else: # identifier identifier = metajson_service.create_identifier(id_type, id_value) if identifier is not None: identifiers.append(identifier) if identifiers: result["identifiers"] = identifiers if rec_id: result["rec_id"] = rec_id return result
def get_rml_phones(rml): """ phone -> phones """ result = {} rml_phones = rml.findall(xmletree.prefixtag("rml", "phone")) if rml_phones is not None: phones = [] for rml_phone in rml_phones: if rml_phone is not None: # @preferred -> preferred preferred = xmletree.get_element_attribute_as_boolean(rml_phone, "preferred") # @relationType -> relation_type relation_type = rml_phone.get("relationType") # @type -> phone_type phone_type = rml_phone.get("type") # @visible -> visible visible = xmletree.get_element_attribute_as_boolean(rml_phone, "visible") # formatted -> formatted rml_formatted = rml_phone.find(xmletree.prefixtag("rml", "formatted")) formatted = xmletree.get_element_text(rml_formatted) phone = metajson_service.create_phone(formatted, phone_type, preferred, relation_type, visible) if phone: phones.append(phone) if phones: result["phones"] = phones return result
def get_rml_instant_messages(rml): """ instantMessage -> instant_messages """ result = {} rml_ims = rml.findall(xmletree.prefixtag("rml", "instantMessage")) if rml_ims is not None: ims = [] for rml_im in rml_ims: if rml_im is not None: # @preferred -> preferred preferred = xmletree.get_element_attribute_as_boolean(rml_im, "preferred") # @relationType -> relation_type relation_type = rml_im.get("relationType") # @service -> service service = rml_im.get("service") # @visible -> visible visible = xmletree.get_element_attribute_as_boolean(rml_im, "visible") # value value = xmletree.get_element_text(rml_im) im = metajson_service.create_instant_message(value, service, preferred, relation_type, visible) if im: ims.append(im) if ims: result["instant_messages"] = ims return result
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) email = metajson_service.create_email(value, preferred, relation_type, visible) if email: emails.append(email) if emails: result["emails"] = emails return result
def get_mods_elements_text(rml, element): elements_xmletree = rml.findall(xmletree.prefixtag("mods", element)) if elements_xmletree is not None: results = [] for element_xmletree in elements_xmletree: if element_xmletree is not None: results.append(xmletree.get_element_text(element_xmletree)) if results: return results return None
def get_rml_elements_text(rml, element): elements_xmletree = rml.findall(xmletree.prefixtag("rml", element)) if elements_xmletree is not None: results = [] for element_xmletree in elements_xmletree: if element_xmletree is not None: results.append(xmletree.get_element_text(element_xmletree)) if results: return results return None
def get_rml_addresses(rml): """ address -> addresses """ result = {} rml_addresses = rml.findall(xmletree.prefixtag("rml", "address")) if rml_addresses is not None: addresses = [] for rml_address in rml_addresses: if rml_address is not None: # country -> country country = xmletree.get_element_text(rml_address.find(xmletree.prefixtag("rml", "country"))) # locality_city_town -> locality_city_town locality_city_town = xmletree.get_element_text(rml_address.find(xmletree.prefixtag("rml", "localityCityTown"))) # post_code -> post_code post_code = xmletree.get_element_text(rml_address.find(xmletree.prefixtag("rml", "postCode"))) # @preferred -> preferred preferred = xmletree.get_element_attribute_as_boolean(rml_address, "preferred") # @relationType -> relation_type relation_type = rml_address.get("relationType") # street -> street street = xmletree.get_element_text(rml_address.find(xmletree.prefixtag("rml", "street"))) # @visible -> visible visible = xmletree.get_element_attribute_as_boolean(rml_address, "visible") # address -> addresses[i] address = metajson_service.create_address(street, post_code, locality_city_town, country, preferred, relation_type, visible) if address: addresses.append(address) if addresses: result["addresses"] = addresses return result
def get_rml_images(rml, role): """ image -> resources[0] """ result = {} rml_images = rml.findall(xmletree.prefixtag("rml", "image")) if rml_images is not None: resources = [] for rml_image in rml_images: if rml_image is not None: url = xmletree.get_element_text(rml_image) resource = metajson_service.create_resource_remote(url, None, role) if resource is not None: resources.append(resource) if resources: result["resources"] = resources return result
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
def get_rml_uris(rml): """ uri -> urls """ result = {} rml_uris = rml.findall(xmletree.prefixtag("rml", "uri")) if rml_uris is not None: urls = [] for rml_uri in rml_uris: if rml_uri is not None: preferred = xmletree.get_element_attribute_as_boolean(rml_uri, "preferred") relation_type = rml_uri.get("relationType") visible = xmletree.get_element_attribute_as_boolean(rml_uri, "visible") value = xmletree.get_element_text(rml_uri) url = metajson_service.create_url(value, preferred, relation_type, None, None, visible) if url: urls.append(url) if urls: result["urls"] = urls return result
def get_rml_turnovers(rml): """ turnover -> turnovers """ result = {} rml_turnovers = rml.findall(xmletree.prefixtag("rml", "turnover")) if rml_turnovers is not None: turnovers = [] for rml_turnover in rml_turnovers: if rml_turnover is not None: turnover = {} turnover.update(xmletree.get_element_attribute_and_set_key(rml_turnover, "currency", "currency")) turnover.update(xmletree.get_element_attribute_and_set_key(rml_turnover, "year", "year")) turnover["value"] = xmletree.get_element_text(rml_turnover) if turnover: turnovers.append(turnover) if turnovers: result["turnovers"] = turnovers return result
def get_mods_element_text(rml, element, strip=True): element_xmletree = rml.find(xmletree.prefixtag("mods", element)) return xmletree.get_element_text(element_xmletree, strip)
def get_rml_self_archiving_policy(rml): """ ckbData -> self_archiving_policy """ result = {} rml_ckbdata = rml.find(xmletree.prefixtag("rml", "ckbData")) if rml_ckbdata is not None: sap = {} # romeoPublisher -> . rml_romeo = rml_ckbdata.find(xmletree.prefixtag("rml", "romeoPublisher")) if rml_romeo is not None: # publisher : don't repeate this information #publisher = Orgunit() #publisher["rec_type"] = "publisher" # alias -> publisher.acronym #publisher.update(get_rml_element_text_and_set_key(rml_romeo, "alias", "acronym")) # homeurl -> publisher.urls[] #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")) if rml_copyrightlinks is not None: rml_copyrightlinks_list = rml_copyrightlinks.findall(xmletree.prefixtag("rml", "copyrightlink")) if rml_copyrightlinks_list is not None: copyright_urls = [] for rml_copyrightlink in rml_copyrightlinks_list: copyrightlinktext = xmletree.get_element_text(rml_copyrightlink.find(xmletree.prefixtag("rml", "copyrightlinktext"))) copyrightlinkurl = xmletree.get_element_text(rml_copyrightlink.find(xmletree.prefixtag("rml", "copyrightlinkurl"))) copyright_url = metajson_service.create_url(copyrightlinkurl, None, None, copyrightlinktext, None, None) copyright_urls.append(copyright_url) if copyright_urls: sap["copyright_urls"] = copyright_urls # paidaccess -> paid_access rml_paidaccess = rml_romeo.find(xmletree.prefixtag("rml", "paidaccess")) if rml_paidaccess is not None: paid_access = {} # paidaccessname -> label paid_access.update(get_rml_element_text_and_set_key(rml_paidaccess, "paidaccessname", "label")) # paidaccessurl -> url paid_access.update(get_rml_element_text_and_set_key(rml_paidaccess, "paidaccessurl", "url")) # paidaccessnotes -> notes # rml_paidaccessnotes = rml_paidaccess.findall(xmletree.prefixtag("rml", "paidaccessnotes")) sap["paid_access"] = paid_access # postprints -> postprint rml_postprints = rml_romeo.find(xmletree.prefixtag("rml", "postprints")) if rml_postprints is not None: postprint = {} # postarchiving -> possibility postprint.update(get_rml_element_text_and_set_key(rml_postprints, "postarchiving", "possibility")) # postrestrictions -> restrictions postprint.update(get_rml_textlangs_and_set_key(rml_postprints, "postrestrictions", "restrictions")) sap["postprint"] = postprint # preprints -> preprint rml_preprints = rml_romeo.find(xmletree.prefixtag("rml", "preprints")) if rml_preprints is not None: preprint = {} # prearchiving -> possibility preprint.update(get_rml_element_text_and_set_key(rml_preprints, "prearchiving", "possibility")) # prerestrictions -> restrictions preprint.update(get_rml_textlangs_and_set_key(rml_preprints, "prerestrictions", "pre_restrictions")) sap["preprint"] = preprint # romeocolour -> romeo_color sap.update(get_rml_element_text_and_set_key(rml_romeo, "romeocolour", "romeo_color")) if sap: result["self_archiving_policy"] = sap return result
def get_rml_element_text(rml, element): element_xmletree = rml.find(xmletree.prefixtag("rml", element)) return xmletree.get_element_text(element_xmletree)