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_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_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_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
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
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
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