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_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_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_affiliations(rml): """ affiliation -> affiliations """ result = {} rml_affiliations = rml.findall(xmletree.prefixtag("rml", "affiliation")) if rml_affiliations is not None: affiliations = [] for rml_affiliation in rml_affiliations: if rml_affiliation is not None: # dateBegin -> date_begin date_begin = get_rml_element_text(rml_affiliation, "dateBegin") # dateEnd -> date_end date_end = get_rml_element_text(rml_affiliation, "dateEnd") # description -> descriptions descriptions = get_rml_textlangs_as_list(rml_affiliation, "description") # identifier -> agent.rec_id identifiers = get_rml_identifiers(rml_affiliation) rec_id = None if "rec_id" in identifiers and identifiers["rec_id"]: rec_id = identifiers["rec_id"] # name -> agent.name name = get_rml_element_text(rml_affiliation, "name") # @preferred -> preferred preferred = xmletree.get_element_attribute_as_boolean(rml_affiliation, "preferred") # relationType -> role role = get_rml_element_text(rml_affiliation, "relationType") affiliation = metajson_service.create_affiliation(rec_id, name, role, date_begin, date_end, preferred, descriptions) if affiliation is not None: affiliations.append(affiliation) if affiliations: result["affiliations"] = affiliations return result